From cd89253474a9ab6ba174c5b79ee9d8aeffe107f1 Mon Sep 17 00:00:00 2001 From: Cavero Barca Date: Mon, 14 Sep 2020 23:58:12 +0200 Subject: [PATCH 001/590] Create the layers configuration, modify the pom and Dockerfile --- docker/docker-spring-boot/pom.xml | 1 + docker/docker-spring-boot/src/layers.xml | 27 +++++++++++++++++++ .../src/main/docker/Dockerfile | 1 + 3 files changed, 29 insertions(+) create mode 100644 docker/docker-spring-boot/src/layers.xml diff --git a/docker/docker-spring-boot/pom.xml b/docker/docker-spring-boot/pom.xml index b9c80bc43a..e8f6c134b1 100644 --- a/docker/docker-spring-boot/pom.xml +++ b/docker/docker-spring-boot/pom.xml @@ -45,6 +45,7 @@ true + ${project.basedir}/src/layers.xml diff --git a/docker/docker-spring-boot/src/layers.xml b/docker/docker-spring-boot/src/layers.xml new file mode 100644 index 0000000000..61c9bd9c39 --- /dev/null +++ b/docker/docker-spring-boot/src/layers.xml @@ -0,0 +1,27 @@ + + + + org/springframework/boot/loader/** + + + + + + *:*:*SNAPSHOT + + + com.baeldung.docker:*:* + + + + + dependencies + spring-boot-loader + internal-dependencies + snapshot-dependencies + application + + \ No newline at end of file diff --git a/docker/docker-spring-boot/src/main/docker/Dockerfile b/docker/docker-spring-boot/src/main/docker/Dockerfile index fa147dd69b..663cc94490 100644 --- a/docker/docker-spring-boot/src/main/docker/Dockerfile +++ b/docker/docker-spring-boot/src/main/docker/Dockerfile @@ -10,6 +10,7 @@ RUN java -Djarmode=layertools -jar application.jar extract FROM adoptopenjdk:11-jre-hotspot COPY --from=builder dependencies/ ./ COPY --from=builder snapshot-dependencies/ ./ +COPY --from=builder internal-dependencies/ ./ COPY --from=builder spring-boot-loader/ ./ COPY --from=builder application/ ./ ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file From c6f067c17f2351f845dab5bb9f83bcb6f1bf039b Mon Sep 17 00:00:00 2001 From: Vishal Date: Sun, 13 Sep 2020 23:05:36 +0530 Subject: [PATCH 002/590] Add examples to demo IndexOutOfBoundsException while using Collectins.copy method and other working demos to copy elements from one list to another list --- .../CopyListUsingAddAllMethodDemo.java | 24 +++++++++++++++++ ...opyListUsingCollectionsCopyMethodDemo.java | 21 +++++++++++++++ .../CopyListUsingConstructorDemo.java | 21 +++++++++++++++ .../com/baeldung/CopyListUsingJava10Demo.java | 18 +++++++++++++ .../CopyListUsingJava8StreamDemo.java | 22 +++++++++++++++ .../exception/IndexOutOfBoundsException.java | 27 +++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java new file mode 100644 index 0000000000..a7d24cdec8 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java @@ -0,0 +1,24 @@ +package com.baeldung; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CopyListUsingAddAllMethodDemo { + + static List copyList(List source) { + List destination = new ArrayList<>(); + + destination.addAll(source); + + return destination; + } + + public static void main(String[] args) { + List source = Arrays.asList(11, 22, 33); + + List destination = copyList(source); + + System.out.println("copy = " + destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java new file mode 100644 index 0000000000..bdf6726924 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java @@ -0,0 +1,21 @@ +package com.baeldung; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class CopyListUsingCollectionsCopyMethodDemo { + + static void copyList(List source, List destination) { + Collections.copy(destination, source); + } + + public static void main(String[] args) { + List source = Arrays.asList(11, 22, 33); + List destination = Arrays.asList(1, 2, 3, 4, 5); + + copyList(source, destination); + + System.out.println("copy = " + destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java new file mode 100644 index 0000000000..b76a1448d4 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java @@ -0,0 +1,21 @@ +package com.baeldung; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CopyListUsingConstructorDemo { + + static List copyList(List source) { + + return new ArrayList<>(source); + } + + public static void main(String[] args) { + List source = Arrays.asList(11, 22, 33); + + List destination = copyList(source); + + System.out.println("copy = " + destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java new file mode 100644 index 0000000000..1a32dcec4f --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java @@ -0,0 +1,18 @@ +package com.baeldung; + +import java.util.Arrays; +import java.util.List; + +public class CopyListUsingJava10Demo { + static List copyList(List source) { + return List.copyOf(source); + } + + public static void main(String[] args) { + List source = Arrays.asList(11, 22, 33); + + List destination = copyList(source); + + System.out.println("copy = " + destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java new file mode 100644 index 0000000000..81ae533505 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java @@ -0,0 +1,22 @@ +package com.baeldung; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CopyListUsingJava8StreamDemo { + + static List copyList(List source) { + return source + .stream() + .collect(Collectors.toList()); + } + + public static void main(String[] args) { + List source = Arrays.asList(11, 22, 33); + + List destination = copyList(source); + + System.out.println("copy = " + destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java new file mode 100644 index 0000000000..a1b6bf1151 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java @@ -0,0 +1,27 @@ +package com.baeldung.exception; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * This example produces an IndexOutOfBoundsException, when we try to copy a list using the Collections.copy method. + * As the destination list doesn't have enough space/size to copy elements from source list. + */ +public class IndexOutOfBoundsException { + + static List copyList(List source) { + List destination = new ArrayList<>(source.size()); + Collections.copy(destination, source); + return destination; + } + + public static void main(String[] args) { + List source = Arrays.asList(1, 2, 3, 4, 5); + List copy = copyList(source); + + System.out.println("copy = " + copy); + } + +} From a47ed70f36934c10bf4161efa5b6bd01e7612246 Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 17 Sep 2020 16:41:47 +0530 Subject: [PATCH 003/590] Add maven compiler plugin for java 11 --- core-java-modules/core-java-exceptions-3/pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml index b909572afe..19996f85af 100644 --- a/core-java-modules/core-java-exceptions-3/pom.xml +++ b/core-java-modules/core-java-exceptions-3/pom.xml @@ -26,6 +26,19 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + 11 + + + + 3.10.0 From f8d53b4c6015d5646c74320151c1ee235f059967 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Thu, 17 Sep 2020 22:00:57 +0200 Subject: [PATCH 004/590] BAEL-4437 - System Rules --- 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 f84e6099381ef89d4c2276a5fe878e939be04ece Mon Sep 17 00:00:00 2001 From: Cavero Barca Date: Tue, 22 Sep 2020 01:08:21 +0200 Subject: [PATCH 005/590] Add a new project with dependencies to separate the layers --- docker/docker-internal-dto/pom.xml | 14 +++++++++ .../java/com/baeldung/docker/VariableDto.java | 14 +++++++++ docker/docker-spring-boot/pom.xml | 28 ++++++++++------- .../src/main/docker/Dockerfile | 4 +-- docker/pom.xml | 30 +++++++++++++++++++ 5 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 docker/docker-internal-dto/pom.xml create mode 100644 docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java create mode 100644 docker/pom.xml diff --git a/docker/docker-internal-dto/pom.xml b/docker/docker-internal-dto/pom.xml new file mode 100644 index 0000000000..d7ba6d7373 --- /dev/null +++ b/docker/docker-internal-dto/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + com.baeldung.docker + docker-spring-boot-parent + 0.0.1 + + + docker-internal-dto + + \ No newline at end of file diff --git a/docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java b/docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java new file mode 100644 index 0000000000..86e173e351 --- /dev/null +++ b/docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java @@ -0,0 +1,14 @@ +package com.baeldung.docker; + +public class VariableDto { + + private final String value; + + public VariableDto(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/docker/docker-spring-boot/pom.xml b/docker/docker-spring-boot/pom.xml index e8f6c134b1..9524f68a5a 100644 --- a/docker/docker-spring-boot/pom.xml +++ b/docker/docker-spring-boot/pom.xml @@ -1,21 +1,21 @@ - + 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.3.1.RELEASE - + com.baeldung.docker + docker-spring-boot-parent + 0.0.1 - com.baeldung.docker - spring-boot-docker - 0.0.1-SNAPSHOT - spring-boot-docker + + docker-spring-boot + + docker-spring-boot Demo project showing Spring Boot and Docker - 8 + 11 @@ -24,6 +24,12 @@ spring-boot-starter-web + + com.baeldung.docker + docker-internal-dto + 0.0.1 + + org.springframework.boot spring-boot-starter-test diff --git a/docker/docker-spring-boot/src/main/docker/Dockerfile b/docker/docker-spring-boot/src/main/docker/Dockerfile index 663cc94490..c0fd9c9cdb 100644 --- a/docker/docker-spring-boot/src/main/docker/Dockerfile +++ b/docker/docker-spring-boot/src/main/docker/Dockerfile @@ -9,8 +9,8 @@ RUN java -Djarmode=layertools -jar application.jar extract FROM adoptopenjdk:11-jre-hotspot COPY --from=builder dependencies/ ./ -COPY --from=builder snapshot-dependencies/ ./ -COPY --from=builder internal-dependencies/ ./ COPY --from=builder spring-boot-loader/ ./ +COPY --from=builder internal-dependencies/ ./ +COPY --from=builder snapshot-dependencies/ ./ COPY --from=builder application/ ./ ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/docker/pom.xml b/docker/pom.xml new file mode 100644 index 0000000000..3668ceb0fc --- /dev/null +++ b/docker/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + + + com.baeldung.docker + docker-spring-boot-parent + 0.0.1 + docker-spring-boot-parent + Demo project showing Spring Boot and Docker + pom + + + 11 + + + + docker-internal-dto + docker-spring-boot + + + From ea8e33f434d95d57b6c3b570d4a391401645d6a5 Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Sun, 27 Sep 2020 18:37:50 +0200 Subject: [PATCH 006/590] Add dependency management module --- .../gradle-dependency-management/.gitignore | 34 ++++ .../gradle-dependency-management/build.gradle | 46 +++++ .../gradle/wrapper/gradle-wrapper.properties | 5 + gradle/gradle-dependency-management/gradlew | 184 ++++++++++++++++++ .../gradle-dependency-management/gradlew.bat | 89 +++++++++ .../settings.gradle | 1 + .../DependencyManagementApplication.java | 13 ++ .../src/main/resources/application.properties | 1 + .../DependencyManagementApplicationTests.java | 13 ++ 9 files changed, 386 insertions(+) create mode 100644 gradle/gradle-dependency-management/.gitignore create mode 100644 gradle/gradle-dependency-management/build.gradle create mode 100644 gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties create mode 100644 gradle/gradle-dependency-management/gradlew create mode 100644 gradle/gradle-dependency-management/gradlew.bat create mode 100644 gradle/gradle-dependency-management/settings.gradle create mode 100644 gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java create mode 100644 gradle/gradle-dependency-management/src/main/resources/application.properties create mode 100644 gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java diff --git a/gradle/gradle-dependency-management/.gitignore b/gradle/gradle-dependency-management/.gitignore new file mode 100644 index 0000000000..84695dca6f --- /dev/null +++ b/gradle/gradle-dependency-management/.gitignore @@ -0,0 +1,34 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/gradle/gradle-dependency-management/build.gradle b/gradle/gradle-dependency-management/build.gradle new file mode 100644 index 0000000000..db908b6457 --- /dev/null +++ b/gradle/gradle-dependency-management/build.gradle @@ -0,0 +1,46 @@ +plugins { + id 'org.springframework.boot' version '2.3.4.RELEASE' + id 'io.spring.dependency-management' version '1.0.10.RELEASE' + id 'java' +} + +group = 'com.gradle' +version = '1.0.0' +sourceCompatibility = '14' + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +ext { + set('testcontainersVersion', "1.14.3") +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-webflux' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } + testImplementation 'io.projectreactor:reactor-test' + testImplementation 'org.springframework.security:spring-security-test' + testImplementation 'org.testcontainers:junit-jupiter' +} + +dependencyManagement { + imports { + mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}" + } +} + +test { + useJUnitPlatform() +} diff --git a/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties b/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..12d38de6a4 --- /dev/null +++ b/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradle/gradle-dependency-management/gradlew b/gradle/gradle-dependency-management/gradlew new file mode 100644 index 0000000000..8f8904743c --- /dev/null +++ b/gradle/gradle-dependency-management/gradlew @@ -0,0 +1,184 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi +done +SAVED="$(pwd)" +cd "$(dirname \"$PRG\")/" >/dev/null +APP_HOME="$(pwd -P)" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=$(basename "$0") + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn() { + echo "$*" +} + +die() { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$(uname)" in +CYGWIN*) + cygwin=true + ;; +Darwin*) + darwin=true + ;; +MINGW*) + msys=true + ;; +NONSTOP*) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then + MAX_FD_LIMIT=$(ulimit -H -n) + if [ $? -eq 0 ]; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ]; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ]; then + APP_HOME=$(cygpath --path --mixed "$APP_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") + + JAVACMD=$(cygpath --unix "$JAVACMD") + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) + SEP="" + for dir in $ROOTDIRSRAW; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ]; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@"; do + CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) + CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition + eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") + else + eval $(echo args$i)="\"$arg\"" + fi + i=$(expr $i + 1) + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save() { + for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradle/gradle-dependency-management/gradlew.bat b/gradle/gradle-dependency-management/gradlew.bat new file mode 100644 index 0000000000..107acd32c4 --- /dev/null +++ b/gradle/gradle-dependency-management/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/gradle/gradle-dependency-management/settings.gradle b/gradle/gradle-dependency-management/settings.gradle new file mode 100644 index 0000000000..09bfe08af7 --- /dev/null +++ b/gradle/gradle-dependency-management/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'dependencymanagement' diff --git a/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java b/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java new file mode 100644 index 0000000000..7e589c0477 --- /dev/null +++ b/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java @@ -0,0 +1,13 @@ +package com.gradle.dependencymanagement; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DependencyManagementApplication { + + public static void main(String[] args) { + SpringApplication.run(DependencyManagementApplication.class, args); + } + +} diff --git a/gradle/gradle-dependency-management/src/main/resources/application.properties b/gradle/gradle-dependency-management/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/gradle/gradle-dependency-management/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java b/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java new file mode 100644 index 0000000000..85634a052e --- /dev/null +++ b/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java @@ -0,0 +1,13 @@ +package com.gradle.dependencymanagement; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DependencyManagementApplicationTests { + + @Test + void contextLoads() { + } + +} From 69d7f51947a4e28f61d3d58eb87adc2fdddd25fc Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Sep 2020 04:04:49 +0530 Subject: [PATCH 007/590] IsLetter / isAlphabetic method unit tests --- .../character/IsLetterOrAlphabetUnitTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java new file mode 100644 index 0000000000..44c712a17f --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.java14.character; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +public class IsLetterOrAlphabetUnitTest { + + @Test + public void givenACharacter_whenLetter_thenAssertIsLetterTrue() { + assertTrue(Character.isLetter(65)); + } + + @Test + public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic(65)); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() { + assertFalse(Character.isLetter(837)); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic(837)); + } + +} \ No newline at end of file From b5e0e559e370178199efda67e5509d60bdecac64 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 3 Oct 2020 11:32:38 +0330 Subject: [PATCH 008/590] add new module to parent pom --- spring-boot-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index fa70a9f058..19dfcbb962 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -26,6 +26,7 @@ spring-boot-artifacts spring-boot-autoconfiguration spring-boot-basic-customization + spring-boot-basic-customization-2 spring-boot-bootstrap spring-boot-client spring-boot-config-jpa-error From 7e56ea33036c8748faa9748244cc7a01ba7c9e24 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 3 Oct 2020 11:33:33 +0330 Subject: [PATCH 009/590] add README file --- .../spring-boot-basic-customization-2/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/README.md diff --git a/spring-boot-modules/spring-boot-basic-customization-2/README.md b/spring-boot-modules/spring-boot-basic-customization-2/README.md new file mode 100644 index 0000000000..faaee0962e --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/README.md @@ -0,0 +1,7 @@ +## Spring Boot Basic Customization 2 + +This module contains articles about Spring Boot customization 2 + +### Relevant Articles: + + - [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/) From 7ffa8ce6a521c5570b305469f8fd7220f1f3e089 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 3 Oct 2020 11:33:57 +0330 Subject: [PATCH 010/590] add gitignore file --- .../.gitignore | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/.gitignore diff --git a/spring-boot-modules/spring-boot-basic-customization-2/.gitignore b/spring-boot-modules/spring-boot-basic-customization-2/.gitignore new file mode 100644 index 0000000000..2af7cefb0a --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file From 17d3411f7c61ef40446e397b55a6f2cd4ed9dc55 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 3 Oct 2020 11:35:16 +0330 Subject: [PATCH 011/590] add main source --- .../spring-boot-basic-customization-2/pom.xml | 33 +++++++++++++++++++ .../com.baeldung.demo/DemoApplication.java | 15 +++++++++ .../java/com.baeldung.demo/conf/WebConf.java | 29 ++++++++++++++++ .../controller/Controller.java | 15 +++++++++ .../filter/CustomFilter.java | 30 +++++++++++++++++ .../listener/CustomListener.java | 22 +++++++++++++ .../servlet/CustomServlet.java | 29 ++++++++++++++++ .../src/main/resources/application.properties | 2 ++ 8 files changed, 175 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/pom.xml create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties diff --git a/spring-boot-modules/spring-boot-basic-customization-2/pom.xml b/spring-boot-modules/spring-boot-basic-customization-2/pom.xml new file mode 100644 index 0000000000..3ce9266ebe --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ + + + spring-boot-basic-customization-2 + jar + + spring-boot-basic-customization-2 + Module For Spring Boot Basic Customization 2 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java new file mode 100644 index 0000000000..9e8148f043 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.annotation.Configuration; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java new file mode 100644 index 0000000000..02fcf152f1 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java @@ -0,0 +1,29 @@ +package com.baeldung.demo.conf; + +import com.baeldung.demo.listener.CustomListener; +import com.baeldung.demo.servlet.CustomServlet; +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.ServletContextListener; + +@Configuration +public class WebConf { + + @Bean + public ServletRegistrationBean customServletBean() { + ServletRegistrationBean bean = + new ServletRegistrationBean(new CustomServlet(), "/servlet"); + return bean; + } + + @Bean + public ServletListenerRegistrationBean customListenerBean() { + ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); + bean.setListener(new CustomListener()); + return bean; + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java new file mode 100644 index 0000000000..a6d1812511 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java @@ -0,0 +1,15 @@ +package com.baeldung.demo.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/") +public class Controller { + + @GetMapping + public String getRequest(){ + return "Baeldung DispatcherServlet"; + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java new file mode 100644 index 0000000000..c661aecf6d --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java @@ -0,0 +1,30 @@ +package com.baeldung.demo.filter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import java.io.IOException; + +@Component +public class CustomFilter implements Filter { + + Logger logger = LoggerFactory.getLogger(CustomFilter.class); + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + logger.info("CustomFilter is invoked"); + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java new file mode 100644 index 0000000000..a9e3ad680f --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java @@ -0,0 +1,22 @@ +package com.baeldung.demo.listener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class CustomListener implements ServletContextListener { + + Logger logger = LoggerFactory.getLogger(CustomListener.class); + + @Override + public void contextInitialized(ServletContextEvent sce) { + logger.info("CustomListener is initialized"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + logger.info("CustomListener is destroyed"); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java new file mode 100644 index 0000000000..fd3e92bedc --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java @@ -0,0 +1,29 @@ +package com.baeldung.demo.servlet; + +import com.baeldung.demo.filter.CustomFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class CustomServlet extends HttpServlet { + + Logger logger = LoggerFactory.getLogger(CustomServlet.class); + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + logger.info("CustomServlet doGet() method is invoked"); + super.doGet(req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + logger.info("CustomServlet doPost() method is invoked"); + super.doPost(req, resp); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties new file mode 100644 index 0000000000..8c4690dedc --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.servlet.context-path=/demo +spring.mvc.servlet.path=/baeldung \ No newline at end of file From b37b135504bd5893ac657cced2434f3621b4c256 Mon Sep 17 00:00:00 2001 From: Thibauld Dujardin <22295595+ThibDujardin@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:25:03 +0200 Subject: [PATCH 012/590] Add Vavr.Tuple example --- .../java/com/baeldung/vavr/VavrUnitTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java index 7beb75632e..b1a9405605 100644 --- a/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java @@ -93,6 +93,37 @@ public class VavrUnitTest { assertEquals("JavaVavr 4", transformed); } + @Test + public void editTupleValueForNewTupleInstance(){ + final Tuple2 java9 = Tuple.of("Java", 8); + final Tuple2 transformed = java9.update2(9); + int num = transformed._2(); + assertEquals(9,num); + } + + @Test + public void editTupleValueForSameInstance(){ + Tuple2 java9 = Tuple.of("Java", 8); + java9 = java9.update2(9); + final int num = java9._2(); + assertEquals(9,num); + } + + @Test + public void getNumberOfElementTuple(){ + Tuple2 java8 = Tuple.of("Java", 8); + Tuple3 java8Triple = Tuple.of("Java", 8, 1.8); + Tuple3 java8TripleWnull = Tuple.of("Java", null, 1.8); + + int num = java8.arity(); + int numTriple = java8Triple.arity(); + int numTripleWnull = java8TripleWnull.arity(); + assertEquals(2,num); + assertEquals(3,numTriple); + assertEquals(3,numTripleWnull); + } + + /* * Functions */ From da6fb652fbf0c732dd7a0a4d34736a15d06aa343 Mon Sep 17 00:00:00 2001 From: sharifi Date: Fri, 9 Oct 2020 11:36:07 +0330 Subject: [PATCH 013/590] remove gitignore file --- .../.gitignore | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/.gitignore diff --git a/spring-boot-modules/spring-boot-basic-customization-2/.gitignore b/spring-boot-modules/spring-boot-basic-customization-2/.gitignore deleted file mode 100644 index 2af7cefb0a..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file From 5cb3bc85bea94ab6414df0e218ec0c7898f27d55 Mon Sep 17 00:00:00 2001 From: sharifi Date: Fri, 9 Oct 2020 11:48:10 +0330 Subject: [PATCH 014/590] change package name and main class's name --- .../DispatchServletApplication.java} | 6 +++--- .../conf/WebConf.java | 6 +++--- .../controller/Controller.java | 2 +- .../filter/CustomFilter.java | 2 +- .../listener/CustomListener.java | 2 +- .../servlet/CustomServlet.java | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo/DemoApplication.java => com.baeldung.dispatchservlet/DispatchServletApplication.java} (68%) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo => com.baeldung.dispatchservlet}/conf/WebConf.java (83%) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo => com.baeldung.dispatchservlet}/controller/Controller.java (88%) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo => com.baeldung.dispatchservlet}/filter/CustomFilter.java (93%) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo => com.baeldung.dispatchservlet}/listener/CustomListener.java (92%) rename spring-boot-modules/spring-boot-basic-customization-2/src/main/java/{com.baeldung.demo => com.baeldung.dispatchservlet}/servlet/CustomServlet.java (89%) diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java similarity index 68% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java index 9e8148f043..4d58715d88 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/DemoApplication.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.demo; +package com.baeldung.dispatchservlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,10 +6,10 @@ import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.Configuration; @SpringBootApplication -public class DemoApplication { +public class DispatchServletApplication { public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); + SpringApplication.run(DispatchServletApplication.class, args); } } diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java similarity index 83% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java index 02fcf152f1..9a1170ca34 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/conf/WebConf.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java @@ -1,7 +1,7 @@ -package com.baeldung.demo.conf; +package com.baeldung.dispatchservlet.conf; -import com.baeldung.demo.listener.CustomListener; -import com.baeldung.demo.servlet.CustomServlet; +import com.baeldung.dispatchservlet.listener.CustomListener; +import com.baeldung.dispatchservlet.servlet.CustomServlet; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java similarity index 88% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java index a6d1812511..14d71c60fb 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/controller/Controller.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java @@ -1,4 +1,4 @@ -package com.baeldung.demo.controller; +package com.baeldung.dispatchservlet.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java similarity index 93% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java index c661aecf6d..8429fc855f 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/filter/CustomFilter.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java @@ -1,4 +1,4 @@ -package com.baeldung.demo.filter; +package com.baeldung.dispatchservlet.filter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java similarity index 92% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java index a9e3ad680f..62b316c012 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/listener/CustomListener.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java @@ -1,4 +1,4 @@ -package com.baeldung.demo.listener; +package com.baeldung.dispatchservlet.listener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java similarity index 89% rename from spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java index fd3e92bedc..2a99e797ce 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.demo/servlet/CustomServlet.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java @@ -1,6 +1,6 @@ -package com.baeldung.demo.servlet; +package com.baeldung.dispatchservlet.servlet; -import com.baeldung.demo.filter.CustomFilter; +import com.baeldung.dispatchservlet.filter.CustomFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 271ad4e3c7224b1ea65fe66146767622598832fe Mon Sep 17 00:00:00 2001 From: sharifi Date: Fri, 9 Oct 2020 11:48:57 +0330 Subject: [PATCH 015/590] remove context-path and path --- .../src/main/resources/application.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties index 8c4690dedc..e69de29bb2 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/resources/application.properties @@ -1,2 +0,0 @@ -server.servlet.context-path=/demo -spring.mvc.servlet.path=/baeldung \ No newline at end of file From 4260a798d11a749c2f987ef2ebc318d863b68c2d Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Fri, 9 Oct 2020 12:41:53 +0200 Subject: [PATCH 016/590] Update dependencies --- .../gradle-dependency-management/build.gradle | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/gradle/gradle-dependency-management/build.gradle b/gradle/gradle-dependency-management/build.gradle index db908b6457..88ed84f4b1 100644 --- a/gradle/gradle-dependency-management/build.gradle +++ b/gradle/gradle-dependency-management/build.gradle @@ -1,44 +1,30 @@ plugins { - id 'org.springframework.boot' version '2.3.4.RELEASE' - id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' + id 'org.springframework.boot' version '2.3.4.RELEASE' } group = 'com.gradle' version = '1.0.0' sourceCompatibility = '14' -configurations { - compileOnly { - extendsFrom annotationProcessor - } -} - repositories { mavenCentral() } -ext { - set('testcontainersVersion', "1.14.3") -} - dependencies { - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-webflux' - developmentOnly 'org.springframework.boot:spring-boot-devtools' - annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' - testImplementation('org.springframework.boot:spring-boot-starter-test') { - exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' - } - testImplementation 'io.projectreactor:reactor-test' - testImplementation 'org.springframework.security:spring-security-test' - testImplementation 'org.testcontainers:junit-jupiter' -} + implementation 'org.springframework.boot:spring-boot-starter:2.3.4.RELEASE' -dependencyManagement { - imports { - mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}" - } + testImplementation 'org.springframework.boot:spring-boot-starter-test:2.3.4.RELEASE' + + compileOnly 'org.projectlombok:lombok:1.18.14' + + testCompileOnly 'org.projectlombok:lombok:1.18.14' + + runtimeOnly files('libs/sampleOne.jar', 'libs/sampleTwo.jar') + + runtimeOnly fileTree('libs') { include '*.jar' } + +// implementation gradleApi() } test { From 6cf54b019aecfc09a0f37b279a5a5e8b8aaae762 Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Fri, 9 Oct 2020 12:53:49 +0200 Subject: [PATCH 017/590] Add article to README --- gradle/README.md | 1 + gradle/gradle-dependency-management/README.md | 3 +++ ...ests.java => DependencyManagementApplicationUnitTests.java} | 0 3 files changed, 4 insertions(+) create mode 100644 gradle/gradle-dependency-management/README.md rename gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/{DependencyManagementApplicationTests.java => DependencyManagementApplicationUnitTests.java} (100%) diff --git a/gradle/README.md b/gradle/README.md index 84a8508e2c..422bc0fcc5 100644 --- a/gradle/README.md +++ b/gradle/README.md @@ -8,3 +8,4 @@ This module contains articles about Gradle - [Creating a Fat Jar in Gradle](https://www.baeldung.com/gradle-fat-jar) - [A Custom Task in Gradle](https://www.baeldung.com/gradle-custom-task) - [Using JUnit 5 with Gradle](https://www.baeldung.com/junit-5-gradle) +- [Dependency Management in Gradle](https://www.baeldung.com/TBD) diff --git a/gradle/gradle-dependency-management/README.md b/gradle/gradle-dependency-management/README.md new file mode 100644 index 0000000000..b46ae5b596 --- /dev/null +++ b/gradle/gradle-dependency-management/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Dependency Management in Gradle](https://www.baeldung.com/TBD) diff --git a/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java b/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java similarity index 100% rename from gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationTests.java rename to gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java From f80f82781fa29f76068cd25368d00cbb5926566c Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 11 Oct 2020 10:22:42 +0200 Subject: [PATCH 018/590] BAEL-4504: Move find free port to networking-3 --- .../core-java-networking-3/README.md | 8 + .../core-java-networking-3/pom.xml | 59 +++++++ .../baeldung/socket/FindFreePortUnitTest.java | 146 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 core-java-modules/core-java-networking-3/README.md create mode 100644 core-java-modules/core-java-networking-3/pom.xml create mode 100644 core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java diff --git a/core-java-modules/core-java-networking-3/README.md b/core-java-modules/core-java-networking-3/README.md new file mode 100644 index 0000000000..a81e85751d --- /dev/null +++ b/core-java-modules/core-java-networking-3/README.md @@ -0,0 +1,8 @@ +## Core Java Networking (Part 3) + +This module contains articles about networking in Java + +### Relevant Articles + +- TODO: add link once live +- [[<-- Prev]](/core-java-modules/core-java-networking-2) diff --git a/core-java-modules/core-java-networking-3/pom.xml b/core-java-modules/core-java-networking-3/pom.xml new file mode 100644 index 0000000000..2a5522074a --- /dev/null +++ b/core-java-modules/core-java-networking-3/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + core-java-networking-4 + core-java-networking-3 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.springframework + spring-core + ${spring.core.version} + + + org.eclipse.jetty + jetty-server + ${jetty.embeded.version} + + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat.embeded.version} + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + core-java-networking-3 + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + 5.2.8.RELEASE + 9.4.31.v20200723 + 10.0.0-M7 + 3.11.1 + + + diff --git a/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java new file mode 100644 index 0000000000..6402a086e6 --- /dev/null +++ b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java @@ -0,0 +1,146 @@ +package com.baeldung.socket; + +import org.apache.catalina.LifecycleException; +import org.apache.catalina.startup.Tomcat; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.util.SocketUtils; + +import java.io.IOException; +import java.net.ServerSocket; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + +public class FindFreePortUnitTest { + + private static int FREE_PORT_NUMBER; + private static int[] FREE_PORT_RANGE; + + @BeforeAll + public static void getExplicitFreePortNumberAndRange() { + try (ServerSocket serverSocket = new ServerSocket(0);) { + FREE_PORT_NUMBER = serverSocket.getLocalPort(); + FREE_PORT_RANGE = new int[] {FREE_PORT_NUMBER, FREE_PORT_NUMBER + 1, FREE_PORT_NUMBER + 2}; + } catch (IOException e) { + fail("No free port is available"); + } + } + + @Test + public void givenExplicitFreePort_whenCreatingServerSocket_thenThatPortIsAssigned() { + try (ServerSocket serverSocket = new ServerSocket(FREE_PORT_NUMBER);) { + assertThat(serverSocket).isNotNull(); + assertThat(serverSocket.getLocalPort()).isEqualTo(FREE_PORT_NUMBER); + } catch (IOException e) { + fail("Port is not available"); + } + } + + @Test + public void givenExplicitOccupiedPort_whenCreatingServerSocket_thenExceptionIsThrown() { + try (ServerSocket serverSocket = new ServerSocket(FREE_PORT_NUMBER)) { + new ServerSocket(FREE_PORT_NUMBER); + fail("Same port cannot be used twice"); + } catch (IOException e) { + assertThat(e).hasMessageContaining("Address already in use"); + } + } + + @Test + public void givenExplicitPortRange_whenCreatingServerSocket_thenOnePortIsAssigned() { + for (int port : FREE_PORT_RANGE) { + try (ServerSocket serverSocket = new ServerSocket(port)) { + assertThat(serverSocket).isNotNull(); + assertThat(serverSocket.getLocalPort()).isGreaterThan(0); + return; + } catch (IOException e) { + assertThat(e).hasMessageContaining("Address already in use"); + } + } + fail("No free port in the range found"); + } + + @Test + public void givenPortZero_whenCreatingServerSocket_thenFreePortIsAssigned() { + try (ServerSocket serverSocket = new ServerSocket(0)) { + assertThat(serverSocket).isNotNull(); + assertThat(serverSocket.getLocalPort()).isGreaterThan(0); + } catch (IOException e) { + fail("Port is not available"); + } + } + + @Test + public void givenAvailableTcpPort_whenCreatingServerSocket_thenThatPortIsAssigned() { + int port = SocketUtils.findAvailableTcpPort(); + try (ServerSocket serverSocket = new ServerSocket(port)) { + assertThat(serverSocket).isNotNull(); + assertThat(serverSocket.getLocalPort()).isGreaterThan(0); + } catch (IOException e) { + fail("Port is not available"); + } + } + + @Test + public void givenNoPortDefined_whenCreatingJettyServer_thenFreePortIsAssigned() { + Server jettyServer = new Server(); + ServerConnector serverConnector = new ServerConnector(jettyServer); + jettyServer.addConnector(serverConnector); + try { + jettyServer.start(); + assertThat(serverConnector.getLocalPort()).isGreaterThan(0); + jettyServer.stop(); + jettyServer.destroy(); + } catch (Exception e) { + fail("Failed to start Jetty server"); + } + } + + @Test + public void givenExplicitFreePort_whenCreatingJettyServer_thenThatPortIsAssigned() { + Server jettyServer = new Server(); + ServerConnector serverConnector = new ServerConnector(jettyServer); + serverConnector.setPort(FREE_PORT_NUMBER); + jettyServer.addConnector(serverConnector); + try { + jettyServer.start(); + assertThat(serverConnector.getLocalPort()).isEqualTo(FREE_PORT_NUMBER); + jettyServer.stop(); + jettyServer.destroy(); + } catch (Exception e) { + fail("Failed to start Jetty server"); + } + } + + @Test + public void givenPortZero_whenCreatingTomcatServer_thenFreePortIsAssigned() { + Tomcat tomcatServer = new Tomcat(); + tomcatServer.setPort(0); + try { + tomcatServer.start(); + assertThat(tomcatServer.getConnector().getLocalPort()).isGreaterThan(0); + tomcatServer.stop(); + tomcatServer.destroy(); + } catch (LifecycleException e) { + fail("Failed to start Tomcat server"); + } + } + + @Test + public void givenExplicitFreePort_whenCreatingTomcatServer_thenThatPortIsAssigned() { + Tomcat tomcatServer = new Tomcat(); + tomcatServer.setPort(FREE_PORT_NUMBER); + try { + tomcatServer.start(); + assertThat(tomcatServer.getConnector().getLocalPort()).isEqualTo(FREE_PORT_NUMBER); + tomcatServer.stop(); + tomcatServer.destroy(); + } catch (LifecycleException e) { + fail("Failed to start Tomcat server"); + } + } + +} From 42455830c0b186042f4073b9dccaaee824cc7a86 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 11 Oct 2020 11:14:36 +0200 Subject: [PATCH 019/590] BAEL-4504: Fix PR comments --- .../java/com/baeldung/socket/FindFreePortUnitTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java index 6402a086e6..d045f753ea 100644 --- a/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java +++ b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java @@ -21,7 +21,7 @@ public class FindFreePortUnitTest { @BeforeAll public static void getExplicitFreePortNumberAndRange() { - try (ServerSocket serverSocket = new ServerSocket(0);) { + try (ServerSocket serverSocket = new ServerSocket(0)) { FREE_PORT_NUMBER = serverSocket.getLocalPort(); FREE_PORT_RANGE = new int[] {FREE_PORT_NUMBER, FREE_PORT_NUMBER + 1, FREE_PORT_NUMBER + 2}; } catch (IOException e) { @@ -31,7 +31,7 @@ public class FindFreePortUnitTest { @Test public void givenExplicitFreePort_whenCreatingServerSocket_thenThatPortIsAssigned() { - try (ServerSocket serverSocket = new ServerSocket(FREE_PORT_NUMBER);) { + try (ServerSocket serverSocket = new ServerSocket(FREE_PORT_NUMBER)) { assertThat(serverSocket).isNotNull(); assertThat(serverSocket.getLocalPort()).isEqualTo(FREE_PORT_NUMBER); } catch (IOException e) { @@ -54,7 +54,7 @@ public class FindFreePortUnitTest { for (int port : FREE_PORT_RANGE) { try (ServerSocket serverSocket = new ServerSocket(port)) { assertThat(serverSocket).isNotNull(); - assertThat(serverSocket.getLocalPort()).isGreaterThan(0); + assertThat(serverSocket.getLocalPort()).isEqualTo(port); return; } catch (IOException e) { assertThat(e).hasMessageContaining("Address already in use"); @@ -78,7 +78,7 @@ public class FindFreePortUnitTest { int port = SocketUtils.findAvailableTcpPort(); try (ServerSocket serverSocket = new ServerSocket(port)) { assertThat(serverSocket).isNotNull(); - assertThat(serverSocket.getLocalPort()).isGreaterThan(0); + assertThat(serverSocket.getLocalPort()).isEqualTo(port); } catch (IOException e) { fail("Port is not available"); } From 40029ed9fc95dd04b548b51f91d564c93299a969 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 11 Oct 2020 11:16:32 +0200 Subject: [PATCH 020/590] BAEL-4504: Wrong artifact ID --- core-java-modules/core-java-networking-3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-networking-3/pom.xml b/core-java-modules/core-java-networking-3/pom.xml index 2a5522074a..d72981f862 100644 --- a/core-java-modules/core-java-networking-3/pom.xml +++ b/core-java-modules/core-java-networking-3/pom.xml @@ -4,7 +4,7 @@ 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 - core-java-networking-4 + core-java-networking-3 core-java-networking-3 jar From b447b94b5037f2c9078d2104d4b92e7759eefbfc Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 11 Oct 2020 16:26:31 +0530 Subject: [PATCH 021/590] moved spring-rest-compress module to spring-resttemplate-2 module --- spring-resttemplate-2/README.md | 1 + spring-resttemplate-2/pom.xml | 23 ++++++++ ...mpressingClientHttpRequestInterceptor.java | 38 +++++++++++++ .../java/com/baeldung/compress/GzipUtils.java | 52 +++++++++++++++++ .../compress/JettyWebServerConfiguration.java | 38 +++++++++++++ .../java/com/baeldung/compress/Message.java | 29 ++++++++++ .../baeldung/compress/MessageController.java | 38 +++++++++++++ .../compress/RestTemplateConfiguration.java | 21 +++++++ .../SpringCompressRequestApplication.java | 15 +++++ .../baeldung/compress/GzipUtilsUnitTest.java | 19 +++++++ .../compress/MessageControllerUnitTest.java | 56 +++++++++++++++++++ 11 files changed, 330 insertions(+) create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java create mode 100644 spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java create mode 100644 spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java diff --git a/spring-resttemplate-2/README.md b/spring-resttemplate-2/README.md index e1e0ba40b0..37d8ac9740 100644 --- a/spring-resttemplate-2/README.md +++ b/spring-resttemplate-2/README.md @@ -8,3 +8,4 @@ This module contains articles about Spring RestTemplate - [Proxies With RestTemplate](https://www.baeldung.com/java-resttemplate-proxy) - [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type) - [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) +- [How to compress requests using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) diff --git a/spring-resttemplate-2/pom.xml b/spring-resttemplate-2/pom.xml index b1d6f60c53..2aed154be6 100644 --- a/spring-resttemplate-2/pom.xml +++ b/spring-resttemplate-2/pom.xml @@ -20,7 +20,30 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-jetty + + + + org.apache.httpcomponents + httpclient + + + + commons-io + commons-io + ${commons-io.version} + + org.springframework.boot spring-boot-starter-test diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java new file mode 100644 index 0000000000..e880e8f915 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java @@ -0,0 +1,38 @@ +package com.baeldung.compress; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; + +import java.io.IOException; + +public class CompressingClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { + + private static final Logger LOG = LoggerFactory.getLogger(CompressingClientHttpRequestInterceptor.class); + + private static final String GZIP_ENCODING = "gzip"; + + /** + * Compress a request body using Gzip and add Http headers. + * + * @param req + * @param body + * @param exec + * @return + * @throws IOException + */ + @Override + public ClientHttpResponse intercept(HttpRequest req, byte[] body, ClientHttpRequestExecution exec) + throws IOException { + LOG.info("Compressing request..."); + HttpHeaders httpHeaders = req.getHeaders(); + httpHeaders.add(HttpHeaders.CONTENT_ENCODING, GZIP_ENCODING); + httpHeaders.add(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING); + return exec.execute(req, GzipUtils.compress(body)); + } + +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java new file mode 100644 index 0000000000..50c565d92c --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java @@ -0,0 +1,52 @@ +package com.baeldung.compress; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import org.apache.commons.io.IOUtils; + +public class GzipUtils { + + /** + * Gzip a string. + * + * @param text + * @return + * @throws Exception + */ + public static byte[] compress(String text) throws Exception { + return GzipUtils.compress(text.getBytes(StandardCharsets.UTF_8)); + } + + /** + * Gzip a byte array. + * + * @param body + * @return + * @throws IOException + */ + public static byte[] compress(byte[] body) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(baos)) { + gzipOutputStream.write(body); + } + return baos.toByteArray(); + } + + /** + * Decompress a Gzipped byte array to a String. + * + * @param body + * @return + * @throws IOException + */ + public static String decompress(byte[] body) throws IOException { + try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(body))) { + return IOUtils.toString(gzipInputStream, StandardCharsets.UTF_8); + } + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java new file mode 100644 index 0000000000..3ac8c31ab3 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java @@ -0,0 +1,38 @@ +package com.baeldung.compress; + +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.server.handler.gzip.GzipHandler; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Configure Jetty web server so it handles compressed requests. + */ +@Configuration +public class JettyWebServerConfiguration { + + private static final int MIN_BYTES = 1; + + /** + * Customise the Jetty web server to automatically decompress requests. + */ + @Bean + public JettyServletWebServerFactory jettyServletWebServerFactory() { + + JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); + factory.addServerCustomizers(server -> { + + GzipHandler gzipHandler = new GzipHandler(); + // Enable request decompression + gzipHandler.setInflateBufferSize(MIN_BYTES); + gzipHandler.setHandler(server.getHandler()); + + HandlerCollection handlerCollection = new HandlerCollection(gzipHandler); + server.setHandler(handlerCollection); + }); + + return factory; + } + +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java new file mode 100644 index 0000000000..f43d06c2fc --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java @@ -0,0 +1,29 @@ +package com.baeldung.compress; + +public class Message { + + private String text; + + public Message() { + } + + public Message(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Message {"); + sb.append("text='").append(text).append('\''); + sb.append('}'); + return sb.toString(); + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java new file mode 100644 index 0000000000..ec574d9dec --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java @@ -0,0 +1,38 @@ +package com.baeldung.compress; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class MessageController { + + protected static final String PROCESSED = "Processed "; + + protected static final String REQUEST_MAPPING = "process"; + + private static final Logger LOG = LoggerFactory.getLogger(MessageController.class); + + /** + * A simple endpoint that responds with "Processed " + supplied Message content. + * + * @param headers + * @param message + * @return + */ + @PostMapping(value = REQUEST_MAPPING) + public ResponseEntity processMessage(@RequestHeader Map headers, + @RequestBody Message message) { + + // Print headers + headers.forEach((k, v) -> LOG.info(k + "=" + v)); + + return ResponseEntity.ok(PROCESSED + message.getText()); + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java new file mode 100644 index 0000000000..12b1e4249e --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.compress; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfiguration { + + /** + * A RestTemplate that compresses requests. + * + * @return RestTemplate + */ + @Bean + public RestTemplate getRestTemplate() { + RestTemplate restTemplate = new RestTemplate(); + restTemplate.getInterceptors().add(new CompressingClientHttpRequestInterceptor()); + return restTemplate; + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java b/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java new file mode 100644 index 0000000000..9ff88ab257 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.compress; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class SpringCompressRequestApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringCompressRequestApplication.class, args); + } + +} diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java new file mode 100644 index 0000000000..10c2eeb748 --- /dev/null +++ b/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.compress; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class GzipUtilsUnitTest { + + @Test + public void givenCompressedText_whenDecompressed_thenSuccessful() throws Exception { + final String expectedText = "Hello Baeldung!"; + byte[] compressedText = GzipUtils.compress(expectedText); + String decompressedText = GzipUtils.decompress(compressedText); + assertNotNull(compressedText); + assertEquals(expectedText, decompressedText); + } + +} \ No newline at end of file diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java new file mode 100644 index 0000000000..643e3f6881 --- /dev/null +++ b/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.compress; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class MessageControllerUnitTest { + + private static final Logger LOG = LoggerFactory.getLogger(MessageControllerUnitTest.class); + + @Autowired + private RestTemplate restTemplate; + + @LocalServerPort + private int randomServerPort; + + /** + * As a further test you can intercept the request body, using a tool like + * Wireshark, to see the request body is actually gzipped. + * + * @throws Exception + */ + @Test + public void givenRestTemplate_whenPostCompressedRequest_thenRespondsSuccessfully() throws Exception { + + final String text = "Hello Baeldung!"; + Message message = new Message(text); + + HttpEntity request = new HttpEntity<>(message); + String uri = String.format("http://localhost:%s/%s", randomServerPort, MessageController.REQUEST_MAPPING); + + ResponseEntity responseEntity = restTemplate.postForEntity(uri, request, String.class); + + String response = responseEntity.getBody(); + LOG.info("Got response [{}]", response); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertNotNull(response); + assertEquals(MessageController.PROCESSED + text, response); + } + +} From afe9a94a4e8f5afdf1e3f355ae64e2ceb21e0a85 Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Mon, 12 Oct 2020 08:07:01 +0200 Subject: [PATCH 022/590] Remove unnecessary files --- gradle/gradle-dependency-management/gradlew | 184 ------------------ .../gradle-dependency-management/gradlew.bat | 89 --------- 2 files changed, 273 deletions(-) delete mode 100644 gradle/gradle-dependency-management/gradlew delete mode 100644 gradle/gradle-dependency-management/gradlew.bat diff --git a/gradle/gradle-dependency-management/gradlew b/gradle/gradle-dependency-management/gradlew deleted file mode 100644 index 8f8904743c..0000000000 --- a/gradle/gradle-dependency-management/gradlew +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG=$(dirname "$PRG")"/$link" - fi -done -SAVED="$(pwd)" -cd "$(dirname \"$PRG\")/" >/dev/null -APP_HOME="$(pwd -P)" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=$(basename "$0") - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn() { - echo "$*" -} - -die() { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$(uname)" in -CYGWIN*) - cygwin=true - ;; -Darwin*) - darwin=true - ;; -MINGW*) - msys=true - ;; -NONSTOP*) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ]; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then - MAX_FD_LIMIT=$(ulimit -H -n) - if [ $? -eq 0 ]; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ]; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ]; then - APP_HOME=$(cygpath --path --mixed "$APP_HOME") - CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") - - JAVACMD=$(cygpath --unix "$JAVACMD") - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) - SEP="" - for dir in $ROOTDIRSRAW; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ]; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@"; do - CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) - CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition - eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") - else - eval $(echo args$i)="\"$arg\"" - fi - i=$(expr $i + 1) - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save() { - for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradle/gradle-dependency-management/gradlew.bat b/gradle/gradle-dependency-management/gradlew.bat deleted file mode 100644 index 107acd32c4..0000000000 --- a/gradle/gradle-dependency-management/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega From f0b9b3db29ccb0b59b7cbefb219c0584a06278bd Mon Sep 17 00:00:00 2001 From: sharifi Date: Mon, 12 Oct 2020 23:07:48 +0330 Subject: [PATCH 023/590] separate directories --- .../DispatchServletApplication.java | 15 ++++++++++ .../dispatchservlet/conf/WebConf.java | 29 ++++++++++++++++++ .../controller/Controller.java | 15 ++++++++++ .../dispatchservlet/filter/CustomFilter.java | 30 +++++++++++++++++++ .../listener/CustomListener.java | 22 ++++++++++++++ .../servlet/CustomServlet.java | 29 ++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/DispatchServletApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/controller/Controller.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/filter/CustomFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/listener/CustomListener.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/servlet/CustomServlet.java diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/DispatchServletApplication.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/DispatchServletApplication.java new file mode 100644 index 0000000000..4d58715d88 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/DispatchServletApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.dispatchservlet; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.annotation.Configuration; + +@SpringBootApplication +public class DispatchServletApplication { + + public static void main(String[] args) { + SpringApplication.run(DispatchServletApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java new file mode 100644 index 0000000000..9a1170ca34 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java @@ -0,0 +1,29 @@ +package com.baeldung.dispatchservlet.conf; + +import com.baeldung.dispatchservlet.listener.CustomListener; +import com.baeldung.dispatchservlet.servlet.CustomServlet; +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.ServletContextListener; + +@Configuration +public class WebConf { + + @Bean + public ServletRegistrationBean customServletBean() { + ServletRegistrationBean bean = + new ServletRegistrationBean(new CustomServlet(), "/servlet"); + return bean; + } + + @Bean + public ServletListenerRegistrationBean customListenerBean() { + ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); + bean.setListener(new CustomListener()); + return bean; + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/controller/Controller.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/controller/Controller.java new file mode 100644 index 0000000000..14d71c60fb --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/controller/Controller.java @@ -0,0 +1,15 @@ +package com.baeldung.dispatchservlet.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/") +public class Controller { + + @GetMapping + public String getRequest(){ + return "Baeldung DispatcherServlet"; + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/filter/CustomFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/filter/CustomFilter.java new file mode 100644 index 0000000000..8429fc855f --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/filter/CustomFilter.java @@ -0,0 +1,30 @@ +package com.baeldung.dispatchservlet.filter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import java.io.IOException; + +@Component +public class CustomFilter implements Filter { + + Logger logger = LoggerFactory.getLogger(CustomFilter.class); + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + logger.info("CustomFilter is invoked"); + chain.doFilter(request, response); + } + + @Override + public void destroy() { + + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/listener/CustomListener.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/listener/CustomListener.java new file mode 100644 index 0000000000..62b316c012 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/listener/CustomListener.java @@ -0,0 +1,22 @@ +package com.baeldung.dispatchservlet.listener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class CustomListener implements ServletContextListener { + + Logger logger = LoggerFactory.getLogger(CustomListener.class); + + @Override + public void contextInitialized(ServletContextEvent sce) { + logger.info("CustomListener is initialized"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + logger.info("CustomListener is destroyed"); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/servlet/CustomServlet.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/servlet/CustomServlet.java new file mode 100644 index 0000000000..2a99e797ce --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/servlet/CustomServlet.java @@ -0,0 +1,29 @@ +package com.baeldung.dispatchservlet.servlet; + +import com.baeldung.dispatchservlet.filter.CustomFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class CustomServlet extends HttpServlet { + + Logger logger = LoggerFactory.getLogger(CustomServlet.class); + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + logger.info("CustomServlet doGet() method is invoked"); + super.doGet(req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + logger.info("CustomServlet doPost() method is invoked"); + super.doPost(req, resp); + } +} From eeadbb04f0521eb0db15f908be861320a04ad8f7 Mon Sep 17 00:00:00 2001 From: sharifi Date: Wed, 14 Oct 2020 15:32:29 +0330 Subject: [PATCH 024/590] delete the original classes related to separate the directories --- .../DispatchServletApplication.java | 15 ---------- .../conf/WebConf.java | 29 ------------------ .../controller/Controller.java | 15 ---------- .../filter/CustomFilter.java | 30 ------------------- .../listener/CustomListener.java | 22 -------------- .../servlet/CustomServlet.java | 29 ------------------ 6 files changed, 140 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java delete mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java deleted file mode 100644 index 4d58715d88..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/DispatchServletApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.dispatchservlet; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.ServletComponentScan; -import org.springframework.context.annotation.Configuration; - -@SpringBootApplication -public class DispatchServletApplication { - - public static void main(String[] args) { - SpringApplication.run(DispatchServletApplication.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java deleted file mode 100644 index 9a1170ca34..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/conf/WebConf.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.dispatchservlet.conf; - -import com.baeldung.dispatchservlet.listener.CustomListener; -import com.baeldung.dispatchservlet.servlet.CustomServlet; -import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; -import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.servlet.ServletContextListener; - -@Configuration -public class WebConf { - - @Bean - public ServletRegistrationBean customServletBean() { - ServletRegistrationBean bean = - new ServletRegistrationBean(new CustomServlet(), "/servlet"); - return bean; - } - - @Bean - public ServletListenerRegistrationBean customListenerBean() { - ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(); - bean.setListener(new CustomListener()); - return bean; - } - -} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java deleted file mode 100644 index 14d71c60fb..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/controller/Controller.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.dispatchservlet.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping(value = "/") -public class Controller { - - @GetMapping - public String getRequest(){ - return "Baeldung DispatcherServlet"; - } -} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java deleted file mode 100644 index 8429fc855f..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/filter/CustomFilter.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.dispatchservlet.filter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import javax.servlet.*; -import java.io.IOException; - -@Component -public class CustomFilter implements Filter { - - Logger logger = LoggerFactory.getLogger(CustomFilter.class); - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - logger.info("CustomFilter is invoked"); - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - } -} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java deleted file mode 100644 index 62b316c012..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/listener/CustomListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.dispatchservlet.listener; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -public class CustomListener implements ServletContextListener { - - Logger logger = LoggerFactory.getLogger(CustomListener.class); - - @Override - public void contextInitialized(ServletContextEvent sce) { - logger.info("CustomListener is initialized"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - logger.info("CustomListener is destroyed"); - } -} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java deleted file mode 100644 index 2a99e797ce..0000000000 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com.baeldung.dispatchservlet/servlet/CustomServlet.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.dispatchservlet.servlet; - -import com.baeldung.dispatchservlet.filter.CustomFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class CustomServlet extends HttpServlet { - - Logger logger = LoggerFactory.getLogger(CustomServlet.class); - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - logger.info("CustomServlet doGet() method is invoked"); - super.doGet(req, resp); - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - logger.info("CustomServlet doPost() method is invoked"); - super.doPost(req, resp); - } -} From bbdf2ae68606b19dedd331453375fadc9dbc315c Mon Sep 17 00:00:00 2001 From: "mateusz.szablak" Date: Thu, 15 Oct 2020 16:08:49 +0200 Subject: [PATCH 025/590] BAEL-4212 (String) or .toString()? - code + tests --- .../baeldung/tostring/StringCastUtils.java | 10 ++ .../baeldung/tostring/ToStringUnitTest.java | 92 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java create mode 100644 core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java new file mode 100644 index 0000000000..056f961ea4 --- /dev/null +++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java @@ -0,0 +1,10 @@ +package com.baeldung.tostring; + +public class StringCastUtils { + public static String castToString(Object object) { + if (object instanceof String) { + return (String) object; + } + return null; + } +} diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java new file mode 100644 index 0000000000..88202e1797 --- /dev/null +++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java @@ -0,0 +1,92 @@ +package com.baeldung.tostring; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ToStringUnitTest { + @Test + public void givenString_whenCastToObjectAndString_thenSameAndNoException() { + String input = "baeldung"; + + Object obj = input; + String str = (String) obj; + + assertEquals(obj, str); + assertEquals(str, input); + assertSame(input, str); + } + + @Test(expected = ClassCastException.class) + public void givenIntegerObject_whenCastToObjectAndString_thenCastClassException() { + Integer input = 1234; + + Object obj = input; + String str = (String) obj; + } + + @Test + public void givenNullInteger_whenCastToObjectAndString_thenSameAndNoException() { + Integer input = null; + + Object obj = input; + String str = (String) obj; + + assertEquals(obj, str); + assertEquals(str, input); + assertSame(input, str); + } + + @Test(expected = NullPointerException.class) + public void givenNullInteger_whenToString_thenNullPointerException() { + Integer input = null; + + String str = input.toString(); + } + + @Test + public void givenInteger_whenCastToObject_thenToStringEquals() { + Integer input = 1234; + + Object obj = input; + + assertEquals("1234", input.toString()); + assertEquals("1234", obj.toString()); + assertEquals(input.toString(), obj.toString()); + } + + @Test + public void givenString_whenToString_thenSame() { + String str = "baeldung"; + + assertEquals("baeldung", str.toString()); + assertSame(str, str.toString()); + } + + @Test + public void givenString_whenCastToObject_thenCastToStringReturnsSame() { + String input = "baeldung"; + + Object obj = input; + + assertSame(input, StringCastUtils.castToString(obj)); + } + + @Test + public void givenInteger_whenCastToObject_thenCastToStringReturnsNull() { + Integer input = 1234; + + Object obj = input; + + assertEquals(null, StringCastUtils.castToString(obj)); + } + + @Test + public void givenIntegerNull_whenCastToObject_thenCastToStringReturnsNull() { + Integer input = null; + + Object obj = input; + + assertEquals(null, StringCastUtils.castToString(obj)); + } +} From 061fa3d12a7f7046b253580eca1a75de62ee2451 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Thu, 15 Oct 2020 16:59:16 +0200 Subject: [PATCH 026/590] BAEL-4504: Add finally --- .../baeldung/socket/FindFreePortUnitTest.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java index d045f753ea..95530ef292 100644 --- a/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java +++ b/core-java-modules/core-java-networking-3/src/test/java/com/baeldung/socket/FindFreePortUnitTest.java @@ -85,22 +85,23 @@ public class FindFreePortUnitTest { } @Test - public void givenNoPortDefined_whenCreatingJettyServer_thenFreePortIsAssigned() { + public void givenNoPortDefined_whenCreatingJettyServer_thenFreePortIsAssigned() throws Exception { Server jettyServer = new Server(); ServerConnector serverConnector = new ServerConnector(jettyServer); jettyServer.addConnector(serverConnector); try { jettyServer.start(); assertThat(serverConnector.getLocalPort()).isGreaterThan(0); - jettyServer.stop(); - jettyServer.destroy(); } catch (Exception e) { fail("Failed to start Jetty server"); + } finally { + jettyServer.stop(); + jettyServer.destroy(); } } @Test - public void givenExplicitFreePort_whenCreatingJettyServer_thenThatPortIsAssigned() { + public void givenExplicitFreePort_whenCreatingJettyServer_thenThatPortIsAssigned() throws Exception { Server jettyServer = new Server(); ServerConnector serverConnector = new ServerConnector(jettyServer); serverConnector.setPort(FREE_PORT_NUMBER); @@ -108,38 +109,41 @@ public class FindFreePortUnitTest { try { jettyServer.start(); assertThat(serverConnector.getLocalPort()).isEqualTo(FREE_PORT_NUMBER); - jettyServer.stop(); - jettyServer.destroy(); } catch (Exception e) { fail("Failed to start Jetty server"); + } finally { + jettyServer.stop(); + jettyServer.destroy(); } } @Test - public void givenPortZero_whenCreatingTomcatServer_thenFreePortIsAssigned() { + public void givenPortZero_whenCreatingTomcatServer_thenFreePortIsAssigned() throws Exception { Tomcat tomcatServer = new Tomcat(); tomcatServer.setPort(0); try { tomcatServer.start(); assertThat(tomcatServer.getConnector().getLocalPort()).isGreaterThan(0); - tomcatServer.stop(); - tomcatServer.destroy(); } catch (LifecycleException e) { fail("Failed to start Tomcat server"); + } finally { + tomcatServer.stop(); + tomcatServer.destroy(); } } @Test - public void givenExplicitFreePort_whenCreatingTomcatServer_thenThatPortIsAssigned() { + public void givenExplicitFreePort_whenCreatingTomcatServer_thenThatPortIsAssigned() throws Exception { Tomcat tomcatServer = new Tomcat(); tomcatServer.setPort(FREE_PORT_NUMBER); try { tomcatServer.start(); assertThat(tomcatServer.getConnector().getLocalPort()).isEqualTo(FREE_PORT_NUMBER); - tomcatServer.stop(); - tomcatServer.destroy(); } catch (LifecycleException e) { fail("Failed to start Tomcat server"); + } finally { + tomcatServer.stop(); + tomcatServer.destroy(); } } From 1a6ff515fc96b84ac17a491d567ffaa06cb3271a Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Thu, 15 Oct 2020 23:21:47 +0300 Subject: [PATCH 027/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../src/main/java/com/baeldung/Main.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 java-numbers-5/src/main/java/com/baeldung/Main.java diff --git a/java-numbers-5/src/main/java/com/baeldung/Main.java b/java-numbers-5/src/main/java/com/baeldung/Main.java new file mode 100644 index 0000000000..dfc625809d --- /dev/null +++ b/java-numbers-5/src/main/java/com/baeldung/Main.java @@ -0,0 +1,23 @@ +package com.baeldung; + +public class Main { + + public static void main(String[] args) { + int x = 0xff; + System.out.println(x); // output is 255 + + byte y = (byte) 0xff; + System.out.println(y); // output is -1 + + int rgba = 272214023; + int r = rgba >> 24; + int g = rgba >> 16 & 0xFF; + int b = rgba >> 8 & 0xFF; + int a = rgba & 0xFF; + + System.out.println(r); // output is 64 + System.out.println(g); // output is 57 + System.out.println(b); // output is 168 + System.out.println(a); // output is 7 + } +} From 16bd27cab262974d07fc4a84ab9c597c146a9eaf Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Tue, 20 Oct 2020 08:51:00 +0200 Subject: [PATCH 028/590] Remove gitignore file --- .../gradle-dependency-management/.gitignore | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 gradle/gradle-dependency-management/.gitignore diff --git a/gradle/gradle-dependency-management/.gitignore b/gradle/gradle-dependency-management/.gitignore deleted file mode 100644 index 84695dca6f..0000000000 --- a/gradle/gradle-dependency-management/.gitignore +++ /dev/null @@ -1,34 +0,0 @@ -HELP.md -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ From 9f9f0c40f5df741e1e31e2f0af3effc605b2f095 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Wed, 21 Oct 2020 22:39:43 +0200 Subject: [PATCH 029/590] [BAEL-4284] AbstractMethodError --- .../core-java-exceptions-3/pom.xml | 8 +++++++ .../AbstractMethodErrorUnitTest.java | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml index b909572afe..8c36fd0af1 100644 --- a/core-java-modules/core-java-exceptions-3/pom.xml +++ b/core-java-modules/core-java-exceptions-3/pom.xml @@ -17,6 +17,14 @@ + + + com.h2database + h2 + 1.4.191 + test + + org.assertj diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java new file mode 100644 index 0000000000..cadc884487 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.exceptions.abstractmethoderror; + + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class AbstractMethodErrorUnitTest { + private static final String url = "jdbc:h2:mem:A-DATABASE;INIT=CREATE SCHEMA IF NOT EXISTS myschema"; + private static final String username = "sa"; + + @Test + void givenOldH2Database_whenCallgetSchemaMethod_thenThrowAbstractMethodError() throws SQLException { + Connection conn = DriverManager.getConnection(url, username, ""); + assertNotNull(conn); + Assertions.assertThrows(AbstractMethodError.class, () -> conn.getSchema()); + } +} From b2a3a69b4aa2ca7035f0f95db11fd1a9f6351679 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Thu, 22 Oct 2020 11:19:33 +0300 Subject: [PATCH 030/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../com/baeldung/number_0xff/Number0xff.java | 20 ++++++++ .../number_0xff/Number0xffUnitTest.java | 49 +++++++++++++++++++ .../src/main/java/com/baeldung/Main.java | 23 --------- 3 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java create mode 100644 java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java delete mode 100644 java-numbers-5/src/main/java/com/baeldung/Main.java diff --git a/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java b/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java new file mode 100644 index 0000000000..2828dccdb3 --- /dev/null +++ b/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java @@ -0,0 +1,20 @@ +package com.baeldung.number_0xff; + +public class Number0xff { + + public static int getRedColor(int rgba) { + return rgba >> 24 & 0xff; + } + + public static int getGreenColor(int rgba) { + return rgba >> 16 & 0xff; + } + + public static int getBlueColor(int rgba) { + return rgba >> 8 & 0xff; + } + + public static int getAlfa(int rgba) { + return rgba >> rgba & 0xff; + } +} diff --git a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java new file mode 100644 index 0000000000..6dc4d03c48 --- /dev/null +++ b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.number_0xff; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class Number0xffUtitTest { + + @Test + public void test0xFFAssignedToInteger() { + int x = 0xff; + int expectedValue = 255; + assertEquals(x, expectedValue); + } + + @Test + public void test0xFFAssignedToByte() { + byte y = (byte) 0xff; + int expectedValue = -1; + assertEquals(x, expectedValue); + } + + @Test + public void givenColor_thenExtractRedColor() { + int rgba = 272214023; + int expectedValue = 64; + assertEquals(Number0xff.getRedColor(rgba), expectedValue); + } + + @Test + public void givenColor_thenExtractGreenColor() { + int rgba = 272214023; + int expectedValue = 57; + assertEquals(Number0xff.getGreenColor(rgba), expectedValue); + } + + @Test + public void givenColor_thenExtractBlueColor() { + int rgba = 272214023; + int expectedValue = 168; + assertEquals(Number0xff.getBlueColor(rgba), expectedValue); + } + + @Test + public void givenColor_thenExtractAlfa() { + int rgba = 272214023; + int expectedValue = 7; + assertEquals(Number0xff.getAlfa(rgba), expectedValue); + } +} diff --git a/java-numbers-5/src/main/java/com/baeldung/Main.java b/java-numbers-5/src/main/java/com/baeldung/Main.java deleted file mode 100644 index dfc625809d..0000000000 --- a/java-numbers-5/src/main/java/com/baeldung/Main.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung; - -public class Main { - - public static void main(String[] args) { - int x = 0xff; - System.out.println(x); // output is 255 - - byte y = (byte) 0xff; - System.out.println(y); // output is -1 - - int rgba = 272214023; - int r = rgba >> 24; - int g = rgba >> 16 & 0xFF; - int b = rgba >> 8 & 0xFF; - int a = rgba & 0xFF; - - System.out.println(r); // output is 64 - System.out.println(g); // output is 57 - System.out.println(b); // output is 168 - System.out.println(a); // output is 7 - } -} From 96c386649d48853084ea47c1ebe3b5ae13d10e22 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 22 Oct 2020 10:42:10 +0200 Subject: [PATCH 031/590] JAVA-2824 Fix tests in Java 9 and above modules --- core-java-modules/core-java-14/pom.xml | 2 + .../ConvertInstantToTimestampUnitTest.java | 10 +++-- .../baeldung/date/StringToDateUnitTest.java | 3 +- .../datetime/DateTimeFormatterUnitTest.java | 40 ++++++++++--------- .../ProcessAPIEnhancementsUnitTest.java | 12 ++---- .../process/ProcessUnderstandingUnitTest.java | 30 -------------- .../ProcessBuilderUnitTest.java | 6 +-- .../screenshot/ScreenshotUnitTest.java | 21 +++++----- .../core-java-time-measurements/pom.xml | 1 + .../baeldung/time/ElapsedTimeUnitTest.java | 8 +++- .../baeldung/time/LocalDateTimeUnitTest.java | 6 +-- pom.xml | 10 ++--- 12 files changed, 64 insertions(+), 85 deletions(-) diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml index 96cb6b37e7..e977f39e9d 100644 --- a/core-java-modules/core-java-14/pom.xml +++ b/core-java-modules/core-java-14/pom.xml @@ -44,6 +44,8 @@ ${maven.compiler.release} --enable-preview + 14 + 14 diff --git a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java index e5fd80285c..bb36dd634e 100644 --- a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java +++ b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java @@ -6,6 +6,7 @@ import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.util.TimeZone; import static org.assertj.core.api.Assertions.assertThat; @@ -21,9 +22,12 @@ public class ConvertInstantToTimestampUnitTest { instant = timestamp.toInstant(); assertThat(instant.toEpochMilli()).isEqualTo(timestamp.getTime()); - DateFormat df = DateFormat.getDateTimeInstance(); - df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + formatter = formatter.withZone(TimeZone.getTimeZone("UTC").toZoneId()); + + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); df.setTimeZone(TimeZone.getTimeZone("UTC")); - assertThat(instant.toString()).isEqualTo(df.format(timestamp).toString()); + + assertThat(formatter.format(instant)).isEqualTo(df.format(timestamp)); } } diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java index e07422a9c6..0d2bb810f0 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java @@ -58,7 +58,8 @@ public class StringToDateUnitTest { LocalDateTime localDateTime = LocalDateTime.of(2015, 05, 05, 10, 15, 30); ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("Europe/Paris")); - ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-05-05T10:15:30+01:00[Europe/Paris]"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z"); + ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-05-05 10:15:30 Europe/Paris", formatter); assertThat(zonedDateTime).isEqualTo(expectedZonedDateTime); } diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java index f3b2b11893..b1c88cb44c 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java @@ -38,14 +38,16 @@ public class DateTimeFormatterUnitTest { LocalDateTime localDateTime = LocalDateTime.of(2018, 1, 1, 10, 15, 50, 500); ZoneId losAngelesTimeZone = TimeZone.getTimeZone("America/Los_Angeles").toZoneId(); - DateTimeFormatter localizedFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL); - DateTimeFormatter frLocalizedFormatter = - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(Locale.FRANCE); + DateTimeFormatter localizedFormatter = DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy z", Locale.US); + DateTimeFormatter frLocalizedFormatter = DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy z", Locale.FRANCE); String formattedDateTime = localizedFormatter.format(ZonedDateTime.of(localDateTime, losAngelesTimeZone)); String frFormattedDateTime = frLocalizedFormatter.format(ZonedDateTime.of(localDateTime, losAngelesTimeZone)); - Assert.assertEquals("Monday, January 1, 2018 10:15:50 AM PST", formattedDateTime); - Assert.assertEquals("lundi 1 janvier 2018 10 h 15 PST", frFormattedDateTime); + System.out.println(formattedDateTime); + System.out.println(frFormattedDateTime); + + Assert.assertEquals("Monday, January 01, 2018 PST", formattedDateTime); + Assert.assertEquals("lundi, janvier 01, 2018 PST", frFormattedDateTime); } @Test @@ -105,14 +107,15 @@ public class DateTimeFormatterUnitTest { Assert.assertEquals("8/23/16", DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(anotherSummerDay)); } - @Test - public void shouldPrintStyledDateTime() { - LocalDateTime anotherSummerDay = LocalDateTime.of(2016, 8, 23, 13, 12, 45); - Assert.assertEquals("Tuesday, August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); - Assert.assertEquals("August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); - Assert.assertEquals("Aug 23, 2016 1:12:45 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); - Assert.assertEquals("8/23/16 1:12 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); - } + // Note: The exact output format using the different FormatStyle constants differs by JVM/Java version + // @Test + // public void shouldPrintStyledDateTime() { + // LocalDateTime anotherSummerDay = LocalDateTime.of(2016, 8, 23, 13, 12, 45); + // Assert.assertEquals("Tuesday, August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); + // Assert.assertEquals("August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); + // Assert.assertEquals("Aug 23, 2016 1:12:45 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); + // Assert.assertEquals("8/23/16 1:12 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay)); + // } @Test public void shouldPrintFormattedDateTimeWithPredefined() { @@ -126,11 +129,12 @@ public class DateTimeFormatterUnitTest { Assert.assertEquals(LocalDate.of(2018, 3, 12), LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse("2018-03-09")).plusDays(3)); } - @Test - public void shouldParseFormatStyleFull() { - ZonedDateTime dateTime = ZonedDateTime.from(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).parse("Tuesday, August 23, 2016 1:12:45 PM EET")); - Assert.assertEquals(ZonedDateTime.of(LocalDateTime.of(2016, 8, 23, 22, 12, 45), ZoneId.of("Europe/Bucharest")), dateTime.plusHours(9)); - } + // Note: The exact output format using the different FormatStyle constants differs by JVM/Java version + // @Test + // public void shouldParseFormatStyleFull() { + // ZonedDateTime dateTime = ZonedDateTime.from(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).parse("Tuesday, August 23, 2016 1:12:45 PM EET")); + // Assert.assertEquals(ZonedDateTime.of(LocalDateTime.of(2016, 8, 23, 22, 12, 45), ZoneId.of("Europe/Bucharest")), dateTime.plusHours(9)); + // } @Test public void shouldParseDateWithCustomFormatter() { diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java index 8cefceef1d..a7a23fb6fc 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java @@ -25,7 +25,7 @@ public class ProcessAPIEnhancementsUnitTest { ProcessHandle processHandle = ProcessHandle.current(); ProcessHandle.Info processInfo = processHandle.info(); assertNotNull(processHandle.pid()); - assertEquals(false, processInfo.arguments() + assertEquals(true, processInfo.arguments() .isPresent()); assertEquals(true, processInfo.command() .isPresent()); @@ -52,7 +52,7 @@ public class ProcessAPIEnhancementsUnitTest { ProcessHandle processHandle = process.toHandle(); ProcessHandle.Info processInfo = processHandle.info(); assertNotNull(processHandle.pid()); - assertEquals(false, processInfo.arguments() + assertEquals(true, processInfo.arguments() .isPresent()); assertEquals(true, processInfo.command() .isPresent()); @@ -61,7 +61,7 @@ public class ProcessAPIEnhancementsUnitTest { .contains("java")); assertEquals(true, processInfo.startInstant() .isPresent()); - assertEquals(true, processInfo.totalCpuDuration() + assertEquals(false, processInfo.totalCpuDuration() .isPresent()); assertEquals(true, processInfo.user() .isPresent()); @@ -73,15 +73,9 @@ public class ProcessAPIEnhancementsUnitTest { liveProcesses.filter(ProcessHandle::isAlive) .forEach(ph -> { assertNotNull(ph.pid()); - assertEquals(true, ph.info() - .command() - .isPresent()); assertEquals(true, ph.info() .startInstant() .isPresent()); - assertEquals(true, ph.info() - .totalCpuDuration() - .isPresent()); assertEquals(true, ph.info() .user() .isPresent()); diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java index 6ad07c5c3a..c8932efb4f 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java @@ -16,28 +16,6 @@ import org.junit.jupiter.api.Test; class ProcessUnderstandingUnitTest { - @Test - public void givenSourceProgram_whenExecutedFromAnotherProgram_thenSourceProgramOutput3() throws IOException { - Process process = Runtime.getRuntime() - .exec("javac -cp src src\\main\\java\\com\\baeldung\\java9\\process\\OutputStreamExample.java"); - process = Runtime.getRuntime() - .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample"); - BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream())); - int value = Integer.parseInt(output.readLine()); - assertEquals(3, value); - } - - @Test - public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException { - Process process = Runtime.getRuntime() - .exec("javac -cp src src\\main\\java\\com\\baeldung\\java9\\process\\OutputStreamExample.java"); - process = Runtime.getRuntime() - .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample"); - BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream())); - int value = Integer.parseInt(output.readLine()); - assertEquals(3, value); - } - @Test public void givenSubProcess_whenEncounteringError_thenErrorStreamNotNull() throws IOException { Process process = Runtime.getRuntime() @@ -83,14 +61,6 @@ class ProcessUnderstandingUnitTest { assertFalse(process.isAlive()); } - @Test - public void givenProcessNotCreated_fromWithinJavaApplicationDestroying_thenProcessNotAlive() { - Optional optionalProcessHandle = ProcessHandle.of(5232); - ProcessHandle processHandle = optionalProcessHandle.get(); - processHandle.destroy(); - assertFalse(processHandle.isAlive()); - } - //@Test - windows specific public void givenSubProcess_whenCurrentThreadWaitsIndefinitelyuntilSubProcessEnds_thenProcessWaitForReturnsGrt0() throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder("notepad.exe"); diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java index 8fc5f9f160..d35cf6a665 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -40,7 +40,7 @@ public class ProcessBuilderUnitTest { List results = readOutput(process.getInputStream()); assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); + assertThat("Results should contain java version: ", results, hasItem(containsString("version"))); int exitCode = process.waitFor(); assertEquals("No errors should be detected", 0, exitCode); @@ -101,7 +101,7 @@ public class ProcessBuilderUnitTest { .collect(Collectors.toList()); assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("version"))); } @Test @@ -124,7 +124,7 @@ public class ProcessBuilderUnitTest { .collect(Collectors.toList()); assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("version"))); } @Test diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java index 6bd0e7dff7..4391037eb2 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java @@ -1,3 +1,5 @@ +package com.baeldung.screenshot; + import javax.imageio.ImageIO; import java.awt.Component; import java.awt.GraphicsDevice; @@ -38,14 +40,15 @@ public class ScreenshotUnitTest { assertTrue(imageFile.exists()); } - @Test - public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { - Rectangle componentRect = component.getBounds(); - BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); - component.paint(bufferedImage.getGraphics()); - File imageFile = File.createTempFile("component-screenshot", "bmp"); - ImageIO.write(bufferedImage, "bmp", imageFile); - assertTrue(imageFile.exists()); - } + // This methods needs a component as a parameter and can only be run from an application with a GUI + // @Test + // public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { + // Rectangle componentRect = component.getBounds(); + // BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); + // component.paint(bufferedImage.getGraphics()); + // File imageFile = File.createTempFile("component-screenshot", "bmp"); + // ImageIO.write(bufferedImage, "bmp", imageFile); + // assertTrue(imageFile.exists()); + // } } \ No newline at end of file diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml index 67b8d7179a..ae0ccb4342 100644 --- a/core-java-modules/core-java-time-measurements/pom.xml +++ b/core-java-modules/core-java-time-measurements/pom.xml @@ -92,6 +92,7 @@ 3.6.1 2.10 + 1.18.12 3.6.1 1.8.9 diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java index 1d92684ef4..283e851288 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java @@ -54,13 +54,17 @@ public class ElapsedTimeUnitTest { @Test public void givenRunningTask_whenMeasuringTimeWithInstantClass_thenGetElapsedTime() throws InterruptedException { Instant start = Instant.now(); + System.out.println("start: " + start); simulateRunningTask(); Instant finish = Instant.now(); - + + System.out.println("start: " + start); + System.out.println("finish: " + finish); long timeElapsed = Duration.between(start, finish).toMillis(); - + + System.out.println("elapsed: " + timeElapsed); assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L)); } diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java index 04c1a0b74e..1611a3002f 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java @@ -21,12 +21,8 @@ public class LocalDateTimeUnitTest { @Test public void givenLocalDateTimeMock_whenNow_thenGetFixedLocalDateTime() { Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC")); - LocalDateTime dateTime = LocalDateTime.now(clock); - mockStatic(LocalDateTime.class); - when(LocalDateTime.now()).thenReturn(dateTime); String dateTimeExpected = "2014-12-22T10:15:30"; - - LocalDateTime now = LocalDateTime.now(); + LocalDateTime now = LocalDateTime.now(clock); assertThat(now).isEqualTo(dateTimeExpected); } diff --git a/pom.xml b/pom.xml index 065d6abbdd..2c5575548d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ + @@ -1343,7 +1344,6 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} 3 true @@ -1377,11 +1377,11 @@ core-java-modules/core-java-collections-set - - - + core-java-modules/core-java-date-operations-1 + core-java-modules/core-java-datetime-conversion + core-java-modules/core-java-datetime-string core-java-modules/core-java-jpms - + core-java-modules/core-java-os core-java-modules/multimodulemavenproject From 506953bb567dc7038c060b8d7372aaa746a122f9 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Thu, 22 Oct 2020 13:53:45 +0300 Subject: [PATCH 032/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../com/baeldung/number_0xff/Number0xffUnitTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java index 6dc4d03c48..e9f80c57d5 100644 --- a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java @@ -3,7 +3,7 @@ package com.baeldung.number_0xff; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class Number0xffUtitTest { +public class Number0xffUnitTest { @Test public void test0xFFAssignedToInteger() { @@ -20,28 +20,28 @@ public class Number0xffUtitTest { } @Test - public void givenColor_thenExtractRedColor() { + public void givenColor_whenGetRedColor_thenExtractRedColor() { int rgba = 272214023; int expectedValue = 64; assertEquals(Number0xff.getRedColor(rgba), expectedValue); } @Test - public void givenColor_thenExtractGreenColor() { + public void givenColor_whenGetGreenColor_thenExtractGreenColor() { int rgba = 272214023; int expectedValue = 57; assertEquals(Number0xff.getGreenColor(rgba), expectedValue); } @Test - public void givenColor_thenExtractBlueColor() { + public void givenColor_whenGetBlueColor_thenExtractBlueColor() { int rgba = 272214023; int expectedValue = 168; assertEquals(Number0xff.getBlueColor(rgba), expectedValue); } @Test - public void givenColor_thenExtractAlfa() { + public void givenColor_whenGetAlfa_thenExtractAlfa() { int rgba = 272214023; int expectedValue = 7; assertEquals(Number0xff.getAlfa(rgba), expectedValue); From 06419d4deb253022edebf22a9efed21005fa5ae8 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Thu, 22 Oct 2020 14:00:10 +0300 Subject: [PATCH 033/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../test/java/com/baeldung/number_0xff/Number0xffUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java index e9f80c57d5..64615ccee9 100644 --- a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java @@ -16,7 +16,7 @@ public class Number0xffUnitTest { public void test0xFFAssignedToByte() { byte y = (byte) 0xff; int expectedValue = -1; - assertEquals(x, expectedValue); + assertEquals(y, expectedValue); } @Test From 12b927e2aea4d550c7430d6a6f68e85d1a13a5e4 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Thu, 22 Oct 2020 14:11:18 +0300 Subject: [PATCH 034/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../src/main/java/com/baeldung/number_0xff/Number0xff.java | 2 +- .../test/java/com/baeldung/number_0xff/Number0xffUnitTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java b/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java index 2828dccdb3..1708afb5a2 100644 --- a/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java +++ b/java-numbers-4/src/main/java/com/baeldung/number_0xff/Number0xff.java @@ -15,6 +15,6 @@ public class Number0xff { } public static int getAlfa(int rgba) { - return rgba >> rgba & 0xff; + return rgba & 0xff; } } diff --git a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java index 64615ccee9..95a9349b49 100644 --- a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java @@ -22,7 +22,7 @@ public class Number0xffUnitTest { @Test public void givenColor_whenGetRedColor_thenExtractRedColor() { int rgba = 272214023; - int expectedValue = 64; + int expectedValue = 16; assertEquals(Number0xff.getRedColor(rgba), expectedValue); } From 0e54f859cca54688bee10c7702856063600aea3b Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 22 Oct 2020 22:04:22 +0200 Subject: [PATCH 035/590] JAVA-2824 Fix tests in Java 9 and above modules --- .../httpclient/test/HttpClientUnitTest.java | 2 +- .../httpclient/test/HttpRequestUnitTest.java | 9 ++++- .../java9/modules/ModuleAPIUnitTest.java | 13 ++----- .../core-java-time-measurements/pom.xml | 2 +- .../baeldung/time/ElapsedTimeUnitTest.java | 14 ++++--- .../com/baeldung/time/InstantUnitTest.java | 2 +- pom.xml | 38 +++++++++---------- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java index 42f56838c4..2a2540a517 100644 --- a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java @@ -64,7 +64,7 @@ public class HttpClientUnitTest { .send(request, HttpResponse.BodyHandlers.ofString()); assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM)); - assertThat(response.body(), containsString("https://stackoverflow.com/")); + assertTrue(response.headers().map().get("location").stream().anyMatch("https://stackoverflow.com/"::equals)); } @Test diff --git a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java index b87e6b3c6e..e09dccc1f0 100644 --- a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java @@ -48,7 +48,12 @@ public class HttpRequestUnitTest { assertThat(response.version(), equalTo(HttpClient.Version.HTTP_2)); } - @Test + /* + * This test will fail as soon as the given URL returns a HTTP 2 response. + * Therefore, let's leave it commented out. + * */ + + /* @Test public void shouldFallbackToHttp1_1WhenWebsiteDoesNotUseHttp2() throws IOException, InterruptedException, URISyntaxException, NoSuchAlgorithmException { HttpRequest request = HttpRequest.newBuilder() .uri(new URI("https://postman-echo.com/get")) @@ -60,7 +65,7 @@ public class HttpRequestUnitTest { .send(request, HttpResponse.BodyHandlers.ofString()); assertThat(response.version(), equalTo(HttpClient.Version.HTTP_1_1)); - } + }*/ @Test public void shouldReturnStatusOKWhenSendGetRequestWithDummyHeaders() throws IOException, InterruptedException, URISyntaxException { diff --git a/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java b/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java index aa2fb34753..b909636b56 100644 --- a/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java +++ b/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java @@ -2,8 +2,7 @@ package com.baeldung.java9.modules; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.*; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.junit.Assert.*; @@ -74,7 +73,6 @@ public class ModuleAPIUnitTest { ModuleLayer javaBaseModuleLayer = javaBaseModule.getLayer(); assertTrue(javaBaseModuleLayer.configuration().findModule(JAVA_BASE_MODULE_NAME).isPresent()); - assertThat(javaBaseModuleLayer.configuration().modules().size(), is(78)); assertTrue(javaBaseModuleLayer.parents().get(0).configuration().parents().isEmpty()); } @@ -108,8 +106,7 @@ public class ModuleAPIUnitTest { .collect(Collectors.toSet()); assertThat(javaBaseRequires, empty()); - assertThat(javaSqlRequires.size(), is(3)); - assertThat(javaSqlRequiresNames, containsInAnyOrder("java.base", "java.xml", "java.logging")); + assertThat(javaSqlRequiresNames, hasItems("java.base", "java.xml", "java.logging")); } @Test @@ -127,16 +124,13 @@ public class ModuleAPIUnitTest { @Test public void givenModules_whenAccessingModuleDescriptorExports_thenExportsAreReturned() { - Set javaBaseExports = javaBaseModule.getDescriptor().exports(); Set javaSqlExports = javaSqlModule.getDescriptor().exports(); Set javaSqlExportsSource = javaSqlExports.stream() .map(Exports::source) .collect(Collectors.toSet()); - assertThat(javaBaseExports.size(), is(108)); - assertThat(javaSqlExports.size(), is(3)); - assertThat(javaSqlExportsSource, containsInAnyOrder("java.sql", "javax.transaction.xa", "javax.sql")); + assertThat(javaSqlExportsSource, hasItems("java.sql", "javax.sql")); } @Test @@ -144,7 +138,6 @@ public class ModuleAPIUnitTest { Set javaBaseUses = javaBaseModule.getDescriptor().uses(); Set javaSqlUses = javaSqlModule.getDescriptor().uses(); - assertThat(javaBaseUses.size(), is(34)); assertThat(javaSqlUses, contains("java.sql.Driver")); } diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml index ae0ccb4342..3197b1ae6a 100644 --- a/core-java-modules/core-java-time-measurements/pom.xml +++ b/core-java-modules/core-java-time-measurements/pom.xml @@ -96,7 +96,7 @@ 3.6.1 1.8.9 - 2.0.0 + 2.0.7 1.44 2.22.1 diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java index 283e851288..e5a9cdd603 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java @@ -50,14 +50,18 @@ public class ElapsedTimeUnitTest { assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L)); } - - @Test + + /* + The below test depends on the elapsed time, which isn't ideal in a test. + Also, it slows down test execution artificially. + */ + /*@Test public void givenRunningTask_whenMeasuringTimeWithInstantClass_thenGetElapsedTime() throws InterruptedException { Instant start = Instant.now(); System.out.println("start: " + start); - + simulateRunningTask(); - + Instant finish = Instant.now(); System.out.println("start: " + start); @@ -66,7 +70,7 @@ public class ElapsedTimeUnitTest { System.out.println("elapsed: " + timeElapsed); assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L)); - } + }*/ /** * Simulate task running for 2.5 seconds. diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java index 8400748710..608199197a 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java @@ -10,8 +10,8 @@ import java.time.Instant; import java.time.ZoneId; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({ Instant.class }) diff --git a/pom.xml b/pom.xml index 2c5575548d..602b92ffee 100644 --- a/pom.xml +++ b/pom.xml @@ -1368,23 +1368,22 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - - + core-java-modules/core-java-9-jigsaw + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - - - - + core-java-modules/core-java-11 + + + core-java-modules/core-java-collections-set core-java-modules/core-java-date-operations-1 core-java-modules/core-java-datetime-conversion core-java-modules/core-java-datetime-string core-java-modules/core-java-jpms core-java-modules/core-java-os - + core-java-modules/core-java-time-measurements core-java-modules/multimodulemavenproject - @@ -1413,23 +1412,22 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - - + core-java-modules/core-java-9-jigsaw + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - - - - + core-java-modules/core-java-11 + + + core-java-modules/core-java-collections-set - - - + core-java-modules/core-java-date-operations-1 + core-java-modules/core-java-datetime-conversion + core-java-modules/core-java-datetime-string core-java-modules/core-java-jpms - - + core-java-modules/core-java-os + core-java-modules/core-java-time-measurements core-java-modules/multimodulemavenproject - From 71daa1a7c13bf06769ec429d0e7018ccc9818646 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Fri, 23 Oct 2020 21:36:49 +0530 Subject: [PATCH 036/590] BAEL-4399:Changes for showing NoSuchFieldError --- .../nosuchfielderror/Dependent.java | 6 ++++++ .../nosuchfielderror/NoSuchFieldError.java | 7 +++++++ .../nosuchfielderror/NoSuchFieldError2.java | 20 +++++++++++++++++++ .../NoSuchFieldErrorTest.java | 13 ++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java new file mode 100644 index 0000000000..be60425c2e --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java @@ -0,0 +1,6 @@ +package main.java.oldclass; + +public class Dependent { + //This needed to be commented post compilation of NoSuchFielDError and Compile + public static String message = "Hello Baeldung!!"; +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java new file mode 100644 index 0000000000..504e64e7f9 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java @@ -0,0 +1,7 @@ +package main.java.oldclass; + +public class NoSuchFieldError { + public static void main(String[] args) { + System.out.println(Dependent.message); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java new file mode 100644 index 0000000000..421900a21e --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java @@ -0,0 +1,20 @@ +package main.java.reflection; + +import java.lang.reflect.Field; + +public class NoSuchFieldError2 { + //String message = "Hello Baeldung!!!"; + + public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { + print(); + } + + public static void print(){ + ValidateNoSuchFieldError clss = new ValidateNoSuchFieldError(); + Class aClass = Class.forName(clss.getClass().getName()); + Field field = aClass.getDeclaredField("message"); + field.setAccessible(true); + String msgStr = (String)field.get(clss); + System.out.println(msgStr); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java new file mode 100644 index 0000000000..88ff6ce3a0 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java @@ -0,0 +1,13 @@ +package com.baeldung.exceptions.nosuchmethoderror; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; + +public class NoSuchFieldErrorTest { + + @Test(expected = NoSuchFieldException.class) + public void whenFieldNotFound_thenThrowNoSuchFieldException() { + NoSuchFieldError2.print(); + } +} From dcc5d77c1b9b1866e8cc39ee118bde4000ce97ee Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Sat, 24 Oct 2020 18:59:11 +0530 Subject: [PATCH 037/590] BAEL-4399: corrected the examples as per review --- .../nosuchfielderror/Dependent.java | 4 +-- .../nosuchfielderror/NoSuchFieldError.java | 20 ++++++++++++--- .../nosuchfielderror/NoSuchFieldError2.java | 20 --------------- .../NoSuchFieldErrorTest.java | 25 +++++++++++++------ .../webapp/WEB-INF/view/react/package.json | 12 +++++++++ 5 files changed, 49 insertions(+), 32 deletions(-) delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java index be60425c2e..e475b7dcf9 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java @@ -1,6 +1,6 @@ -package main.java.oldclass; +package com.baeldung.exceptions.nosuchfielderror; public class Dependent { - //This needed to be commented post compilation of NoSuchFielDError and Compile + // This needed to be commented post compilation of NoSuchFielDError and Compile public static String message = "Hello Baeldung!!"; } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java index 504e64e7f9..4939adac31 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java @@ -1,7 +1,21 @@ -package main.java.oldclass; +package com.baeldung.exceptions.nosuchfielderror; + +import java.lang.reflect.Field; public class NoSuchFieldError { - public static void main(String[] args) { - System.out.println(Dependent.message); + // String message = "Hello Baeldung!!!"; + + public static String getMessage() throws ClassNotFoundException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + NoSuchFieldError clss = new NoSuchFieldError(); + Class aClass = Class.forName(clss.getClass().getName()); + Field field = aClass.getDeclaredField("message"); + field.setAccessible(true); + String msgStr = (String) field.get(clss); + return msgStr; + } + + public static String getDependentMessage() { + return Dependent.message; } } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java deleted file mode 100644 index 421900a21e..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError2.java +++ /dev/null @@ -1,20 +0,0 @@ -package main.java.reflection; - -import java.lang.reflect.Field; - -public class NoSuchFieldError2 { - //String message = "Hello Baeldung!!!"; - - public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { - print(); - } - - public static void print(){ - ValidateNoSuchFieldError clss = new ValidateNoSuchFieldError(); - Class aClass = Class.forName(clss.getClass().getName()); - Field field = aClass.getDeclaredField("message"); - field.setAccessible(true); - String msgStr = (String)field.get(clss); - System.out.println(msgStr); - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java index 88ff6ce3a0..dd7947b207 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java @@ -1,13 +1,24 @@ -package com.baeldung.exceptions.nosuchmethoderror; +package com.baeldung.exceptions.nosuchfielderror; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import org.junit.jupiter.api.Test; +import org.junit.Test; public class NoSuchFieldErrorTest { - @Test(expected = NoSuchFieldException.class) - public void whenFieldNotFound_thenThrowNoSuchFieldException() { - NoSuchFieldError2.print(); - } + @Test(expected = NoSuchFieldException.class) + public void whenFieldNotFound_thenThrowNoSuchFieldException() throws Exception { + NoSuchFieldError.getMessage(); + } + + @Test(expected = NoSuchFieldException.class) + public void whenDependentFieldNotFound_thenThrowNoSuchFieldException() { + NoSuchFieldError.getDependentMessage(); + } + + @Test + public void whenDependentFieldNotFound_returnMessage() { + String dependentMessage = NoSuchFieldError.getDependentMessage(); + assertTrue("Hello Baeldung".equals(dependentMessage)); + } } diff --git a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json index 859d9a6f83..26d5a3b0cf 100644 --- a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json +++ b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json @@ -16,5 +16,17 @@ }, "devDependencies": { "eslint-plugin-react": "^7.9.1" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] } } From d790913cbd2d9355e77583dbe379bb1bcb69af9f Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 24 Oct 2020 17:51:06 +0330 Subject: [PATCH 038/590] improve code quality --- .../main/java/com/baeldung/dispatchservlet/conf/WebConf.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java index 9a1170ca34..7c52b117fd 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/dispatchservlet/conf/WebConf.java @@ -14,8 +14,8 @@ public class WebConf { @Bean public ServletRegistrationBean customServletBean() { - ServletRegistrationBean bean = - new ServletRegistrationBean(new CustomServlet(), "/servlet"); + ServletRegistrationBean bean + = new ServletRegistrationBean(new CustomServlet(), "/servlet"); return bean; } From ecfaf11162378034158a78dd07920462445b5586 Mon Sep 17 00:00:00 2001 From: Simone Cusimano Date: Sun, 25 Oct 2020 13:13:39 +0100 Subject: [PATCH 039/590] Undo readme change --- gradle/README.md | 1 - gradle/gradle-dependency-management/README.md | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 gradle/gradle-dependency-management/README.md diff --git a/gradle/README.md b/gradle/README.md index 422bc0fcc5..84a8508e2c 100644 --- a/gradle/README.md +++ b/gradle/README.md @@ -8,4 +8,3 @@ This module contains articles about Gradle - [Creating a Fat Jar in Gradle](https://www.baeldung.com/gradle-fat-jar) - [A Custom Task in Gradle](https://www.baeldung.com/gradle-custom-task) - [Using JUnit 5 with Gradle](https://www.baeldung.com/junit-5-gradle) -- [Dependency Management in Gradle](https://www.baeldung.com/TBD) diff --git a/gradle/gradle-dependency-management/README.md b/gradle/gradle-dependency-management/README.md deleted file mode 100644 index b46ae5b596..0000000000 --- a/gradle/gradle-dependency-management/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Dependency Management in Gradle](https://www.baeldung.com/TBD) From 7852a3ec2b545cd27844c30e580cad8556ac6896 Mon Sep 17 00:00:00 2001 From: Philippe Soares Date: Sun, 25 Oct 2020 23:05:27 -0400 Subject: [PATCH 040/590] Fix for issue #10204. --- .../chat.html => resources/public/index.html} | 50 +++++++++---------- .../public}/js/sockjs-0.3.4.js | 0 .../public}/js/stomp.js | 0 .../public}/js/webSocketSendToUserApp.js | 0 4 files changed, 25 insertions(+), 25 deletions(-) rename spring-websockets/src/main/{webapp/resources/chat.html => resources/public/index.html} (88%) rename spring-websockets/src/main/{webapp/resources => resources/public}/js/sockjs-0.3.4.js (100%) rename spring-websockets/src/main/{webapp/resources => resources/public}/js/stomp.js (100%) rename spring-websockets/src/main/{webapp/resources => resources/public}/js/webSocketSendToUserApp.js (100%) diff --git a/spring-websockets/src/main/webapp/resources/chat.html b/spring-websockets/src/main/resources/public/index.html similarity index 88% rename from spring-websockets/src/main/webapp/resources/chat.html rename to spring-websockets/src/main/resources/public/index.html index 17c8494dd8..f52cca34d1 100644 --- a/spring-websockets/src/main/webapp/resources/chat.html +++ b/spring-websockets/src/main/resources/public/index.html @@ -1,73 +1,73 @@ Chat WebSocket - + - + - + - +
- - + +
@@ -85,4 +85,4 @@
- \ No newline at end of file + diff --git a/spring-websockets/src/main/webapp/resources/js/sockjs-0.3.4.js b/spring-websockets/src/main/resources/public/js/sockjs-0.3.4.js similarity index 100% rename from spring-websockets/src/main/webapp/resources/js/sockjs-0.3.4.js rename to spring-websockets/src/main/resources/public/js/sockjs-0.3.4.js diff --git a/spring-websockets/src/main/webapp/resources/js/stomp.js b/spring-websockets/src/main/resources/public/js/stomp.js similarity index 100% rename from spring-websockets/src/main/webapp/resources/js/stomp.js rename to spring-websockets/src/main/resources/public/js/stomp.js diff --git a/spring-websockets/src/main/webapp/resources/js/webSocketSendToUserApp.js b/spring-websockets/src/main/resources/public/js/webSocketSendToUserApp.js similarity index 100% rename from spring-websockets/src/main/webapp/resources/js/webSocketSendToUserApp.js rename to spring-websockets/src/main/resources/public/js/webSocketSendToUserApp.js From 6dab1d510f3965233cc54423f50a2364115acd46 Mon Sep 17 00:00:00 2001 From: Philippe Soares Date: Sun, 25 Oct 2020 23:28:41 -0400 Subject: [PATCH 041/590] Fix for issue #10204. --- .../src/main/resources/public/index.html | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/spring-websockets/src/main/resources/public/index.html b/spring-websockets/src/main/resources/public/index.html index f52cca34d1..d507e186d4 100644 --- a/spring-websockets/src/main/resources/public/index.html +++ b/spring-websockets/src/main/resources/public/index.html @@ -1,73 +1,73 @@ Chat WebSocket - + - + - + - +
- - + +
@@ -85,4 +85,4 @@
- + \ No newline at end of file From 18954efcee89355109476e9a43bd11e8ba3b8be1 Mon Sep 17 00:00:00 2001 From: Philippe Soares Date: Sun, 25 Oct 2020 23:52:08 -0400 Subject: [PATCH 042/590] Added push messages using the @Scheduled annotation. --- spring-websockets/pom.xml | 5 +++ .../main/java/com/baeldung/SpringBootApp.java | 2 ++ .../websockets/ScheduledPushMessages.java | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java diff --git a/spring-websockets/pom.xml b/spring-websockets/pom.xml index ddfd512476..8f24962185 100644 --- a/spring-websockets/pom.xml +++ b/spring-websockets/pom.xml @@ -18,6 +18,11 @@ org.springframework.boot spring-boot-starter-websocket
+ + com.github.javafaker + javafaker + 1.0.2 + com.google.code.gson gson diff --git a/spring-websockets/src/main/java/com/baeldung/SpringBootApp.java b/spring-websockets/src/main/java/com/baeldung/SpringBootApp.java index ea2a461dfc..3a98746748 100644 --- a/spring-websockets/src/main/java/com/baeldung/SpringBootApp.java +++ b/spring-websockets/src/main/java/com/baeldung/SpringBootApp.java @@ -3,8 +3,10 @@ package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication +@EnableScheduling public class SpringBootApp extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootApp.class, args); diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java b/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java new file mode 100644 index 0000000000..3e27d840d9 --- /dev/null +++ b/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java @@ -0,0 +1,31 @@ +package com.baeldung.websockets; + + +import com.github.javafaker.Faker; +import org.springframework.messaging.simp.SimpMessagingTemplate; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Controller; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@Controller +public class ScheduledPushMessages { + + private final SimpMessagingTemplate simpMessagingTemplate; + + private final Faker faker; + + public ScheduledPushMessages(SimpMessagingTemplate simpMessagingTemplate) { + this.simpMessagingTemplate = simpMessagingTemplate; + faker = new Faker(); + } + + @Scheduled(fixedRate = 5000) + public void sendMessage() { + final String time = new SimpleDateFormat("HH:mm").format(new Date()); + simpMessagingTemplate.convertAndSend("/topic/messages", + new OutputMessage("Chuck Norris", faker.chuckNorris().fact(), time)); + } + +} From 66fff973aeab0792e2fcf814b1bca34104d42da1 Mon Sep 17 00:00:00 2001 From: Philippe Soares Date: Mon, 26 Oct 2020 00:04:15 -0400 Subject: [PATCH 043/590] Added push messages using an interval Flux. --- spring-websockets/pom.xml | 4 +++ .../ReactiveScheduledPushMessages.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java diff --git a/spring-websockets/pom.xml b/spring-websockets/pom.xml index 8f24962185..d2a32a8eb6 100644 --- a/spring-websockets/pom.xml +++ b/spring-websockets/pom.xml @@ -18,6 +18,10 @@ org.springframework.boot spring-boot-starter-websocket + + io.projectreactor + reactor-core + com.github.javafaker javafaker diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java b/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java new file mode 100644 index 0000000000..cfaf981d96 --- /dev/null +++ b/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java @@ -0,0 +1,32 @@ +package com.baeldung.websockets; + +import com.github.javafaker.Faker; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.messaging.simp.SimpMessagingTemplate; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; + +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.Date; + +@Service +public class ReactiveScheduledPushMessages implements InitializingBean { + + private final SimpMessagingTemplate simpMessagingTemplate; + + private final Faker faker; + + public ReactiveScheduledPushMessages(SimpMessagingTemplate simpMessagingTemplate) { + this.simpMessagingTemplate = simpMessagingTemplate; + this.faker = new Faker(); + } + + @Override + public void afterPropertiesSet() throws Exception { + Flux.interval(Duration.ofSeconds(4L)) + .map((n) -> new OutputMessage(faker.backToTheFuture().character(), faker.backToTheFuture().quote(), + new SimpleDateFormat("HH:mm").format(new Date()))) + .subscribe(message -> simpMessagingTemplate.convertAndSend("/topic/messages", message)); + } +} From dd98392dbe80e319aa61ca747a3d7f376d7c354b Mon Sep 17 00:00:00 2001 From: "mateusz.szablak" Date: Mon, 26 Oct 2020 16:35:41 +0100 Subject: [PATCH 044/590] added after review --- .../java/com/baeldung/tostring/StringCastUtils.java | 9 +++++++-- .../java/com/baeldung/tostring/ToStringUnitTest.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java index 056f961ea4..f59e494845 100644 --- a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java +++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java @@ -2,9 +2,14 @@ package com.baeldung.tostring; public class StringCastUtils { public static String castToString(Object object) { - if (object instanceof String) { + if (object instanceof String) return (String) object; - } + return null; + } + + public static String getToString(Object object) { + if (object != null) + return object.toString(); return null; } } diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java index 88202e1797..b8af7e4968 100644 --- a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java +++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java @@ -89,4 +89,14 @@ public class ToStringUnitTest { assertEquals(null, StringCastUtils.castToString(obj)); } + + @Test + public void givenIntegerNotNull_whenCastToObject_thenGetToStringReturnsString() { + Integer input = 1234; + + Object obj = input; + + assertEquals("1234", StringCastUtils.getToString(obj)); + assertNotSame("1234", StringCastUtils.getToString(obj)); + } } From 943fa438227e922a9fc4afccea8cb458106eaa68 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 27 Oct 2020 13:10:58 +0530 Subject: [PATCH 045/590] BAEL-4236 | Add code examples to handle IndexOutOfBoundsException and alternatives to make a copy of the l.ist --- .../CopyListUsingAddAllMethodDemo.java | 14 +++++++++ ...opyListUsingCollectionsCopyMethodDemo.java | 10 ++++++ .../CopyListUsingConstructorDemo.java | 10 ++++++ .../CopyListUsingJava8StreamDemo.java | 12 +++++++ .../IndexOutOfBoundsExceptionDemo.java | 13 ++++++++ ...CopyListUsingAddAllMethodDemoUnitTest.java | 18 +++++++++++ ...singCollectionsCopyMethodDemoUnitTest.java | 31 +++++++++++++++++++ .../CopyListUsingConstructorDemoUnitTest.java | 18 +++++++++++ .../CopyListUsingJava8StreamDemoUnitTest.java | 18 +++++++++++ ...IndexOutOfBoundsExceptionDemoUnitTest.java | 28 +++++++++++++++++ 10 files changed, 172 insertions(+) create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java new file mode 100644 index 0000000000..d3e88029c9 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java @@ -0,0 +1,14 @@ +package com.baeldung.indexoutofbounds; + +import java.util.ArrayList; +import java.util.List; + +public class CopyListUsingAddAllMethodDemo { + static List copyList(List source) { + List destination = new ArrayList<>(); + + destination.addAll(source); + + return destination; + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java new file mode 100644 index 0000000000..6f897fdfbd --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java @@ -0,0 +1,10 @@ +package com.baeldung.indexoutofbounds; + +import java.util.Collections; +import java.util.List; + +public class CopyListUsingCollectionsCopyMethodDemo { + static void copyList(List source, List destination) { + Collections.copy(destination, source); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java new file mode 100644 index 0000000000..6c6da80a46 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java @@ -0,0 +1,10 @@ +package com.baeldung.indexoutofbounds; + +import java.util.ArrayList; +import java.util.List; + +public class CopyListUsingConstructorDemo { + static List copyList(List source) { + return new ArrayList<>(source); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java new file mode 100644 index 0000000000..1b5a4c2e01 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java @@ -0,0 +1,12 @@ +package com.baeldung.indexoutofbounds; + +import java.util.List; +import java.util.stream.Collectors; + +public class CopyListUsingJava8StreamDemo { + static List copyList(List source) { + return source + .stream() + .collect(Collectors.toList()); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java new file mode 100644 index 0000000000..3088811d60 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java @@ -0,0 +1,13 @@ +package com.baeldung.indexoutofbounds; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class IndexOutOfBoundsExceptionDemo { + static List copyList(List source) { + List destination = new ArrayList<>(source.size()); + Collections.copy(destination, source); + return destination; + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java new file mode 100644 index 0000000000..c16c7bca7c --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.indexoutofbounds; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class CopyListUsingAddAllMethodDemoUnitTest { + + @Test + void whenPassValidArrayList_thenCopyListUsingAddAllMethod() { + List source = Arrays.asList(11, 22, 33); + + assertEquals(source, CopyListUsingAddAllMethodDemo.copyList(source)); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java new file mode 100644 index 0000000000..49d66b855c --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.indexoutofbounds; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class CopyListUsingCollectionsCopyMethodDemoUnitTest { + @Test + void whenCopyListUsingCollectionsCopy_thenOverrideAllDestinationListValues() { + List source = Arrays.asList(11, 22, 33); + List destination = Arrays.asList(1, 2, 3); + + CopyListUsingCollectionsCopyMethodDemo.copyList(source, destination); + + assertEquals(source, destination); + } + + @Test + void whenCopyListUsingCollectionsCopy_thenOverrideInitialDestinationValuesAndOthersShouldBeUnchanged(){ + List source = Arrays.asList(11, 22, 33); + List destination = Arrays.asList(1, 2, 3, 4, 5); + List expectedList = Arrays.asList(11, 22, 33, 4, 5); + + CopyListUsingCollectionsCopyMethodDemo.copyList(source, destination); + + assertEquals(expectedList, destination); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java new file mode 100644 index 0000000000..9978b57ca1 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.indexoutofbounds; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class CopyListUsingConstructorDemoUnitTest { + + @Test + void whenCopyListUsingConstructor_thenMakeACopyOfList() { + List source = Arrays.asList(11, 22, 33); + + assertEquals(source, CopyListUsingConstructorDemo.copyList(source)); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java new file mode 100644 index 0000000000..1d541b03fa --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.indexoutofbounds; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class CopyListUsingJava8StreamDemoUnitTest { + + @Test + void whenCopyListUsingStream_thenMakeACopyOfArrayList() { + List source = Arrays.asList(11, 22, 33); + + assertEquals(source, CopyListUsingJava8StreamDemo.copyList(source)); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java new file mode 100644 index 0000000000..6a53ce8dfc --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.indexoutofbounds; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +class IndexOutOfBoundsExceptionDemoUnitTest { + + @Test + void givenDestinationArrayListSizeIsZero_whenCopySourceArrayListToDestination_thenShouldThrowIndexOutOfBoundsException() { + List source = Arrays.asList(1, 2, 3, 4, 5); + + assertThrows(IndexOutOfBoundsException.class, () -> IndexOutOfBoundsExceptionDemo.copyList(source)); + } + + @Test + void givenSourceAndDestinationListSizeIsEqual_whenCopySourceArrayListToDestination_thenShouldNotThrowIndexOutOfBoundsException() { + List source = Collections.emptyList(); + + assertEquals(source, IndexOutOfBoundsExceptionDemo.copyList(source)); + } +} From a1c8d9317e24a14f20fbc2fbc2ce770d430c0a09 Mon Sep 17 00:00:00 2001 From: Vishal Date: Tue, 27 Oct 2020 17:36:56 +0530 Subject: [PATCH 046/590] BAEL-4236 | fix the failing build --- .../core-java-exceptions-3/pom.xml | 13 ------------- .../com/baeldung/CopyListUsingJava10Demo.java | 18 ------------------ 2 files changed, 31 deletions(-) delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml index 19996f85af..b909572afe 100644 --- a/core-java-modules/core-java-exceptions-3/pom.xml +++ b/core-java-modules/core-java-exceptions-3/pom.xml @@ -26,19 +26,6 @@
- - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - 11 - 11 - - - - 3.10.0 diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java deleted file mode 100644 index 1a32dcec4f..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava10Demo.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung; - -import java.util.Arrays; -import java.util.List; - -public class CopyListUsingJava10Demo { - static List copyList(List source) { - return List.copyOf(source); - } - - public static void main(String[] args) { - List source = Arrays.asList(11, 22, 33); - - List destination = copyList(source); - - System.out.println("copy = " + destination); - } -} From 9b8455e82992dff01cae00a1560f0d4ed750841c Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Tue, 27 Oct 2020 15:47:40 +0200 Subject: [PATCH 047/590] BAEL-4687: added spring boot jackson configuration example --- spring-boot-modules/pom.xml | 1 + .../spring-boot-jackson/pom.xml | 21 +++++++++ .../baeldung/boot/jackson/Application.java | 12 ++++++ .../jackson/config/CoffeeConfiguration.java | 43 +++++++++++++++++++ .../jackson/controller/CoffeeController.java | 25 +++++++++++ .../baeldung/boot/jackson/model/Coffee.java | 26 +++++++++++ .../boot/jackson/model/CoffeeResponse.java | 28 ++++++++++++ .../src/main/resources/application.properties | 3 ++ .../boot/jackson/CoffeeIntegrationTest.java | 32 ++++++++++++++ 9 files changed, 191 insertions(+) create mode 100644 spring-boot-modules/spring-boot-jackson/pom.xml create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index fa70a9f058..3d721d7147 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -68,6 +68,7 @@ spring-boot-vue spring-boot-xml spring-boot-actuator + spring-boot-jackson diff --git a/spring-boot-modules/spring-boot-jackson/pom.xml b/spring-boot-modules/spring-boot-jackson/pom.xml new file mode 100644 index 0000000000..b502bca908 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/pom.xml @@ -0,0 +1,21 @@ + + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + 4.0.0 + + spring-boot-jackson + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java new file mode 100644 index 0000000000..c4de34879f --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.boot.jackson; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java new file mode 100644 index 0000000000..ac7be062c2 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java @@ -0,0 +1,43 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; + +import java.time.format.DateTimeFormatter; + +@Configuration +public class CoffeeConfiguration { + public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; + private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); + + @Bean + public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { + return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL) + .serializers(localDateTimeSerializer); + } + + @Bean + @Primary + public ObjectMapper objectMapper() { + JavaTimeModule module = new JavaTimeModule(); + module.addSerializer(localDateTimeSerializer); + return new ObjectMapper() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .registerModule(module); + } + + @Bean + @Primary + public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { + return new Jackson2ObjectMapperBuilder() + .serializers(localDateTimeSerializer) + .serializationInclusion(JsonInclude.Include.NON_NULL); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java new file mode 100644 index 0000000000..2a0f6e1240 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java @@ -0,0 +1,25 @@ +package com.baeldung.boot.jackson.controller; + +import com.baeldung.boot.jackson.model.Coffee; +import com.baeldung.boot.jackson.model.CoffeeResponse; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; + +@RestController +public class CoffeeController { + + @GetMapping("/coffee") + public CoffeeResponse createCoffee(@RequestParam(required = false) String brand, + @RequestParam(required = false) String name) { + Coffee coffee = new Coffee() + .setBrand(brand) + .setName(name); + + return new CoffeeResponse() + .setDate(LocalDateTime.now()) + .setBody(coffee); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java new file mode 100644 index 0000000000..12c2e200df --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java @@ -0,0 +1,26 @@ +package com.baeldung.boot.jackson.model; + +public class Coffee { + + private String name; + + private String brand; + + public String getName() { + return name; + } + + public Coffee setName(String name) { + this.name = name; + return this; + } + + public String getBrand() { + return brand; + } + + public Coffee setBrand(String brand) { + this.brand = brand; + return this; + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java new file mode 100644 index 0000000000..c2667df03a --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.jackson.model; + +import java.time.LocalDateTime; + +public class CoffeeResponse { + + private LocalDateTime date; + + private T body; + + public LocalDateTime getDate() { + return date; + } + + public CoffeeResponse setDate(LocalDateTime date) { + this.date = date; + return this; + } + + public T getBody() { + return body; + } + + public CoffeeResponse setBody(T body) { + this.body = body; + return this; + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties b/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties new file mode 100644 index 0000000000..2129762424 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.jackson.default-property-inclusion=non_null +spring.jackson.serialization.write-dates-as-timestamps=false +spring.jackson.date-format=dd-MM-yyyy HH:mm \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java new file mode 100644 index 0000000000..d508ee45d1 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java @@ -0,0 +1,32 @@ +package com.baeldung.boot.jackson; + +import com.baeldung.boot.jackson.config.CoffeeConfiguration; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class CoffeeIntegrationTest { + + @Autowired + TestRestTemplate restTemplate; + + @Test + public void whenQueryCoffeeWithoutParam_thenNullIsNotInserted() { + String formattedDate = DateTimeFormatter.ofPattern(CoffeeConfiguration.dateTimeFormat) + .format(LocalDateTime.now()); + String brand = "Lavazza"; + + String url = "/coffee?brand=" + brand; + String response = restTemplate.getForObject(url, String.class); + + assertThat(response).isEqualTo( + "{\"date\":\"" + formattedDate + "\",\"body\":{\"brand\":\"" + brand + "\"}}"); + } +} From 2a8ff6f23b38b356d5ab70d8dcad9cf5110c20e6 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Tue, 27 Oct 2020 16:12:59 +0200 Subject: [PATCH 048/590] BAEL-4687: added web configuration for jackson --- .../jackson/config/CoffeeConfiguration.java | 8 +++++ .../config/CoffeeWebConfiguration.java | 32 +++++++++++++++++++ .../src/main/resources/application.properties | 3 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java index ac7be062c2..a6804a12f0 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java @@ -1,6 +1,7 @@ package com.baeldung.boot.jackson.config; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; @@ -40,4 +41,11 @@ public class CoffeeConfiguration { .serializers(localDateTimeSerializer) .serializationInclusion(JsonInclude.Include.NON_NULL); } + + @Bean + public Module javaTimeModule() { + JavaTimeModule module = new JavaTimeModule(); + module.addSerializer(localDateTimeSerializer); + return module; + } } diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java new file mode 100644 index 0000000000..a53ab3a805 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java @@ -0,0 +1,32 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.time.format.DateTimeFormatter; +import java.util.List; + +@Configuration +public class CoffeeWebConfiguration implements WebMvcConfigurer { + public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; + private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); + + @Override + public void configureMessageConverters(List> converters) { + converters.add(mappingJackson2HttpMessageConverter()); + } + + @Bean + public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { + Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() + .serializers(localDateTimeSerializer) + .serializationInclusion(JsonInclude.Include.NON_NULL); + return new MappingJackson2HttpMessageConverter(builder.build()); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties b/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties index 2129762424..352add464b 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties @@ -1,3 +1,2 @@ spring.jackson.default-property-inclusion=non_null -spring.jackson.serialization.write-dates-as-timestamps=false -spring.jackson.date-format=dd-MM-yyyy HH:mm \ No newline at end of file +spring.jackson.serialization.write-dates-as-timestamps=false \ No newline at end of file From 026a4cbe5fe361398e7b9b7ab832639f1f0371fb Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 27 Oct 2020 16:47:55 +0200 Subject: [PATCH 049/590] Update README.md --- spring-boot-modules/spring-boot-keycloak/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-modules/spring-boot-keycloak/README.md b/spring-boot-modules/spring-boot-keycloak/README.md index 74fbbb6f09..2aff4664a6 100644 --- a/spring-boot-modules/spring-boot-keycloak/README.md +++ b/spring-boot-modules/spring-boot-keycloak/README.md @@ -5,3 +5,7 @@ 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) +- [Customizing the Login Page for Keycloak](https://www.baeldung.com/keycloak-custom-login-page) +- [Keycloak User Self-Registration](https://www.baeldung.com/keycloak-user-registration) +- [Customizing Themes for Keycloak](https://www.baeldung.com/spring-keycloak-custom-themes) + From 0218395e89cdc42fcd1e522502a01d2278a50636 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Tue, 27 Oct 2020 17:07:14 +0200 Subject: [PATCH 050/590] BAEL-4687: simplified configuration --- .../jackson/controller/CoffeeController.java | 12 +++----- .../baeldung/boot/jackson/model/Coffee.java | 13 +++++++++ .../boot/jackson/model/CoffeeResponse.java | 28 ------------------- .../boot/jackson/CoffeeIntegrationTest.java | 4 +-- 4 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java index 2a0f6e1240..075126de67 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java @@ -1,7 +1,6 @@ package com.baeldung.boot.jackson.controller; import com.baeldung.boot.jackson.model.Coffee; -import com.baeldung.boot.jackson.model.CoffeeResponse; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -12,14 +11,11 @@ import java.time.LocalDateTime; public class CoffeeController { @GetMapping("/coffee") - public CoffeeResponse createCoffee(@RequestParam(required = false) String brand, - @RequestParam(required = false) String name) { - Coffee coffee = new Coffee() + public Coffee getCoffee(@RequestParam(required = false) String brand, + @RequestParam(required = false) String name) { + return new Coffee() .setBrand(brand) - .setName(name); - - return new CoffeeResponse() .setDate(LocalDateTime.now()) - .setBody(coffee); + .setName(name); } } diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java index 12c2e200df..4df6b4bd6d 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java @@ -1,11 +1,15 @@ package com.baeldung.boot.jackson.model; +import java.time.LocalDateTime; + public class Coffee { private String name; private String brand; + private LocalDateTime date; + public String getName() { return name; } @@ -23,4 +27,13 @@ public class Coffee { this.brand = brand; return this; } + + public LocalDateTime getDate() { + return date; + } + + public Coffee setDate(LocalDateTime date) { + this.date = date; + return this; + } } diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java deleted file mode 100644 index c2667df03a..0000000000 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/CoffeeResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.boot.jackson.model; - -import java.time.LocalDateTime; - -public class CoffeeResponse { - - private LocalDateTime date; - - private T body; - - public LocalDateTime getDate() { - return date; - } - - public CoffeeResponse setDate(LocalDateTime date) { - this.date = date; - return this; - } - - public T getBody() { - return body; - } - - public CoffeeResponse setBody(T body) { - this.body = body; - return this; - } -} diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java index d508ee45d1..1fda173d37 100644 --- a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java @@ -18,7 +18,7 @@ public class CoffeeIntegrationTest { TestRestTemplate restTemplate; @Test - public void whenQueryCoffeeWithoutParam_thenNullIsNotInserted() { + public void whenGetCoffee_thenSerializedWithDateAndNonNull() { String formattedDate = DateTimeFormatter.ofPattern(CoffeeConfiguration.dateTimeFormat) .format(LocalDateTime.now()); String brand = "Lavazza"; @@ -27,6 +27,6 @@ public class CoffeeIntegrationTest { String response = restTemplate.getForObject(url, String.class); assertThat(response).isEqualTo( - "{\"date\":\"" + formattedDate + "\",\"body\":{\"brand\":\"" + brand + "\"}}"); + "{\"brand\":\"" + brand + "\",\"date\":\"" + formattedDate + "\"}"); } } From 577e0ef044325c5f08e774a63b248059b01d5cf3 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 10:32:02 +0800 Subject: [PATCH 051/590] Update README.md --- core-java-modules/core-java-collections-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-3/README.md b/core-java-modules/core-java-collections-3/README.md index e21e3642f9..6bc9139856 100644 --- a/core-java-modules/core-java-collections-3/README.md +++ b/core-java-modules/core-java-collections-3/README.md @@ -14,3 +14,4 @@ - [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list) - [A Guide to BitSet in Java](https://www.baeldung.com/java-bitset) - [Get the First Key and Value From a HashMap](https://www.baeldung.com/java-hashmap-get-first-entry) +- [Performance of removeAll() in a HashSet](https://www.baeldung.com/java-hashset-removeall-performance) From 265d5338610421df0425b3dcde148c130cff8006 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 10:34:26 +0800 Subject: [PATCH 052/590] Update README.md --- netflix-modules/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netflix-modules/README.md b/netflix-modules/README.md index c126bbdf5b..21d6958dab 100644 --- a/netflix-modules/README.md +++ b/netflix-modules/README.md @@ -2,3 +2,6 @@ This module contains articles about Netflix. +### Relevant Articles: + +- [Introduction to Netflix Mantis](https://www.baeldung.com/java-netflix-mantis) From 8d277a8d0463e93ab7ec69f593ce9a2715964204 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 10:39:29 +0800 Subject: [PATCH 053/590] Update README.md --- core-java-modules/core-java-jar/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-jar/README.md b/core-java-modules/core-java-jar/README.md index f6bb7677d4..f83ea496ab 100644 --- a/core-java-modules/core-java-jar/README.md +++ b/core-java-modules/core-java-jar/README.md @@ -7,3 +7,4 @@ This module contains articles about JAR files - [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) - [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class) - [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar) +- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names) From 4b1a853871124618c7b054d467ba9c4e285b5b90 Mon Sep 17 00:00:00 2001 From: nguyennamthai Date: Wed, 28 Oct 2020 13:12:52 +0700 Subject: [PATCH 054/590] BAEL-4477 Add a class to demonstrate that the app will crash if too many objects have a finalizer (#10200) --- .../baeldung/finalize/CrashedFinalizable.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CrashedFinalizable.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CrashedFinalizable.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CrashedFinalizable.java new file mode 100644 index 0000000000..d5ee27591b --- /dev/null +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CrashedFinalizable.java @@ -0,0 +1,28 @@ +package com.baeldung.finalize; + +import java.lang.ref.ReferenceQueue; +import java.lang.reflect.Field; + +public class CrashedFinalizable { + public static void main(String[] args) throws ReflectiveOperationException { + for (int i = 0; ; i++) { + new CrashedFinalizable(); + if ((i % 1_000_000) == 0) { + Class finalizerClass = Class.forName("java.lang.ref.Finalizer"); + Field queueStaticField = finalizerClass.getDeclaredField("queue"); + queueStaticField.setAccessible(true); + ReferenceQueue referenceQueue = (ReferenceQueue) queueStaticField.get(null); + + Field queueLengthField = ReferenceQueue.class.getDeclaredField("queueLength"); + queueLengthField.setAccessible(true); + long queueLength = (long) queueLengthField.get(referenceQueue); + System.out.format("There are %d references in the queue%n", queueLength); + } + } + } + + @Override + protected void finalize() { + System.out.print(""); + } +} From 523d4e5f7446d2a9c52e5f99efe9214944665a91 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 14:30:57 +0800 Subject: [PATCH 055/590] Update README.md --- algorithms-searching/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index a3ea023da3..1af3f19c1a 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -8,7 +8,7 @@ This module contains articles about searching algorithms. - [Depth First Search in Java](https://www.baeldung.com/java-depth-first-search) - [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search) - [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search) -- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms) +- [String Search Algorithms for Large Texts with Java](https://www.baeldung.com/java-full-text-search-algorithms) - [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) - [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) From 5192b6c07b3ebba96a14bd267de8d16a222f1f3c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 14:32:56 +0800 Subject: [PATCH 056/590] Update README.md --- libraries-data-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-data-2/README.md b/libraries-data-2/README.md index a8f2a0cb37..893d3e64e8 100644 --- a/libraries-data-2/README.md +++ b/libraries-data-2/README.md @@ -4,7 +4,7 @@ This module contains articles about libraries for data processing in Java. ### Relevant articles - [Introduction to Apache Flink with Java](https://www.baeldung.com/apache-flink) -- [Guide to the HyperLogLog Algorithm](https://www.baeldung.com/java-hyperloglog) +- [Guide to the HyperLogLog Algorithm in Java](https://www.baeldung.com/java-hyperloglog) - [Introduction to Conflict-Free Replicated Data Types](https://www.baeldung.com/java-conflict-free-replicated-data-types) - [Introduction to javax.measure](https://www.baeldung.com/javax-measure) - [A Guide to Infinispan in Java](https://www.baeldung.com/infinispan) From 4faa16d2c70b9947a8b5e2b470359b143fc514dc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:32:41 +0800 Subject: [PATCH 057/590] Update README.md --- algorithms-miscellaneous-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index 77c621339a..9233b4cc0d 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -7,7 +7,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata) - [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm) -- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm) +- [Introduction to Minimax Algorithm with a Java Implementation](https://www.baeldung.com/java-minimax-algorithm) - [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance) - [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element) - More articles: [[next -->]](/algorithms-miscellaneous-2) From 9f23e79295b726217e22bcfc8d9650f887ae628b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:36:35 +0800 Subject: [PATCH 058/590] Update README.md --- algorithms-searching/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index 1af3f19c1a..24560bf951 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -9,7 +9,7 @@ This module contains articles about searching algorithms. - [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search) - [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search) - [String Search Algorithms for Large Texts with Java](https://www.baeldung.com/java-full-text-search-algorithms) -- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) +- [Monte Carlo Tree Search for Tic-Tac-Toe Game in Java](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) - [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) - [Find the Kth Smallest Element in Two Sorted Arrays](https://www.baeldung.com/java-kth-smallest-element-in-sorted-arrays) From ceb12f8d545b1697468177958de2f638398658c9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:39:09 +0800 Subject: [PATCH 059/590] Update README.md --- algorithms-miscellaneous-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index 9233b4cc0d..02bf874197 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -6,7 +6,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. ### Relevant articles: - [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata) -- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm) +- [Example of Hill Climbing Algorithm in Java](https://www.baeldung.com/java-hill-climbing-algorithm) - [Introduction to Minimax Algorithm with a Java Implementation](https://www.baeldung.com/java-minimax-algorithm) - [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance) - [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element) From 8f077a6df1662549af6f893c93416e61e63f239c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:41:23 +0800 Subject: [PATCH 060/590] Update README.md --- algorithms-genetic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-genetic/README.md b/algorithms-genetic/README.md index 1c9e831ac2..eb4e3fb798 100644 --- a/algorithms-genetic/README.md +++ b/algorithms-genetic/README.md @@ -5,6 +5,6 @@ This module contains articles about genetic algorithms. ### Relevant articles: - [Introduction to Jenetics Library](https://www.baeldung.com/jenetics) -- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization) +- [Ant Colony Optimization with a Java Example](https://www.baeldung.com/java-ant-colony-optimization) - [Design a Genetic Algorithm in Java](https://www.baeldung.com/java-genetic-algorithm) - [The Traveling Salesman Problem in Java](https://www.baeldung.com/java-simulated-annealing-for-traveling-salesman) From 99702e0e182b33fced1147fca0a3c660f1c4b7cd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:43:43 +0800 Subject: [PATCH 061/590] Update README.md --- spring-boot-modules/spring-boot-data/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-data/README.md b/spring-boot-modules/spring-boot-data/README.md index 98589cf2d2..da22b62128 100644 --- a/spring-boot-modules/spring-boot-data/README.md +++ b/spring-boot-modules/spring-boot-data/README.md @@ -10,4 +10,4 @@ This module contains articles about Spring Boot with Spring Data - [Repositories with Multiple Spring Data Modules](https://www.baeldung.com/spring-multiple-data-modules) - [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) - [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent) -- [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) +- [Guide To Running Logic on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) From c8bd5248ed7d1ee131ff6249c89ccea0bdfed99e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:45:12 +0800 Subject: [PATCH 062/590] Update README.md --- persistence-modules/spring-jdbc/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index 58d7bdec43..efe675be51 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -1,6 +1,6 @@ ## Spring JDBC ### Relevant Articles: -- [Spring JDBC Template](https://www.baeldung.com/spring-jdbc-jdbctemplate) +- [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate) - [Spring JDBC Template Testing](https://www.baeldung.com/spring-jdbctemplate-testing) -- [Spring JDBC Template In Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) \ No newline at end of file +- [Spring JDBC Template In Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) From 54753f3f09ae6531cc8a4f074aaf134434248523 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:46:34 +0800 Subject: [PATCH 063/590] Update README.md --- core-java-modules/core-java-string-algorithms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms/README.md b/core-java-modules/core-java-string-algorithms/README.md index 70a4b5ffaf..b30d2967d2 100644 --- a/core-java-modules/core-java-string-algorithms/README.md +++ b/core-java-modules/core-java-string-algorithms/README.md @@ -3,7 +3,7 @@ This module contains articles about string-related algorithms. ### Relevant Articles: -- [Check If a String Is a Palindrome](https://www.baeldung.com/java-palindrome) +- [Check if a String is a Palindrome in Java](https://www.baeldung.com/java-palindrome) - [Count Occurrences of a Char in a String](https://www.baeldung.com/java-count-chars) - [Using indexOf to Find All Occurrences of a Word in a String](https://www.baeldung.com/java-indexOf-find-string-occurrences) - [Removing Stopwords from a String in Java](https://www.baeldung.com/java-string-remove-stopwords) From 6c1e37aa0010ca024e15a41988b5db93abe3cd65 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:19:53 +0800 Subject: [PATCH 064/590] Update README.md --- java-numbers/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java-numbers/README.md b/java-numbers/README.md index f4b76c3c98..3007e1746c 100644 --- a/java-numbers/README.md +++ b/java-numbers/README.md @@ -3,12 +3,12 @@ This module contains articles about numbers in Java. ### Relevant Articles: -- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) -- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number) -- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) -- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum) -- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) -- [A Practical Guide to DecimalFormat](http://www.baeldung.com/java-decimalformat) +- [Number of Digits in an Integer in Java](https://www.baeldung.com/java-number-of-digits-in-int) +- [How to Round a Number to N Decimal Places in Java](https://www.baeldung.com/java-round-decimal-number) +- [BigDecimal and BigInteger in Java](https://www.baeldung.com/java-bigdecimal-biginteger) +- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum in Java](https://www.baeldung.com/java-algorithm-number-pairs-sum) +- [Java – Random Long, Float, Integer and Double](https://www.baeldung.com/java-generate-random-long-float-integer-double) +- [A Practical Guide to DecimalFormat](https://www.baeldung.com/java-decimalformat) - [Calculating the nth Root in Java](https://www.baeldung.com/java-nth-root) - [Convert Double to String, Removing Decimal Places](https://www.baeldung.com/java-double-to-string) - [Changing the Order in a Sum Operation Can Produce Different Results?](https://www.baeldung.com/java-floating-point-sum-order) From c3474e72138565d60df70626e9673961d8829098 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:24:05 +0800 Subject: [PATCH 065/590] Update README.md --- persistence-modules/spring-data-jpa-query-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-query-2/README.md b/persistence-modules/spring-data-jpa-query-2/README.md index bdc8d7cb32..36875c899c 100644 --- a/persistence-modules/spring-data-jpa-query-2/README.md +++ b/persistence-modules/spring-data-jpa-query-2/README.md @@ -3,7 +3,7 @@ This module contains articles about querying data using Spring Data JPA ### Relevant Articles: -- [Spring Data JPA @Query Annotation](https://www.baeldung.com/spring-data-jpa-query) +- [Spring Data JPA @Query](https://www.baeldung.com/spring-data-jpa-query) - [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries) - [Query Entities by Dates and Times with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-by-date) - [Hibernate Pagination](https://www.baeldung.com/hibernate-pagination) From 3d6460daa45c9f78924fbaac2e3f30eaa822557f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:26:53 +0800 Subject: [PATCH 066/590] Update README.md --- patterns/design-patterns-architectural/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patterns/design-patterns-architectural/README.md b/patterns/design-patterns-architectural/README.md index 5b6011c159..ae6781c66c 100644 --- a/patterns/design-patterns-architectural/README.md +++ b/patterns/design-patterns-architectural/README.md @@ -1,4 +1,4 @@ ### Relevant Articles: -- [Service Locator Pattern](https://www.baeldung.com/java-service-locator-pattern) +- [Service Locator Pattern and Java Implementation](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 9fa553d3786fea9f2ff62b29867b9d0960808fb1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:28:26 +0800 Subject: [PATCH 067/590] Update README.md --- algorithms-miscellaneous-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-4/README.md b/algorithms-miscellaneous-4/README.md index fd33b58d72..1524bfb65f 100644 --- a/algorithms-miscellaneous-4/README.md +++ b/algorithms-miscellaneous-4/README.md @@ -6,7 +6,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm) - [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters) -- [Find the Middle Element of a Linked List](https://www.baeldung.com/java-linked-list-middle-element) +- [Find the Middle Element of a Linked List in Java](https://www.baeldung.com/java-linked-list-middle-element) - [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings) - [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters) - [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations) From e4bc8b2fda94e2494c66d12773d2869e4891fef7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:30:31 +0800 Subject: [PATCH 068/590] Update README.md --- algorithms-miscellaneous-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-4/README.md b/algorithms-miscellaneous-4/README.md index 1524bfb65f..2649df9fc9 100644 --- a/algorithms-miscellaneous-4/README.md +++ b/algorithms-miscellaneous-4/README.md @@ -5,7 +5,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. ### Relevant articles: - [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm) -- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters) +- [Check If a String Contains All The Letters of The Alphabet with Java](https://www.baeldung.com/java-string-contains-all-letters) - [Find the Middle Element of a Linked List in Java](https://www.baeldung.com/java-linked-list-middle-element) - [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings) - [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters) From f82d9e0fe592b6308c58639226e6c564be25efb9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:32:06 +0800 Subject: [PATCH 069/590] Update README.md --- core-java-modules/core-java-lang-math-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69ee00b5a5..703bd2c12f 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -9,7 +9,7 @@ - [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap) - [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points) - [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines) -- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred) +- [Round Up to the Nearest Hundred in Java](https://www.baeldung.com/java-round-up-nearest-hundred) - [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) From 2b35fd795b5a49461b1b2fadc1e73abaf0a9f2c1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:33:44 +0800 Subject: [PATCH 070/590] Update README.md --- libraries-6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-6/README.md b/libraries-6/README.md index 5be600f50e..f91ad43bbe 100644 --- a/libraries-6/README.md +++ b/libraries-6/README.md @@ -13,7 +13,7 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) - [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) -- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) +- [Exactly Once Processing in Kafka with Java](https://www.baeldung.com/kafka-exactly-once) - [Introduction to Protonpack](https://www.baeldung.com/java-protonpack) - [Java-R Integration](https://www.baeldung.com/java-r-integration) - [Using libphonenumber to Validate Phone Numbers](https://www.baeldung.com/java-libphonenumber) From 493d3b2c3713d0f5cfff4b07180c9e1f1aec6bf5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:35:26 +0800 Subject: [PATCH 071/590] Update README.md --- spring-5-reactive-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive-2/README.md b/spring-5-reactive-2/README.md index 54f7ad35b1..397f6be57c 100644 --- a/spring-5-reactive-2/README.md +++ b/spring-5-reactive-2/README.md @@ -6,7 +6,7 @@ This module contains articles about reactive Spring 5 - [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) - [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) - [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher) -- [Debugging Reactive Streams in Spring 5](https://www.baeldung.com/spring-debugging-reactive-streams) +- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) - [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content) - [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) - More articles: [[<-- prev]](/spring-5-reactive) From 65d3dab26fe824effcb98fc770c78f63d90c2b7f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:36:53 +0800 Subject: [PATCH 072/590] Update README.md --- core-java-modules/core-java-string-algorithms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms/README.md b/core-java-modules/core-java-string-algorithms/README.md index b30d2967d2..c3eafda23d 100644 --- a/core-java-modules/core-java-string-algorithms/README.md +++ b/core-java-modules/core-java-string-algorithms/README.md @@ -10,7 +10,7 @@ This module contains articles about string-related algorithms. - [Removing Repeated Characters from a String](https://www.baeldung.com/java-remove-repeated-char) - [How to Reverse a String in Java](https://www.baeldung.com/java-reverse-string) - [Check If a String Is a Pangram in Java](https://www.baeldung.com/java-string-pangram) -- [Check If a String Contains Multiple Keywords](https://www.baeldung.com/string-contains-multiple-words) +- [Check If a String Contains Multiple Keywords in Java](https://www.baeldung.com/string-contains-multiple-words) - [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) - [Remove Emojis from a Java String](https://www.baeldung.com/java-string-remove-emojis) - More articles: [[next -->]](../core-java-string-algorithms-2) From ad4350d84bb14f85180be218ba6e8f7dc3caf936 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:38:22 +0800 Subject: [PATCH 073/590] Update README.md --- algorithms-sorting-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-sorting-2/README.md b/algorithms-sorting-2/README.md index 71c9b8f86c..5ea33a259a 100644 --- a/algorithms-sorting-2/README.md +++ b/algorithms-sorting-2/README.md @@ -2,6 +2,6 @@ - [Sorting a String Alphabetically in Java](https://www.baeldung.com/java-sort-string-alphabetically) - [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers) -- [How an In-Place Sorting Algorithm Works](https://www.baeldung.com/java-in-place-sorting) +- [Guide to In-Place Sorting Algorithm Works with a Java Implementation](https://www.baeldung.com/java-in-place-sorting) - [Partitioning and Sorting Arrays with Many Repeated Entries](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries) - More articles: [[<-- prev]](/algorithms-sorting) From 4f1d748669e5928d59d9dc471c49fbf94e6587ee Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:39:46 +0800 Subject: [PATCH 074/590] Update README.md --- core-java-modules/core-java-string-algorithms-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms-2/README.md b/core-java-modules/core-java-string-algorithms-2/README.md index 94ace77d66..dbfbb3ef3c 100644 --- a/core-java-modules/core-java-string-algorithms-2/README.md +++ b/core-java-modules/core-java-string-algorithms-2/README.md @@ -11,6 +11,6 @@ This module contains articles about string-related algorithms. - [Join Array of Primitives with Separator in Java](https://www.baeldung.com/java-join-primitive-array) - [Pad a String with Zeros or Spaces in Java](https://www.baeldung.com/java-pad-string) - [Remove Leading and Trailing Characters from a String](https://www.baeldung.com/java-remove-trailing-characters) -- [Counting Words in a String](https://www.baeldung.com/java-word-counting) +- [Counting Words in a String with Java](https://www.baeldung.com/java-word-counting) - [Finding the Difference Between Two Strings in Java](https://www.baeldung.com/java-difference-between-two-strings) - More articles: [[<-- prev]](../core-java-string-algorithms) From a51d5c6cbeef2ff363ac6dc10f0ae1e6b33f6482 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:43:32 +0800 Subject: [PATCH 075/590] Update README.md --- algorithms-miscellaneous-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index e5d46ace1c..e2ed173970 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -9,7 +9,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree) - [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers) - [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack) -- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree) +- [How to Determine if a Binary Tree is Balanced in Java](https://www.baeldung.com/java-balanced-binary-tree) - [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms) - [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm) - [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray) From 1e4a657d8742c0ecbcdd10a5754264e177a1fc3e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:45:49 +0800 Subject: [PATCH 076/590] Update README.md --- algorithms-miscellaneous-6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 5c2306d794..3756e51fb5 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -2,7 +2,7 @@ - [Boruvka’s Algorithm for Minimum Spanning Trees](https://www.baeldung.com/java-boruvka-algorithm) - [Gradient Descent in Java](https://www.baeldung.com/java-gradient-descent) -- [Kruskal’s Algorithm for Spanning Trees](https://www.baeldung.com/java-spanning-trees-kruskal) +- [Kruskal’s Algorithm for Spanning Trees with a Java Implementation](https://www.baeldung.com/java-spanning-trees-kruskal) - [Balanced Brackets Algorithm in Java](https://www.baeldung.com/java-balanced-brackets-algorithm) - [Efficiently Merge Sorted Java Sequences](https://www.baeldung.com/java-merge-sorted-sequences) - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) From b0a4e469e1fc61bca2cc14e84a6709f7b38be720 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:47:32 +0800 Subject: [PATCH 077/590] Update README.md --- algorithms-miscellaneous-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index e2ed173970..243d4fc591 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -14,6 +14,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm) - [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray) - [How to Merge Two Sorted Arrays](https://www.baeldung.com/java-merge-sorted-arrays) -- [Median of Stream of Integers using Heap](https://www.baeldung.com/java-stream-integers-median-using-heap) +- [Median of Stream of Integers using Heap in Java](https://www.baeldung.com/java-stream-integers-median-using-heap) - More articles: [[<-- prev]](/algorithms-miscellaneous-4) [[next -->]](/algorithms-miscellaneous-6) From e8efd0b21148404c4d07cf53661770a073987a70 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:49:18 +0800 Subject: [PATCH 078/590] Update README.md --- algorithms-miscellaneous-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index 243d4fc591..f8f663f54c 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -13,7 +13,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms) - [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm) - [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray) -- [How to Merge Two Sorted Arrays](https://www.baeldung.com/java-merge-sorted-arrays) +- [How to Merge Two Sorted Arrays in Java](https://www.baeldung.com/java-merge-sorted-arrays) - [Median of Stream of Integers using Heap in Java](https://www.baeldung.com/java-stream-integers-median-using-heap) - More articles: [[<-- prev]](/algorithms-miscellaneous-4) [[next -->]](/algorithms-miscellaneous-6) From 491a5db344e568e927699604f2bcc8b4d9f3eb91 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:51:32 +0800 Subject: [PATCH 079/590] Update README.md --- algorithms-miscellaneous-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index f8f663f54c..e1a270429d 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -12,7 +12,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [How to Determine if a Binary Tree is Balanced in Java](https://www.baeldung.com/java-balanced-binary-tree) - [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms) - [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm) -- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray) +- [Maximum Subarray Problem in Java](https://www.baeldung.com/java-maximum-subarray) - [How to Merge Two Sorted Arrays in Java](https://www.baeldung.com/java-merge-sorted-arrays) - [Median of Stream of Integers using Heap in Java](https://www.baeldung.com/java-stream-integers-median-using-heap) - More articles: [[<-- prev]](/algorithms-miscellaneous-4) [[next -->]](/algorithms-miscellaneous-6) From 5f1719c16130d336b715e0ed35d380856049fc94 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:53:05 +0800 Subject: [PATCH 080/590] Update README.md --- algorithms-miscellaneous-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index e1a270429d..54b936586f 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -11,7 +11,7 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack) - [How to Determine if a Binary Tree is Balanced in Java](https://www.baeldung.com/java-balanced-binary-tree) - [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms) -- [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm) +- [Prim’s Algorithm with a Java Implementation](https://www.baeldung.com/java-prim-algorithm) - [Maximum Subarray Problem in Java](https://www.baeldung.com/java-maximum-subarray) - [How to Merge Two Sorted Arrays in Java](https://www.baeldung.com/java-merge-sorted-arrays) - [Median of Stream of Integers using Heap in Java](https://www.baeldung.com/java-stream-integers-median-using-heap) From 85d7a456998f7d77e0c393b394f2c89835f8099d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:54:34 +0800 Subject: [PATCH 081/590] Update README.md --- algorithms-sorting-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-sorting-2/README.md b/algorithms-sorting-2/README.md index 5ea33a259a..b31cfceb42 100644 --- a/algorithms-sorting-2/README.md +++ b/algorithms-sorting-2/README.md @@ -3,5 +3,5 @@ - [Sorting a String Alphabetically in Java](https://www.baeldung.com/java-sort-string-alphabetically) - [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers) - [Guide to In-Place Sorting Algorithm Works with a Java Implementation](https://www.baeldung.com/java-in-place-sorting) -- [Partitioning and Sorting Arrays with Many Repeated Entries](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries) +- [Partitioning and Sorting Arrays with Many Repeated Entries with Java Examples](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries) - More articles: [[<-- prev]](/algorithms-sorting) From 83489df71134b2428b4e82ee513a4c612bc6676a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:57:05 +0800 Subject: [PATCH 082/590] Update README.md --- core-java-modules/core-java-regex/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-regex/README.md b/core-java-modules/core-java-regex/README.md index ad8ba1e4ae..92321fa656 100644 --- a/core-java-modules/core-java-regex/README.md +++ b/core-java-modules/core-java-regex/README.md @@ -9,7 +9,7 @@ - [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char) - [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile) - [Difference Between Java Matcher find() and matches()](https://www.baeldung.com/java-matcher-find-vs-matches) -- [How to Use Regular Expressions to Replace Tokens in Strings](https://www.baeldung.com/java-regex-token-replacement) +- [How to Use Regular Expressions to Replace Tokens in Strings in Java](https://www.baeldung.com/java-regex-token-replacement) - [Regular Expressions \s and \s+ in Java](https://www.baeldung.com/java-regex-s-splus) - [Validate Phone Numbers With Java Regex](https://www.baeldung.com/java-regex-validate-phone-numbers) - [How to Count the Number of Matches for a Regex?](https://www.baeldung.com/java-count-regex-matches) From 6e4cff9261570f918c5b54a07a26670870aea403 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:59:15 +0800 Subject: [PATCH 083/590] Update README.md --- algorithms-searching/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index 24560bf951..5b97ed0c74 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -11,5 +11,5 @@ This module contains articles about searching algorithms. - [String Search Algorithms for Large Texts with Java](https://www.baeldung.com/java-full-text-search-algorithms) - [Monte Carlo Tree Search for Tic-Tac-Toe Game in Java](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) -- [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) +- [Fast Pattern Matching of Strings Using Suffix Tree in Java](https://www.baeldung.com/java-pattern-matching-suffix-tree) - [Find the Kth Smallest Element in Two Sorted Arrays](https://www.baeldung.com/java-kth-smallest-element-in-sorted-arrays) From 3f049c51b5dac00ad22b412ef584aa81e506321e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:01:07 +0800 Subject: [PATCH 084/590] Update README.md --- persistence-modules/spring-jdbc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index efe675be51..f442f79466 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -2,5 +2,5 @@ ### Relevant Articles: - [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate) -- [Spring JDBC Template Testing](https://www.baeldung.com/spring-jdbctemplate-testing) +- [Spring JdbcTemplate Unit Testing](https://www.baeldung.com/spring-jdbctemplate-testing) - [Spring JDBC Template In Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) From 0a0da389106464c2825e10ddaeb035cf729888b2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:03:10 +0800 Subject: [PATCH 085/590] Update README.md --- algorithms-miscellaneous-6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 3756e51fb5..4257306b72 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -1,6 +1,6 @@ ### Relevant Articles: -- [Boruvka’s Algorithm for Minimum Spanning Trees](https://www.baeldung.com/java-boruvka-algorithm) +- [Boruvka’s Algorithm for Minimum Spanning Trees in Java](https://www.baeldung.com/java-boruvka-algorithm) - [Gradient Descent in Java](https://www.baeldung.com/java-gradient-descent) - [Kruskal’s Algorithm for Spanning Trees with a Java Implementation](https://www.baeldung.com/java-spanning-trees-kruskal) - [Balanced Brackets Algorithm in Java](https://www.baeldung.com/java-balanced-brackets-algorithm) From 8f28017782d7a63e73100bf7a4427b3648de5099 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:05:43 +0800 Subject: [PATCH 086/590] Update README.md --- persistence-modules/spring-jdbc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index f442f79466..1433344b7a 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -3,4 +3,4 @@ ### Relevant Articles: - [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate) - [Spring JdbcTemplate Unit Testing](https://www.baeldung.com/spring-jdbctemplate-testing) -- [Spring JDBC Template In Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) +- [Using a List of Values in a JdbcTemplate IN Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) From a96868a314d65f078d8a45c54233e70cd4587db0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:07:37 +0800 Subject: [PATCH 087/590] Update README.md --- core-java-modules/core-java-concurrency-advanced-3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/README.md b/core-java-modules/core-java-concurrency-advanced-3/README.md index 7d98e462d7..9495d5f479 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/README.md +++ b/core-java-modules/core-java-concurrency-advanced-3/README.md @@ -13,7 +13,7 @@ This module contains articles about advanced topics about multithreading with co - [Java Thread Deadlock and Livelock](https://www.baeldung.com/java-deadlock-livelock) - [Guide to AtomicStampedReference in Java](https://www.baeldung.com/java-atomicstampedreference) - [The ABA Problem in Concurrency](https://www.baeldung.com/cs/aba-concurrency) -- [Introduction to Lock-Free Data Structures](https://www.baeldung.com/lock-free-programming) +- [Introduction to Lock-Free Data Structures with Java Examples](https://www.baeldung.com/lock-free-programming) - [Introduction to Exchanger in Java](https://www.baeldung.com/java-exchanger) - [Why Not To Start A Thread In The Constructor?](https://www.baeldung.com/java-thread-constructor) - [[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2) From 0c225ec742623fa05b5649f3a0e7bf3361a7747c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:15:12 +0800 Subject: [PATCH 088/590] Update README.md --- persistence-modules/spring-persistence-simple/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-persistence-simple/README.md b/persistence-modules/spring-persistence-simple/README.md index 34211e981e..f118d12f6f 100644 --- a/persistence-modules/spring-persistence-simple/README.md +++ b/persistence-modules/spring-persistence-simple/README.md @@ -5,7 +5,7 @@ ### Relevant Articles: - [Transaction Propagation and Isolation in Spring @Transactional](https://www.baeldung.com/spring-transactional-propagation-isolation) -- [JTA Transaction with Spring](https://www.baeldung.com/spring-vs-jta-transactional) +- [Transactional Annotations: Spring vs. JTA](https://www.baeldung.com/spring-vs-jta-transactional) - [Test a Mock JNDI Datasource with Spring](https://www.baeldung.com/spring-mock-jndi-datasource) - [Detecting If a Spring Transaction Is Active](https://www.baeldung.com/spring-transaction-active) From 8a97af121f41542421b6ff74e19834558570d46e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:16:48 +0800 Subject: [PATCH 089/590] Update README.md --- algorithms-miscellaneous-6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 4257306b72..f21eddeed8 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -8,6 +8,6 @@ - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) - [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher) - [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver) -- [Finding Top K Elements in an Array](https://www.baeldung.com/java-array-top-elements) +- [Finding Top K Elements in a Java Array](https://www.baeldung.com/java-array-top-elements) - [Reversing a Linked List in Java](https://www.baeldung.com/java-reverse-linked-list) - More articles: [[<-- prev]](/algorithms-miscellaneous-5) From e5681dee1beb3f9d5d4cdae6c63629f694d799a4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:18:55 +0800 Subject: [PATCH 090/590] Update README.md --- algorithms-searching/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index 5b97ed0c74..7d10100832 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -12,4 +12,4 @@ This module contains articles about searching algorithms. - [Monte Carlo Tree Search for Tic-Tac-Toe Game in Java](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) - [Fast Pattern Matching of Strings Using Suffix Tree in Java](https://www.baeldung.com/java-pattern-matching-suffix-tree) -- [Find the Kth Smallest Element in Two Sorted Arrays](https://www.baeldung.com/java-kth-smallest-element-in-sorted-arrays) +- [Find the Kth Smallest Element in Two Sorted Arrays in Java](https://www.baeldung.com/java-kth-smallest-element-in-sorted-arrays) From ed3fe0cfce8a92499d37eda4b73e27682728e32f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:21:03 +0800 Subject: [PATCH 091/590] Update README.md --- core-java-modules/core-java-lang-math-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 703bd2c12f..a98ff863ac 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -13,5 +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) +- [Largest Power of 2 That Is Less Than the Given Number with Java](https://www.baeldung.com/java-largest-power-of-2-less-than-number) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math) From 0794a1ad1b757447a052e9ff24549b6970d8415c Mon Sep 17 00:00:00 2001 From: Kumar Chandrakant Date: Thu, 29 Oct 2020 10:41:46 +0530 Subject: [PATCH 092/590] Adding source code for article tracked under BAEL-4576 (#10203) Co-authored-by: CHANDRAKANT Kumar --- .../core-java-functional/README.md | 1 + .../core-java-functional/pom.xml | 18 +++++++++ .../com/baeldung/functional/Currying.java | 26 +++++++++++++ .../functional/FirstClassFunctions.java | 24 ++++++++++++ .../functional/FunctionComposition.java | 20 ++++++++++ .../baeldung/functional/ImmutableData.java | 36 +++++++++++++++++ .../java/com/baeldung/functional/Monads.java | 11 ++++++ .../baeldung/functional/PureFunctions.java | 13 +++++++ .../com/baeldung/functional/Recursion.java | 17 ++++++++ .../functional/ReferentialTransparency.java | 39 +++++++++++++++++++ .../baeldung/functional/CurryingUnitTest.java | 22 +++++++++++ .../FirstClassFunctionsUnitTest.java | 27 +++++++++++++ .../FunctionCompositionUnitTest.java | 23 +++++++++++ .../baeldung/functional/MonadsUnitTest.java | 19 +++++++++ .../functional/PureFunctionsUnitTets.java | 18 +++++++++ .../functional/RecursionUnitTest.java | 23 +++++++++++ core-java-modules/pom.xml | 1 + 17 files changed, 338 insertions(+) create mode 100644 core-java-modules/core-java-functional/README.md create mode 100644 core-java-modules/core-java-functional/pom.xml create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java create mode 100644 core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java create mode 100644 core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java diff --git a/core-java-modules/core-java-functional/README.md b/core-java-modules/core-java-functional/README.md new file mode 100644 index 0000000000..ff12555376 --- /dev/null +++ b/core-java-modules/core-java-functional/README.md @@ -0,0 +1 @@ +## Relevant articles: diff --git a/core-java-modules/core-java-functional/pom.xml b/core-java-modules/core-java-functional/pom.xml new file mode 100644 index 0000000000..f00600c794 --- /dev/null +++ b/core-java-modules/core-java-functional/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + core-java-functional + 0.1.0-SNAPSHOT + core-java-functional + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + \ No newline at end of file diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java new file mode 100644 index 0000000000..594fea4b8c --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java @@ -0,0 +1,26 @@ +package com.baeldung.functional; + +import java.util.function.Function; + +public class Currying { + + private static Function> weight = mass -> gravity -> mass * gravity; + + private static Function weightOnEarth = weight.apply(9.81); + + private static Function weightOnMars = weight.apply(3.75); + + public static Double weightOnEarth(Double mass) { + return weightOnEarth.apply(mass); + } + + public static Double weightOnMars(Double mass) { + return weightOnMars.apply(mass); + } + + public static Function weightOnEarth() { + final double gravity = 9.81; + return mass -> mass * gravity; + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java new file mode 100644 index 0000000000..13b408ab27 --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java @@ -0,0 +1,24 @@ +package com.baeldung.functional; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class FirstClassFunctions { + + public static List sortWithoutLambda(List numbers) { + Collections.sort(numbers, new Comparator() { + @Override + public int compare(Integer n1, Integer n2) { + return n1.compareTo(n2); + } + }); + return numbers; + } + + public static List sortWithLambda(List numbers) { + Collections.sort(numbers, (n1, n2) -> n1.compareTo(n2)); + return numbers; + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java new file mode 100644 index 0000000000..57103be98a --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java @@ -0,0 +1,20 @@ +package com.baeldung.functional; + +import java.util.function.Function; + +public class FunctionComposition { + + private static Function log = (value) -> Math.log(value); + private static Function sqrt = (value) -> Math.sqrt(value); + + public static Double logThenSqrt(Double number) { + Function logThenSqrt = sqrt.compose(log); + return (logThenSqrt.apply(3.14)); + } + + public static Double sqrtThenLog(Double number) { + Function sqrtThenLog = sqrt.andThen(log); + return (sqrtThenLog.apply(3.14)); + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java new file mode 100644 index 0000000000..738680f743 --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java @@ -0,0 +1,36 @@ +package com.baeldung.functional; + +public class ImmutableData { + + private final String someData; + + private final AnotherImmutableData anotherImmutableData; + + public ImmutableData(final String someData, final AnotherImmutableData anotherImmutableData) { + this.someData = someData; + this.anotherImmutableData = anotherImmutableData; + } + + public String getSomeData() { + return someData; + } + + public AnotherImmutableData getAnotherImmutableData() { + return anotherImmutableData; + } + + public class AnotherImmutableData { + + private final Integer someOtherData; + + public AnotherImmutableData(final Integer someData) { + this.someOtherData = someData; + } + + public Integer getSomeOtherData() { + return someOtherData; + } + + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java new file mode 100644 index 0000000000..c1223c73c7 --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java @@ -0,0 +1,11 @@ +package com.baeldung.functional; + +import java.util.Optional; + +public class Monads { + + public static Optional add(Optional val1, Optional val2) { + return val1.flatMap(first -> val2.flatMap(second -> Optional.of(first + second))); + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java new file mode 100644 index 0000000000..522b9de9eb --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java @@ -0,0 +1,13 @@ +package com.baeldung.functional; + +import java.util.List; +import java.util.stream.Collectors; + +public class PureFunctions { + + public static Integer sum(List numbers) { + return numbers.stream() + .collect(Collectors.summingInt(Integer::intValue)); + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java new file mode 100644 index 0000000000..d5492df69d --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java @@ -0,0 +1,17 @@ +package com.baeldung.functional; + +public class Recursion { + + public static Integer headRecursion(Integer number) { + + return (number == 1) ? 1 : number * headRecursion(number - 1); + + } + + public static Integer tailRecursion(Integer number, Integer result) { + + return (number == 1) ? result : tailRecursion(number - 1, result * number); + + } + +} diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java new file mode 100644 index 0000000000..1392cdd00a --- /dev/null +++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java @@ -0,0 +1,39 @@ +package com.baeldung.functional; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ReferentialTransparency { + + private static Logger logger = Logger.getGlobal(); + + public void main() { + + String data = new SimpleData().setData("Baeldung") + .getData(); + logger.log(Level.INFO, new SimpleData().setData("Baeldung") + .getData()); + logger.log(Level.INFO, data); + logger.log(Level.INFO, "Baeldung"); + } + + public class SimpleData { + + private Logger logger = Logger.getGlobal(); + + private String data; + + public String getData() { + logger.log(Level.INFO, "Get data called for SimpleData"); + return data; + } + + public SimpleData setData(String data) { + logger.log(Level.INFO, "Set data called for SimpleData"); + this.data = data; + return this; + } + + } + +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java new file mode 100644 index 0000000000..0cf96ed566 --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class CurryingUnitTest { + + @Test + public void testWeightOnEarth() { + + assertEquals(588.6, Currying.weightOnEarth(60.0), 0.1); + + } + + @Test + public void testWeightOnMars() { + + assertEquals(225.0, Currying.weightOnMars(60.0), 0.1); + + } +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java new file mode 100644 index 0000000000..8056b44f21 --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; + +public class FirstClassFunctionsUnitTest { + + @Test + public void testSortingWithoutLambda() { + + assertEquals(new Integer(8), FirstClassFunctions.sortWithoutLambda(Arrays.asList(new Integer(10), new Integer(8))) + .get(0)); + + } + + @Test + public void testSortingWithLambda() { + + assertEquals(new Integer(8), FirstClassFunctions.sortWithLambda(Arrays.asList(new Integer(10), new Integer(8))) + .get(0)); + + } + +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java new file mode 100644 index 0000000000..48d8fb695c --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class FunctionCompositionUnitTest { + + @Test + public void testLogThenSqrt() { + + assertEquals(1.07, FunctionComposition.logThenSqrt(3.14), 0.01); + + } + + @Test + public void testSqrtThenLog() { + + assertEquals(0.57, FunctionComposition.sqrtThenLog(3.14), 0.01); + + } + +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java new file mode 100644 index 0000000000..8258eef59e --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + +import org.junit.Test; + +public class MonadsUnitTest { + + @Test + public void testOptionalAdd() { + + assertEquals(5, Monads.add(Optional.of(new Integer(2)), Optional.of(new Integer(3))) + .get()); + + } + +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java new file mode 100644 index 0000000000..23cca8bf8d --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java @@ -0,0 +1,18 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; + +public class PureFunctionsUnitTets { + + @Test + public void testSortingWithoutLambda() { + + assertEquals(new Integer(18), PureFunctions.sum(Arrays.asList(new Integer(10), new Integer(8)))); + + } + +} diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java new file mode 100644 index 0000000000..aa406dc7ab --- /dev/null +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.functional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class RecursionUnitTest { + + @Test + public void testHeadRecursion() { + + assertEquals(120, Recursion.headRecursion(5)); + + } + + @Test + public void testTailRecursion() { + + assertEquals(120, Recursion.tailRecursion(5, 1)); + + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index a6aecef741..b995092782 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -60,6 +60,7 @@ core-java-exceptions-2 core-java-exceptions-3 core-java-function + core-java-functional core-java-io core-java-io-2 From 985d8df0885acf35ccc0c94701d9a2ef791c78cb Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 29 Oct 2020 15:16:29 +0200 Subject: [PATCH 093/590] add additional property for httpclient v.4.5 --- .../HttpClientGettingCookieValueUnitTest.java | 4 +++- httpclient-simple/pom.xml | 2 +- .../sec/HttpClientCookieLiveTest.java | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java b/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java index c3b0ef3c25..404acb3098 100644 --- a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java +++ b/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java @@ -4,12 +4,13 @@ import org.apache.http.client.CookieStore; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.cookie.ClientCookie; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.cookie.BasicClientCookie; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,6 +48,7 @@ public class HttpClientGettingCookieValueUnitTest { BasicCookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = new BasicClientCookie("custom_cookie", "test_value"); cookie.setDomain("baeldung.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); cookie.setPath("/"); cookieStore.addCookie(cookie); return cookieStore; diff --git a/httpclient-simple/pom.xml b/httpclient-simple/pom.xml index 4b97070307..019f1af856 100644 --- a/httpclient-simple/pom.xml +++ b/httpclient-simple/pom.xml @@ -302,7 +302,7 @@ 2.5.1 4.4.11 - 4.5.8 + 4.5.8 1.6.1 diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java index 287b6e996c..75286e5b2e 100644 --- a/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java @@ -1,19 +1,23 @@ package com.baeldung.httpclient.sec; -import org.apache.http.client.HttpClient; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.cookie.ClientCookie; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import com.baeldung.httpclient.ResponseUtil; + import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; @@ -25,6 +29,8 @@ public class HttpClientCookieLiveTest { private CloseableHttpClient instance; private CloseableHttpResponse response; + + private static Logger log = LoggerFactory.getLogger(HttpClientCookieLiveTest.class); @Before public final void before() { @@ -54,11 +60,15 @@ public class HttpClientCookieLiveTest { final BasicCookieStore cookieStore = new BasicCookieStore(); final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234"); cookie.setDomain(".github.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); + cookie.setPath("/"); cookieStore.addCookie(cookie); - final HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); - - final HttpGet request = new HttpGet("http://www.github.com"); + + DefaultHttpClient client = new DefaultHttpClient(); + client.setCookieStore(cookieStore); + + final HttpGet request = new HttpGet("https://www.github.com"); response = (CloseableHttpResponse) client.execute(request); @@ -70,6 +80,7 @@ public class HttpClientCookieLiveTest { final BasicCookieStore cookieStore = new BasicCookieStore(); final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234"); cookie.setDomain(".github.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); cookie.setPath("/"); cookieStore.addCookie(cookie); instance = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); From 46c257f00f718dcd157bd7bfaf8bd8dc254271fe Mon Sep 17 00:00:00 2001 From: "mateusz.szablak" Date: Thu, 29 Oct 2020 16:44:28 +0100 Subject: [PATCH 094/590] review #2 --- .../main/java/com/baeldung/tostring/StringCastUtils.java | 8 +++++--- .../test/java/com/baeldung/tostring/ToStringUnitTest.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java index f59e494845..e96c87dfe4 100644 --- a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java +++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java @@ -2,14 +2,16 @@ package com.baeldung.tostring; public class StringCastUtils { public static String castToString(Object object) { - if (object instanceof String) + if (object instanceof String) { return (String) object; + } return null; } - public static String getToString(Object object) { - if (object != null) + public static String getStringRepresentation(Object object) { + if (object != null) { return object.toString(); + } return null; } } diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java index b8af7e4968..51a27e1b5c 100644 --- a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java +++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java @@ -2,7 +2,9 @@ package com.baeldung.tostring; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; public class ToStringUnitTest { @Test @@ -96,7 +98,7 @@ public class ToStringUnitTest { Object obj = input; - assertEquals("1234", StringCastUtils.getToString(obj)); - assertNotSame("1234", StringCastUtils.getToString(obj)); + assertEquals("1234", StringCastUtils.getStringRepresentation(obj)); + assertNotSame("1234", StringCastUtils.getStringRepresentation(obj)); } } From 4cac5aa1d8a1d0aff382595dc6167d812ecb4c4f Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 29 Oct 2020 22:01:15 +0100 Subject: [PATCH 095/590] JAVA-2824 Fix tests in Java 9 and above modules (Update after PR review) --- .../httpclient/test/HttpRequestUnitTest.java | 7 ++-- .../screenshot/ScreenshotUnitTest.java | 22 +++++++------ ...itTest.java => ElapsedTimeManualTest.java} | 6 ++-- pom.xml | 32 +++++++++---------- 4 files changed, 35 insertions(+), 32 deletions(-) rename core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/{ElapsedTimeUnitTest.java => ElapsedTimeManualTest.java} (97%) diff --git a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java index e09dccc1f0..a3a5592cd9 100644 --- a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java @@ -18,6 +18,7 @@ import java.security.NoSuchAlgorithmException; import java.time.Duration; import org.junit.Test; +import org.junit.jupiter.api.Disabled; public class HttpRequestUnitTest { @@ -52,8 +53,8 @@ public class HttpRequestUnitTest { * This test will fail as soon as the given URL returns a HTTP 2 response. * Therefore, let's leave it commented out. * */ - - /* @Test + @Test + @Disabled public void shouldFallbackToHttp1_1WhenWebsiteDoesNotUseHttp2() throws IOException, InterruptedException, URISyntaxException, NoSuchAlgorithmException { HttpRequest request = HttpRequest.newBuilder() .uri(new URI("https://postman-echo.com/get")) @@ -65,7 +66,7 @@ public class HttpRequestUnitTest { .send(request, HttpResponse.BodyHandlers.ofString()); assertThat(response.version(), equalTo(HttpClient.Version.HTTP_1_1)); - }*/ + } @Test public void shouldReturnStatusOKWhenSendGetRequestWithDummyHeaders() throws IOException, InterruptedException, URISyntaxException { diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java index 4391037eb2..ac358b4e71 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java @@ -10,6 +10,7 @@ import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; import org.junit.Test; +import org.junit.jupiter.api.Disabled; import static org.junit.Assert.assertTrue; @@ -40,15 +41,16 @@ public class ScreenshotUnitTest { assertTrue(imageFile.exists()); } - // This methods needs a component as a parameter and can only be run from an application with a GUI - // @Test - // public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { - // Rectangle componentRect = component.getBounds(); - // BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); - // component.paint(bufferedImage.getGraphics()); - // File imageFile = File.createTempFile("component-screenshot", "bmp"); - // ImageIO.write(bufferedImage, "bmp", imageFile); - // assertTrue(imageFile.exists()); - // } + // This methods needs a component as a parameter and can only be run from an application with a GUI + @Test + @Disabled + public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { + Rectangle componentRect = component.getBounds(); + BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); + component.paint(bufferedImage.getGraphics()); + File imageFile = File.createTempFile("component-screenshot", "bmp"); + ImageIO.write(bufferedImage, "bmp", imageFile); + assertTrue(imageFile.exists()); + } } \ No newline at end of file diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java similarity index 97% rename from core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java rename to core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java index e5a9cdd603..211222c665 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java @@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.time.StopWatch; import org.junit.Test; -public class ElapsedTimeUnitTest { +public class ElapsedTimeManualTest { @Test public void givenRunningTask_whenMeasuringTimeWithCurrentTimeMillis_thenGetElapsedTime() throws InterruptedException { @@ -55,7 +55,7 @@ public class ElapsedTimeUnitTest { The below test depends on the elapsed time, which isn't ideal in a test. Also, it slows down test execution artificially. */ - /*@Test + @Test public void givenRunningTask_whenMeasuringTimeWithInstantClass_thenGetElapsedTime() throws InterruptedException { Instant start = Instant.now(); System.out.println("start: " + start); @@ -70,7 +70,7 @@ public class ElapsedTimeUnitTest { System.out.println("elapsed: " + timeElapsed); assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L)); - }*/ + } /** * Simulate task running for 2.5 seconds. diff --git a/pom.xml b/pom.xml index 602b92ffee..63f2a12640 100644 --- a/pom.xml +++ b/pom.xml @@ -1368,21 +1368,21 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - core-java-modules/core-java-9-jigsaw - + core-java-modules/core-java-9-jigsaw + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - core-java-modules/core-java-11 + core-java-modules/core-java-11 core-java-modules/core-java-collections-set - core-java-modules/core-java-date-operations-1 - core-java-modules/core-java-datetime-conversion - core-java-modules/core-java-datetime-string + core-java-modules/core-java-date-operations-1 + core-java-modules/core-java-datetime-conversion + core-java-modules/core-java-datetime-string core-java-modules/core-java-jpms - core-java-modules/core-java-os - core-java-modules/core-java-time-measurements + core-java-modules/core-java-os + core-java-modules/core-java-time-measurements core-java-modules/multimodulemavenproject @@ -1412,21 +1412,21 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - core-java-modules/core-java-9-jigsaw - + core-java-modules/core-java-9-jigsaw + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - core-java-modules/core-java-11 + core-java-modules/core-java-11 core-java-modules/core-java-collections-set - core-java-modules/core-java-date-operations-1 - core-java-modules/core-java-datetime-conversion - core-java-modules/core-java-datetime-string + core-java-modules/core-java-date-operations-1 + core-java-modules/core-java-datetime-conversion + core-java-modules/core-java-datetime-string core-java-modules/core-java-jpms - core-java-modules/core-java-os - core-java-modules/core-java-time-measurements + core-java-modules/core-java-os + core-java-modules/core-java-time-measurements core-java-modules/multimodulemavenproject From 400cbb845dfa11b4d762c6fdf2f223062b59e098 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 27 Oct 2020 21:59:40 -0400 Subject: [PATCH 096/590] [BAEL-4635] Tests for JPA Transient Annotation tutorial --- persistence-modules/java-jpa-3/pom.xml | 16 +++- .../ignorable/fields/HibernateConfig.java | 40 ++++++++++ .../com/baeldung/ignorable/fields/User.java | 80 +++++++++++++++++++ .../baeldung/ignorable/fields/UserDao.java | 32 ++++++++ .../ignorable/fields/TransientFieldTest.java | 79 ++++++++++++++++++ 5 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml index da18ae3046..7c02cc6c8e 100644 --- a/persistence-modules/java-jpa-3/pom.xml +++ b/persistence-modules/java-jpa-3/pom.xml @@ -27,7 +27,21 @@ h2 ${h2.version} - + + mysql + mysql-connector-java + 8.0.21 + + + com.fasterxml.jackson.core + jackson-databind + 2.11.3 + + + com.fasterxml.jackson.datatype + jackson-datatype-hibernate5 + 2.9.8 + javax.persistence diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java new file mode 100644 index 0000000000..f5608db8d7 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java @@ -0,0 +1,40 @@ +package com.baeldung.ignorable.fields; + +import java.util.Properties; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.service.ServiceRegistry; + +public class HibernateConfig { + private static SessionFactory sessionFactory; + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + try { + Configuration configuration = new Configuration(); + + Properties settings = new Properties(); + settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver"); + settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false"); + settings.put(Environment.USER, "root"); + settings.put(Environment.PASS, "password"); + settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); + settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); + configuration.setProperties(settings); + + configuration.addAnnotatedClass(User.class); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) + .build(); + + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + } catch (Exception e) { + e.printStackTrace(); + } + } + return sessionFactory; + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java new file mode 100644 index 0000000000..0789b93b75 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java @@ -0,0 +1,80 @@ +package com.baeldung.ignorable.fields; + +import java.io.Serializable; +import java.util.StringJoiner; + +import javax.persistence.*; + +@Entity +@Table(name = "Users") +public class User implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private String email; + private String password; + @Transient + private String currentDevice; + + // Needed for Hibernate mapping + public User() { + } + + public User(String email, String password, String currentDevice) { + this.email = email; + this.password = password; + this.currentDevice = currentDevice; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getCurrentDevice() { + return currentDevice; + } + + public void setCurrentDevice(String currentDevice) { + this.currentDevice = currentDevice; + } + + @Override + public String toString() { + return new StringJoiner(", ", User.class.getSimpleName() + "[", "]").add("id=" + id) + .add("email='" + email + "'") + .add("password='" + password + "'") + .add("currentDevice='" + currentDevice + "'") + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof User)) + return false; + User user = (User) o; + return email.equals(user.email); + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java new file mode 100644 index 0000000000..f923968ef4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java @@ -0,0 +1,32 @@ +package com.baeldung.ignorable.fields; + +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class UserDao { + + public void saveUser(User user) { + Transaction transaction = null; + try (Session session = HibernateConfig.getSessionFactory() + .openSession()) { + transaction = session.beginTransaction(); + session.save(user); + transaction.commit(); + } catch (Exception e) { + e.printStackTrace(); + if (transaction != null) { + transaction.rollback(); + } + } + } + + public List getUsers() { + try (Session session = HibernateConfig.getSessionFactory() + .openSession()) { + return session.createQuery("from User", User.class) + .list(); + } + } +} diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java new file mode 100644 index 0000000000..221bc9bfed --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java @@ -0,0 +1,79 @@ +package com.baeldung.ignorable.fields; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.*; +import java.util.List; +import java.util.Random; + +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; + +public class TransientFieldTest { + + private final UserDao userDao = new UserDao(); + + private final int randInt = new Random().nextInt(); + + private final User user = new User("user" + randInt + "@bar.com", "hunter2", "MacOSX"); + + @Test + public void JPA_UserWithTransientAnnotation_FieldNotPersisted() { + userDao.saveUser(user); + List allUsers = userDao.getUsers(); + User savedUser = allUsers.get(allUsers.indexOf(user)); + + assertNull(savedUser.getCurrentDevice()); + } + + @Test + public void JavaSerialization_UserWithTransientAnnotation_FieldSerialized() throws IOException, ClassNotFoundException { + + FileOutputStream fout = new FileOutputStream("test.obj"); + ObjectOutputStream out = new ObjectOutputStream(fout); + out.writeObject(user); + out.flush(); + out.close(); + + FileInputStream fin = new FileInputStream("test.obj"); + ObjectInputStream in = new ObjectInputStream(fin); + User savedUser = (User) in.readObject(); + in.close(); + + assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice()); + } + + @Test + public void JSONSerialization_UserWithTransientAnnotation_FieldSerialized() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(user); + User savedUser = objectMapper.readValue(json, User.class); + + assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice()); + } + + @Test + public void JSONSerialization_JacksonUsingHibernate5Module_FieldNotSerialized() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new Hibernate5Module()); + String json = objectMapper.writeValueAsString(user); + User savedUser = objectMapper.readValue(json, User.class); + + assertNull(savedUser.getCurrentDevice()); + } + + @Test + public void JSONSerialization_MapperPropagatesTransientMarker_FieldSerialized() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true); + String json = objectMapper.writeValueAsString(user); + User savedUser = objectMapper.readValue(json, User.class); + + assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice()); + } +} From 16b38741becfb811357ef92ea353728c0e16b0e1 Mon Sep 17 00:00:00 2001 From: Cavero Barca Date: Fri, 30 Oct 2020 17:44:33 +0100 Subject: [PATCH 097/590] Correct the artifactid and names to match with the folder following the guidelines --- docker/docker-internal-dto/pom.xml | 3 ++- .../main/java/com/baeldung/docker/{ => dto}/VariableDto.java | 2 +- docker/docker-spring-boot/pom.xml | 2 +- .../com/baeldung/docker/{ => spring}/DemoApplication.java | 2 +- .../com/baeldung/docker/{ => spring}/HelloController.java | 2 +- docker/pom.xml | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) rename docker/docker-internal-dto/src/main/java/com/baeldung/docker/{ => dto}/VariableDto.java (85%) rename docker/docker-spring-boot/src/main/java/com/baeldung/docker/{ => spring}/DemoApplication.java (88%) rename docker/docker-spring-boot/src/main/java/com/baeldung/docker/{ => spring}/HelloController.java (90%) diff --git a/docker/docker-internal-dto/pom.xml b/docker/docker-internal-dto/pom.xml index d7ba6d7373..01b92f81dc 100644 --- a/docker/docker-internal-dto/pom.xml +++ b/docker/docker-internal-dto/pom.xml @@ -5,10 +5,11 @@ 4.0.0 com.baeldung.docker - docker-spring-boot-parent + docker 0.0.1 docker-internal-dto + docker-internal-dto \ No newline at end of file diff --git a/docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java b/docker/docker-internal-dto/src/main/java/com/baeldung/docker/dto/VariableDto.java similarity index 85% rename from docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java rename to docker/docker-internal-dto/src/main/java/com/baeldung/docker/dto/VariableDto.java index 86e173e351..2de3b734ea 100644 --- a/docker/docker-internal-dto/src/main/java/com/baeldung/docker/VariableDto.java +++ b/docker/docker-internal-dto/src/main/java/com/baeldung/docker/dto/VariableDto.java @@ -1,4 +1,4 @@ -package com.baeldung.docker; +package com.baeldung.docker.dto; public class VariableDto { diff --git a/docker/docker-spring-boot/pom.xml b/docker/docker-spring-boot/pom.xml index 9524f68a5a..74bd1561cf 100644 --- a/docker/docker-spring-boot/pom.xml +++ b/docker/docker-spring-boot/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.baeldung.docker - docker-spring-boot-parent + docker 0.0.1 diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/DemoApplication.java similarity index 88% rename from docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java rename to docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/DemoApplication.java index e0c1d57e89..9210cabbb3 100644 --- a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/DemoApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.docker; +package com.baeldung.docker.spring; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/HelloController.java similarity index 90% rename from docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java rename to docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/HelloController.java index b463bb557f..430a158011 100644 --- a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/spring/HelloController.java @@ -1,4 +1,4 @@ -package com.baeldung.docker; +package com.baeldung.docker.spring; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/docker/pom.xml b/docker/pom.xml index 3668ceb0fc..f05c303938 100644 --- a/docker/pom.xml +++ b/docker/pom.xml @@ -12,9 +12,9 @@ com.baeldung.docker - docker-spring-boot-parent + docker 0.0.1 - docker-spring-boot-parent + docker Demo project showing Spring Boot and Docker pom From 964cde9dbc40517e37638098ba08a144d83f264e Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Fri, 30 Oct 2020 23:07:24 +0530 Subject: [PATCH 098/590] BAEL-3894: Added Performance Tests (#10213) --- .../apache/commons/CollectionsUnitTest.java | 73 +++++++++++++++++++ .../com/baeldung/guava/GuavaUnitTest.java | 25 +++++++ 2 files changed, 98 insertions(+) diff --git a/libraries-6/src/test/java/com/baeldung/apache/commons/CollectionsUnitTest.java b/libraries-6/src/test/java/com/baeldung/apache/commons/CollectionsUnitTest.java index aa5e09b443..3de0c64fb9 100644 --- a/libraries-6/src/test/java/com/baeldung/apache/commons/CollectionsUnitTest.java +++ b/libraries-6/src/test/java/com/baeldung/apache/commons/CollectionsUnitTest.java @@ -7,9 +7,12 @@ import static org.junit.Assert.assertFalse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import org.apache.commons.collections4.BidiMap; import org.apache.commons.collections4.MultiValuedMap; +import org.apache.commons.collections4.bidimap.DualHashBidiMap; +import org.apache.commons.collections4.bidimap.DualTreeBidiMap; import org.apache.commons.collections4.bidimap.TreeBidiMap; import org.apache.commons.collections4.map.MultiKeyMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; @@ -20,6 +23,7 @@ public class CollectionsUnitTest { private final static MultiValuedMap groceryCart = new ArrayListValuedHashMap<>(); private final static MultiKeyMap days = new MultiKeyMap(); private final static MultiKeyMap cityCoordinates = new MultiKeyMap(); + private long start; static { daysOfWeek.put(1, "Monday"); @@ -106,4 +110,73 @@ public class CollectionsUnitTest { } + @Test + public void givenTreeBidiMap_whenHundredThousandKeys_thenPerformanceNoted() { + System.out.println("**TreeBidiMap**"); + BidiMap map = new TreeBidiMap<>(); + start = System.nanoTime(); + for (int i = 0; i < 100000; i++) { + Integer key = new Integer(i); + Integer value = new Integer(i + 1); + map.put(key, value); + } + System.out.println("Insertion time:" + TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer value = (Integer) map.get(new Integer(500)); + System.out.println("Value:" + value); + System.out.println("Fetch time key:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer key = (Integer) map.getKey(new Integer(501)); + System.out.println("Key:" + key); + System.out.println("Fetch time value:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + } + + @Test + public void givenDualTreeBidiMap_whenHundredThousandKeys_thenPerformanceNoted() { + System.out.println("**DualTreeBidiMap**"); + BidiMap map = new DualTreeBidiMap<>(); + start = System.nanoTime(); + for (int i = 0; i < 100000; i++) { + Integer key = new Integer(i); + Integer value = new Integer(i + 1); + map.put(key, value); + } + System.out.println("Insertion time:" + TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer value = (Integer) map.get(new Integer(500)); + System.out.println("Value:" + value); + System.out.println("Fetch time key:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer key = (Integer) map.getKey(new Integer(501)); + System.out.println("Key:" + key); + System.out.println("Fetch time value:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + } + + @Test + public void givenDualHashBidiMap_whenHundredThousandKeys_thenPerformanceNoted() { + System.out.println("**DualHashBidiMap**"); + BidiMap map = new DualHashBidiMap<>(); + start = System.nanoTime(); + for (int i = 0; i < 100000; i++) { + Integer key = new Integer(i); + Integer value = new Integer(i + 1); + map.put(key, value); + } + System.out.println("Insertion time:" + TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer value = (Integer) map.get(new Integer(500)); + System.out.println("Value:" + value); + System.out.println("Fetch time key:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer key = (Integer) map.getKey(new Integer(501)); + System.out.println("Key:" + key); + System.out.println("Fetch time value:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + } + } \ No newline at end of file diff --git a/libraries-6/src/test/java/com/baeldung/guava/GuavaUnitTest.java b/libraries-6/src/test/java/com/baeldung/guava/GuavaUnitTest.java index 13a676e709..c0501f761e 100644 --- a/libraries-6/src/test/java/com/baeldung/guava/GuavaUnitTest.java +++ b/libraries-6/src/test/java/com/baeldung/guava/GuavaUnitTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -21,6 +22,7 @@ public class GuavaUnitTest { private final static Multimap groceryCart = ArrayListMultimap.create(); private final static Table cityCoordinates = HashBasedTable.create(); private final static Table movies = HashBasedTable.create(); + private long start; static { daysOfWeek.put(1, "Monday"); @@ -115,4 +117,27 @@ public class GuavaUnitTest { assertTrue(movies.containsValue("Speed")); } + + @Test + public void givenHashBiMap_whenHundredThousandKeys_thenPerformanceNoted() { + BiMap map = HashBiMap.create(); + start = System.nanoTime(); + for (int i = 0; i < 100000; i++) { + Integer key = new Integer(i); + Integer value = new Integer(i + 1); + map.put(key, value); + } + System.out.println("Insertion time:" + TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer value = map.get(new Integer(500)); + System.out.println("Value:" + value); + System.out.println("Fetch time key:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + + start = System.nanoTime(); + Integer key = map.inverse() + .get(new Integer(501)); + System.out.println("Key:" + key); + System.out.println("Fetch time value:" + TimeUnit.MICROSECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); + } } \ No newline at end of file From c71fb2ce9e72d24676974259709491ddfff68e95 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 31 Oct 2020 12:07:35 +0200 Subject: [PATCH 099/590] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index b08a93f23e..88750cf654 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -**UPDATE**: The price of "Learn Spring Security OAuth" will permanently change on the 11th of December, along with the upcoming OAuth2 material: http://bit.ly/github-lss - The Courses ============================== From d4a8a336043cee35266c3f81fe4bf4214f5304cd Mon Sep 17 00:00:00 2001 From: GilvanOrnelas Date: Sun, 1 Nov 2020 11:46:15 -0300 Subject: [PATCH 100/590] Storing files indexed by a database (#10174) Creating the FileLocationService to link the FileSystemRepository to the ImageDbRepository. Removing test order Changing to BDDMockito Changing Long wrapper for @id. Changing the test names to given-when-then pattern Co-authored-by: Gilvan Ornelas Fernandes Filho --- .../db/indexing/FileLocationService.java | 31 ++++++++ .../indexing/FileSystemImageController.java | 30 ++++++++ .../db/indexing/FileSystemRepository.java | 36 +++++++++ .../java/com/baeldung/db/indexing/Image.java | 62 +++++++++++++++ .../db/indexing/ImageArchiveApplication.java | 13 ++++ .../baeldung/db/indexing/ImageController.java | 46 +++++++++++ .../db/indexing/ImageDbRepository.java | 9 +++ .../FileSystemImageIntegrationTest.java | 69 +++++++++++++++++ .../db/indexing/ImageIntegrationTest.java | 72 ++++++++++++++++++ .../src/test/resources/baeldung.jpeg | Bin 0 -> 9291 bytes 10 files changed, 368 insertions(+) create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileLocationService.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemImageController.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemRepository.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageArchiveApplication.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageController.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageDbRepository.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java create mode 100644 persistence-modules/spring-boot-persistence-2/src/test/resources/baeldung.jpeg diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileLocationService.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileLocationService.java new file mode 100644 index 0000000000..6b2f33e885 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileLocationService.java @@ -0,0 +1,31 @@ +package com.baeldung.db.indexing; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +@Service +class FileLocationService { + + @Autowired + FileSystemRepository fileSystemRepository; + @Autowired + ImageDbRepository imageDbRepository; + + Long save(byte[] bytes, String imageName) throws Exception { + String location = fileSystemRepository.save(bytes, imageName); + + return imageDbRepository.save(new Image(imageName, location)) + .getId(); + } + + FileSystemResource find(Long imageId) { + Image image = imageDbRepository.findById(imageId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); + + return fileSystemRepository.findInFileSystem(image.getLocation()); + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemImageController.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemImageController.java new file mode 100644 index 0000000000..09e33bb943 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemImageController.java @@ -0,0 +1,30 @@ +package com.baeldung.db.indexing; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequestMapping("file-system") +class FileSystemImageController { + + @Autowired + FileLocationService fileLocationService; + + @PostMapping("/image") + Long uploadImage(@RequestParam MultipartFile image) throws Exception { + return fileLocationService.save(image.getBytes(), image.getOriginalFilename()); + } + + @GetMapping(value = "/image/{imageId}", produces = MediaType.IMAGE_JPEG_VALUE) + FileSystemResource downloadImage(@PathVariable Long imageId) throws Exception { + return fileLocationService.find(imageId); + } +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemRepository.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemRepository.java new file mode 100644 index 0000000000..bc6bdecfed --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/FileSystemRepository.java @@ -0,0 +1,36 @@ +package com.baeldung.db.indexing; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Date; + +import org.springframework.core.io.FileSystemResource; +import org.springframework.stereotype.Repository; + +@Repository +class FileSystemRepository { + + String RESOURCES_DIR = FileSystemRepository.class.getResource("/") + .getPath(); + + String save(byte[] content, String imageName) throws Exception { + Path newFile = Paths.get(RESOURCES_DIR + new Date().getTime() + "-" + imageName); + Files.createDirectories(newFile.getParent()); + + Files.write(newFile, content); + + return newFile.toAbsolutePath() + .toString(); + } + + FileSystemResource findInFileSystem(String location) { + try { + return new FileSystemResource(Paths.get(location)); + } catch (Exception e) { + // Handle access or file not found problems. + throw new RuntimeException(); + } + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java new file mode 100644 index 0000000000..5348788c12 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java @@ -0,0 +1,62 @@ +package com.baeldung.db.indexing; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; + +@Entity +class Image { + + @Id + @GeneratedValue + Long id; + + String name; + + String location; + + @Lob + byte[] content; + + public Image() { + } + + public Image(String name, String location) { + this.name = name; + this.location = location; + } + + public byte[] getContent() { + return content; + } + + public void setContent(byte[] content) { + this.content = content; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageArchiveApplication.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageArchiveApplication.java new file mode 100644 index 0000000000..02d2db32b3 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageArchiveApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.db.indexing; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ImageArchiveApplication { + + public static void main(String[] args) { + SpringApplication.run(ImageArchiveApplication.class, args); + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageController.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageController.java new file mode 100644 index 0000000000..1b2378a51f --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageController.java @@ -0,0 +1,46 @@ +package com.baeldung.db.indexing; + +import java.io.IOException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ResponseStatusException; + +import lombok.extern.slf4j.Slf4j; + +@RestController +@Slf4j +class ImageController { + + @Autowired + ImageDbRepository imageDbRepository; + + @PostMapping("/image") + long uploadImage(@RequestParam MultipartFile multipartImage) throws IOException { + Image dbImage = new Image(); + dbImage.setName(multipartImage.getOriginalFilename()); + dbImage.setContent(multipartImage.getBytes()); + + return imageDbRepository.save(dbImage) + .getId(); + } + + @GetMapping(value = "/image/{imageId}", produces = MediaType.IMAGE_JPEG_VALUE) + Resource downloadImage(@PathVariable Long imageId) { + byte[] image = imageDbRepository.findById(imageId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)) + .getContent(); + + return new ByteArrayResource(image); + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageDbRepository.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageDbRepository.java new file mode 100644 index 0000000000..eb33f14dae --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/ImageDbRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.db.indexing; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +interface ImageDbRepository extends JpaRepository { + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java new file mode 100644 index 0000000000..3082f16a78 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java @@ -0,0 +1,69 @@ +package com.baeldung.db.indexing; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.InputStream; +import java.nio.file.Paths; + +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.boot.test.mock.mockito.MockBean; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +@SpringBootTest(classes = ImageArchiveApplication.class) +@AutoConfigureMockMvc +class FileSystemImageIntegrationTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + FileLocationService fileLocationService; + + @Test + void givenJpegImage_whenUploadIt_thenReturnItsId() throws Exception { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + InputStream image = classLoader.getResourceAsStream("baeldung.jpeg"); + + MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/file-system/image") + .file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image)); + + MvcResult result = mockMvc.perform(multipartRequest) + .andExpect(status().isOk()) + .andReturn(); + + assertThat(result.getResponse() + .getContentAsString()) + .isEqualTo("1"); + } + + @Test + void givenBaeldungImage_whenDownloadIt_thenReturnTheImage() throws Exception { + given(fileLocationService.find(1L)) + .willReturn(baeldungJpegResource()); + + mockMvc.perform(MockMvcRequestBuilders + .get("/file-system/image/1") + .contentType(MediaType.IMAGE_JPEG_VALUE)) + .andExpect(status().isOk()); + } + + private FileSystemResource baeldungJpegResource() { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + String imagePath = classLoader.getResource("baeldung.jpeg") + .getFile(); + + return new FileSystemResource(Paths.get(imagePath)); + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java new file mode 100644 index 0000000000..f7d4ecf129 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java @@ -0,0 +1,72 @@ +package com.baeldung.db.indexing; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; + +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.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +@SpringBootTest(classes = ImageArchiveApplication.class) +@AutoConfigureMockMvc +class ImageIntegrationTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + ImageDbRepository imageRepository; + + @Test + void givenBaeldungJpegImage_whenUploadIt_thenReturnItsId() throws Exception { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + InputStream image = classLoader.getResourceAsStream("baeldung.jpeg"); + + MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/image") + .file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image)); + + MvcResult result = mockMvc.perform(multipartRequest) + .andExpect(status().isOk()) + .andReturn(); + + assertThat(result.getResponse() + .getContentAsString()) + .isEqualTo("1"); + } + + @Test + void givenExistingImage_whenDownloadIt_thenReturnHttpStatusOk() throws Exception { + given(imageRepository.findById(1L)) + .willReturn(Optional.of(baeldungImage())); + + mockMvc.perform(MockMvcRequestBuilders + .get("/image/1") + .contentType(MediaType.IMAGE_JPEG_VALUE)) + .andExpect(status().isOk()); + } + + private Image baeldungImage() throws IOException { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + + Image mockImage = new Image(); + mockImage.setContent(Files.readAllBytes(Paths.get(classLoader.getResource("baeldung.jpeg") + .getFile()))); + return mockImage; + } + +} diff --git a/persistence-modules/spring-boot-persistence-2/src/test/resources/baeldung.jpeg b/persistence-modules/spring-boot-persistence-2/src/test/resources/baeldung.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..2654748a27c61c03384e9c3597e40bf7380b5296 GIT binary patch literal 9291 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 Date: Mon, 2 Nov 2020 10:31:44 +0200 Subject: [PATCH 101/590] The Value of 0xFF Number and Its Uses With & Operation in Java Article by Abdallah Sawan --- .../com/baeldung/number_0xff/Number0xffUnitTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java index 95a9349b49..b0feaf8628 100644 --- a/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/number_0xff/Number0xffUnitTest.java @@ -9,41 +9,41 @@ public class Number0xffUnitTest { public void test0xFFAssignedToInteger() { int x = 0xff; int expectedValue = 255; - assertEquals(x, expectedValue); + assertEquals(expectedValue, x); } @Test public void test0xFFAssignedToByte() { byte y = (byte) 0xff; int expectedValue = -1; - assertEquals(y, expectedValue); + assertEquals(expectedValue, y); } @Test public void givenColor_whenGetRedColor_thenExtractRedColor() { int rgba = 272214023; int expectedValue = 16; - assertEquals(Number0xff.getRedColor(rgba), expectedValue); + assertEquals(expectedValue, Number0xff.getRedColor(rgba)); } @Test public void givenColor_whenGetGreenColor_thenExtractGreenColor() { int rgba = 272214023; int expectedValue = 57; - assertEquals(Number0xff.getGreenColor(rgba), expectedValue); + assertEquals(expectedValue, Number0xff.getGreenColor(rgba)); } @Test public void givenColor_whenGetBlueColor_thenExtractBlueColor() { int rgba = 272214023; int expectedValue = 168; - assertEquals(Number0xff.getBlueColor(rgba), expectedValue); + assertEquals(expectedValue, Number0xff.getBlueColor(rgba)); } @Test public void givenColor_whenGetAlfa_thenExtractAlfa() { int rgba = 272214023; int expectedValue = 7; - assertEquals(Number0xff.getAlfa(rgba), expectedValue); + assertEquals(expectedValue, Number0xff.getAlfa(rgba)); } } From 3686fa1cfb0045a02f5412ba59a9374e8db934d1 Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 2 Nov 2020 22:05:46 -0500 Subject: [PATCH 102/590] [BAEL-4635] Fixed tests and formatted per feedback --- .../ignorable/fields/HibernateConfig.java | 31 +++++++++---------- .../com/baeldung/ignorable/fields/User.java | 8 ++--- .../baeldung/ignorable/fields/UserDao.java | 10 ++---- ...dTest.java => TransientFieldUnitTest.java} | 12 +++---- 4 files changed, 27 insertions(+), 34 deletions(-) rename persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/{TransientFieldTest.java => TransientFieldUnitTest.java} (77%) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java index f5608db8d7..9285c23dfa 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java @@ -13,27 +13,24 @@ public class HibernateConfig { public static SessionFactory getSessionFactory() { if (sessionFactory == null) { - try { - Configuration configuration = new Configuration(); + Configuration configuration = new Configuration(); - Properties settings = new Properties(); - settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver"); - settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false"); - settings.put(Environment.USER, "root"); - settings.put(Environment.PASS, "password"); - settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); - settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); - configuration.setProperties(settings); + Properties settings = new Properties(); + settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver"); + settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false"); + settings.put(Environment.USER, "root"); + settings.put(Environment.PASS, "password"); + settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); + settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); + configuration.setProperties(settings); - configuration.addAnnotatedClass(User.class); + configuration.addAnnotatedClass(User.class); - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) - .build(); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()) + .build(); - sessionFactory = configuration.buildSessionFactory(serviceRegistry); - } catch (Exception e) { - e.printStackTrace(); - } + sessionFactory = configuration.buildSessionFactory(serviceRegistry); } return sessionFactory; } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java index 0789b93b75..8d1812605d 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/User.java @@ -62,10 +62,10 @@ public class User implements Serializable { @Override public String toString() { return new StringJoiner(", ", User.class.getSimpleName() + "[", "]").add("id=" + id) - .add("email='" + email + "'") - .add("password='" + password + "'") - .add("currentDevice='" + currentDevice + "'") - .toString(); + .add("email='" + email + "'") + .add("password='" + password + "'") + .add("currentDevice='" + currentDevice + "'") + .toString(); } @Override diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java index f923968ef4..45e491e42e 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/UserDao.java @@ -9,13 +9,11 @@ public class UserDao { public void saveUser(User user) { Transaction transaction = null; - try (Session session = HibernateConfig.getSessionFactory() - .openSession()) { + try (Session session = HibernateConfig.getSessionFactory().openSession()) { transaction = session.beginTransaction(); session.save(user); transaction.commit(); } catch (Exception e) { - e.printStackTrace(); if (transaction != null) { transaction.rollback(); } @@ -23,10 +21,8 @@ public class UserDao { } public List getUsers() { - try (Session session = HibernateConfig.getSessionFactory() - .openSession()) { - return session.createQuery("from User", User.class) - .list(); + try (Session session = HibernateConfig.getSessionFactory().openSession()) { + return session.createQuery("from User", User.class).list(); } } } diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java similarity index 77% rename from persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java rename to persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java index 221bc9bfed..114a4cca4c 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; -public class TransientFieldTest { +public class TransientFieldUnitTest { private final UserDao userDao = new UserDao(); @@ -23,7 +23,7 @@ public class TransientFieldTest { private final User user = new User("user" + randInt + "@bar.com", "hunter2", "MacOSX"); @Test - public void JPA_UserWithTransientAnnotation_FieldNotPersisted() { + public void givenFieldWithTransientAnnotation_whenSavingViaJPA_thenFieldIgnored() { userDao.saveUser(user); List allUsers = userDao.getUsers(); User savedUser = allUsers.get(allUsers.indexOf(user)); @@ -32,7 +32,7 @@ public class TransientFieldTest { } @Test - public void JavaSerialization_UserWithTransientAnnotation_FieldSerialized() throws IOException, ClassNotFoundException { + public void givenFieldWithTransientAnnotation_whenSerializingObject_thenFieldSerialized() throws IOException, ClassNotFoundException { FileOutputStream fout = new FileOutputStream("test.obj"); ObjectOutputStream out = new ObjectOutputStream(fout); @@ -49,7 +49,7 @@ public class TransientFieldTest { } @Test - public void JSONSerialization_UserWithTransientAnnotation_FieldSerialized() throws JsonProcessingException { + public void givenFieldWithTransientAnnotation_whenSerializingToJSON_thenFieldSerialized() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(user); User savedUser = objectMapper.readValue(json, User.class); @@ -58,7 +58,7 @@ public class TransientFieldTest { } @Test - public void JSONSerialization_JacksonUsingHibernate5Module_FieldNotSerialized() throws JsonProcessingException { + public void givenJacksonHibernate5Module_whenSerializingTransientAnnotation_thenFieldIgnored() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new Hibernate5Module()); String json = objectMapper.writeValueAsString(user); @@ -68,7 +68,7 @@ public class TransientFieldTest { } @Test - public void JSONSerialization_MapperPropagatesTransientMarker_FieldSerialized() throws JsonProcessingException { + public void givenPropagateTransientFieldFlag_whenSerializingTransientAnnotation_thenFieldSerialized() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true); String json = objectMapper.writeValueAsString(user); From 8c26df1709f209f39d7c3b81441cf01747b12532 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 3 Nov 2020 09:33:24 +0100 Subject: [PATCH 103/590] BAEL-4682: Add boolean example to the YAML (#10227) --- .../main/java/com/baeldung/yaml/MyApplication.java | 7 +++---- .../src/main/java/com/baeldung/yaml/YAMLConfig.java | 11 ++++++++++- .../src/main/resources/application.yml | 3 +++ .../com/baeldung/yaml/YAMLDevIntegrationTest.java | 1 + .../java/com/baeldung/yaml/YAMLIntegrationTest.java | 2 ++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java index f3cfff57b7..27195911bd 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java @@ -5,15 +5,13 @@ */ package com.baeldung.yaml; -import java.util.Collections; +import com.baeldung.yaml.YAMLConfig.Idm; +import com.baeldung.yaml.YAMLConfig.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.yaml.YAMLConfig.Idm; -import com.baeldung.yaml.YAMLConfig.Service; - @SpringBootApplication public class MyApplication implements CommandLineRunner { @@ -28,6 +26,7 @@ public class MyApplication implements CommandLineRunner { public void run(String... args) throws Exception { System.out.println("using environment:" + myConfig.getEnvironment()); System.out.println("name:" + myConfig.getName()); + System.out.println("enabled:" + myConfig.isEnabled()); System.out.println("servers:" + myConfig.getServers()); if ("testing".equalsIgnoreCase(myConfig.getEnvironment())) { diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java index 83c083734c..4099ded1aa 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java @@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration; public class YAMLConfig { private String name; private String environment; + private boolean enabled; private List servers = new ArrayList(); private List external = new ArrayList(); private Map map = new HashMap(); @@ -43,7 +44,15 @@ public class YAMLConfig { public void setEnvironment(String environment) { this.environment = environment; } - + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + public Component getComponent() { return component; } diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml index 30e64f9d35..fc9bb42a95 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml @@ -9,6 +9,7 @@ spring: profiles: test name: test-YAML environment: testing +enabled: false servers: - www.abc.test.com - www.xyz.test.com @@ -39,6 +40,7 @@ spring: profiles: prod name: prod-YAML environment: production +enabled: true servers: - www.abc.com - www.xyz.com @@ -49,6 +51,7 @@ spring: profiles: dev name: ${DEV_NAME:dev-YAML} environment: development +enabled: true servers: - www.abc.dev.com - www.xyz.dev.com diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLDevIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLDevIntegrationTest.java index 8dfc4c2208..5e6ebf6d81 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLDevIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLDevIntegrationTest.java @@ -21,5 +21,6 @@ class YAMLDevIntegrationTest { void whenProfileTest_thenNameTesting() { assertTrue("development".equalsIgnoreCase(config.getEnvironment())); assertTrue("dev-YAML".equalsIgnoreCase(config.getName())); + assertTrue(config.isEnabled()); } } diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java index 19412c91f5..278307504b 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java @@ -1,5 +1,6 @@ package com.baeldung.yaml; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Test; @@ -22,5 +23,6 @@ class YAMLIntegrationTest { assertTrue("testing".equalsIgnoreCase(config.getEnvironment())); assertTrue("test-YAML".equalsIgnoreCase(config.getName())); assertTrue("myurl".equalsIgnoreCase(config.getComponent().getIdm().getUrl())); + assertFalse(config.isEnabled()); } } From 819669c97c61a04722558295c512dad38974e8d9 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 3 Nov 2020 14:07:23 +0530 Subject: [PATCH 104/590] BAEL-4399: Added changes as per review comment --- .../nosuchfielderror/Dependent.java | 4 ++-- .../nosuchfielderror/NoSuchFieldError.java | 21 ---------------- .../NoSuchFieldErrorExample.java | 8 +++++++ .../NoSuchFieldErrorExampleUnitTest.java | 15 ++++++++++++ .../NoSuchFieldErrorTest.java | 24 ------------------- 5 files changed, 25 insertions(+), 47 deletions(-) delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java index e475b7dcf9..d838eafdd9 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java @@ -1,6 +1,6 @@ package com.baeldung.exceptions.nosuchfielderror; public class Dependent { - // This needed to be commented post compilation of NoSuchFielDError and Compile - public static String message = "Hello Baeldung!!"; + // This needed to be commented post compilation of NoSuchFielDError and Compile + public static String message = "Hello Baeldung!!"; } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java deleted file mode 100644 index 4939adac31..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldError.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.exceptions.nosuchfielderror; - -import java.lang.reflect.Field; - -public class NoSuchFieldError { - // String message = "Hello Baeldung!!!"; - - public static String getMessage() throws ClassNotFoundException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException { - NoSuchFieldError clss = new NoSuchFieldError(); - Class aClass = Class.forName(clss.getClass().getName()); - Field field = aClass.getDeclaredField("message"); - field.setAccessible(true); - String msgStr = (String) field.get(clss); - return msgStr; - } - - public static String getDependentMessage() { - return Dependent.message; - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java new file mode 100644 index 0000000000..727f10581d --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java @@ -0,0 +1,8 @@ +package com.baeldung.exceptions.nosuchfielderror; + +public class NoSuchFieldErrorExample { + + public static String getDependentMessage() { + return Dependent.message; + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java new file mode 100644 index 0000000000..8f2dc45aa0 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptions.nosuchfielderror; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class NoSuchFieldErrorExampleUnitTest { + + @Test + public void whenDependentMessage_returnMessage() { + String dependentMessage = NoSuchFieldErrorExample.getDependentMessage(); + assertTrue("Hello Baeldung".equals(dependentMessage)); + } + +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java deleted file mode 100644 index dd7947b207..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.exceptions.nosuchfielderror; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class NoSuchFieldErrorTest { - - @Test(expected = NoSuchFieldException.class) - public void whenFieldNotFound_thenThrowNoSuchFieldException() throws Exception { - NoSuchFieldError.getMessage(); - } - - @Test(expected = NoSuchFieldException.class) - public void whenDependentFieldNotFound_thenThrowNoSuchFieldException() { - NoSuchFieldError.getDependentMessage(); - } - - @Test - public void whenDependentFieldNotFound_returnMessage() { - String dependentMessage = NoSuchFieldError.getDependentMessage(); - assertTrue("Hello Baeldung".equals(dependentMessage)); - } -} From 080dd2f226247ecc3458a9cc95388cf8537f4561 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 3 Nov 2020 14:16:44 +0530 Subject: [PATCH 105/590] BAEL-4399: Removed unwanted changes --- .../main/webapp/WEB-INF/view/react/package.json | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json index 26d5a3b0cf..64c116ec72 100644 --- a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json +++ b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json @@ -16,17 +16,5 @@ }, "devDependencies": { "eslint-plugin-react": "^7.9.1" - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] } -} +} \ No newline at end of file From be3614c157a4532be1fd0d270a8ff248cbc12aec Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 3 Nov 2020 19:13:59 +0530 Subject: [PATCH 106/590] Corrected the file names --- .../nosuchfielderror/FieldErrorExample.java | 16 ++++++++++++++++ .../NoSuchFieldErrorExample.java | 8 -------- .../FieldErrorExampleUnitTest.java | 15 +++++++++++++++ .../NoSuchFieldErrorExampleUnitTest.java | 15 --------------- 4 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java new file mode 100644 index 0000000000..71099201b8 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java @@ -0,0 +1,16 @@ +package com.baeldung.exceptions.nosuchfielderror; + +public class FieldErrorExample { + + public static void main(String... args) { + fetchAndPrint(); + } + + public static String getDependentMessage() { + return Dependent.message; + } + + public static void fetchAndPrint() { + System.out.println(getDependentMessage()); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java deleted file mode 100644 index 727f10581d..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExample.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.exceptions.nosuchfielderror; - -public class NoSuchFieldErrorExample { - - public static String getDependentMessage() { - return Dependent.message; - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java new file mode 100644 index 0000000000..d9ffd294e6 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptions.nosuchfielderror; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class FieldErrorExampleUnitTest { + + @Test + public void whenDependentMessage_returnMessage() { + String dependentMessage = FieldErrorExample.getDependentMessage(); + assertTrue("Hello Baeldung!!".equals(dependentMessage)); + } + +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java deleted file mode 100644 index 8f2dc45aa0..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/NoSuchFieldErrorExampleUnitTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.exceptions.nosuchfielderror; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class NoSuchFieldErrorExampleUnitTest { - - @Test - public void whenDependentMessage_returnMessage() { - String dependentMessage = NoSuchFieldErrorExample.getDependentMessage(); - assertTrue("Hello Baeldung".equals(dependentMessage)); - } - -} From 2ff415af7bc9ff140d07b7289c2cdf1af3249b88 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 3 Nov 2020 19:23:18 +0530 Subject: [PATCH 107/590] BAEL-4399: Removed the unwanted code --- .../src/main/webapp/WEB-INF/view/react/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json index 64c116ec72..859d9a6f83 100644 --- a/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json +++ b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json @@ -17,4 +17,4 @@ "devDependencies": { "eslint-plugin-react": "^7.9.1" } -} \ No newline at end of file +} From 3bea743e5b127c6c74bbd828b023c8f9541f55e7 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 3 Nov 2020 19:25:25 +0530 Subject: [PATCH 108/590] BAEL-4399: Removed unwanted space --- .../exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java index d9ffd294e6..5b18b92079 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java @@ -11,5 +11,4 @@ public class FieldErrorExampleUnitTest { String dependentMessage = FieldErrorExample.getDependentMessage(); assertTrue("Hello Baeldung!!".equals(dependentMessage)); } - } From a0828bf3d16ec1678fc6b8383f3546ee27859fc9 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 3 Nov 2020 19:07:21 +0100 Subject: [PATCH 109/590] BAEL-3704: Add missing code samples (#10226) --- .../ConfigurationScanDemoApplication.java | 14 ++++++++++++++ .../EnableConfigurationDemoApplication.java | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigurationScanDemoApplication.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/EnableConfigurationDemoApplication.java diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigurationScanDemoApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigurationScanDemoApplication.java new file mode 100644 index 0000000000..b2339b9980 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigurationScanDemoApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.configurationproperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; + +@SpringBootApplication +@ConfigurationPropertiesScan("com.baeldung.configurationproperties") +public class ConfigurationScanDemoApplication{ + + public static void main(String[] args) { + SpringApplication.run(ConfigurationScanDemoApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/EnableConfigurationDemoApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/EnableConfigurationDemoApplication.java new file mode 100644 index 0000000000..69b8c2802b --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/EnableConfigurationDemoApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.configurationproperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@SpringBootApplication +@EnableConfigurationProperties(ConfigProperties.class) +public class EnableConfigurationDemoApplication { + public static void main(String[] args) { + SpringApplication.run(EnableConfigurationDemoApplication.class, args); + } +} From f40ed2cef50926ebc7c5b13413a84d1238c8a4b8 Mon Sep 17 00:00:00 2001 From: Harihar Das Date: Tue, 3 Nov 2020 19:13:36 +0100 Subject: [PATCH 110/590] Channels examples (#10225) Co-authored-by: Harihar Das --- .../com/baeldung/channles/BufferedChannel.kt | 29 +++++++++++ .../com/baeldung/channles/ConflatedChannel.kt | 27 ++++++++++ .../com/baeldung/channles/PizzaPipeline.kt | 52 +++++++++++++++++++ .../com/baeldung/channles/ProducerConsumer.kt | 22 ++++++++ .../baeldung/channles/RendezvousChannel.kt | 26 ++++++++++ .../channles/SeveralProducersOneConsumer.kt | 36 +++++++++++++ .../SingleProducerSeveralConsumers.kt | 31 +++++++++++ .../com/baeldung/channles/TickerChannel.kt | 24 +++++++++ .../com/baeldung/channles/UnlimitedChannel.kt | 28 ++++++++++ .../kotlin/com/baeldung/channles/logger.kt | 8 +++ .../com/baeldung/channels/ChannelsTest.kt | 29 +++++++++++ 11 files changed, 312 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt create mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt new file mode 100644 index 0000000000..6cfaf5b496 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt @@ -0,0 +1,29 @@ +package com.baeldung.channles + +import kotlinx.coroutines.cancelChildren +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + val basket = Channel(1) + + launch { // coroutine1 + val fruits = listOf("Apple", "Orange", "Banana") + for (fruit in fruits) { + println("coroutine1: Sending $fruit") + basket.send(fruit) + } + } + + launch { // coroutine2 + repeat(3) { + delay(100) + println("coroutine2: Received ${basket.receive()}") + } + } + + delay(2000) + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt new file mode 100644 index 0000000000..63b0b967c1 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt @@ -0,0 +1,27 @@ +package com.baeldung.channles + +import kotlinx.coroutines.cancelChildren +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.Channel.Factory.CONFLATED +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + val basket = Channel(CONFLATED) + + launch { // coroutine1 + val fruits = listOf("Apple", "Orange", "Banana") + for (fruit in fruits) { + println("coroutine1: Sending $fruit") + basket.send(fruit) + } + } + + launch { // coroutine2 + println("coroutine2: Received ${basket.receive()}") + } + + delay(2000) + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt new file mode 100644 index 0000000000..ff4dcb2d32 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt @@ -0,0 +1,52 @@ +package com.baeldung.channles + +import com.baeldung.channles.OrderStatus.* +import kotlinx.coroutines.* +import kotlinx.coroutines.channels.ReceiveChannel +import kotlinx.coroutines.channels.produce + +enum class OrderStatus { ORDERED, BAKED, TOPPED, SERVED } + +data class PizzaOrder(val orderNumber: Int, val orderStatus: OrderStatus = ORDERED) + +@ExperimentalCoroutinesApi +fun CoroutineScope.baking(orders: ReceiveChannel) = produce { + for (order in orders) { + delay(200) + println("Baking ${order.orderNumber}") + send(order.copy(orderStatus = BAKED)) + } +} + +@ExperimentalCoroutinesApi +fun CoroutineScope.topping(orders: ReceiveChannel) = produce { + for (order in orders) { + delay(50) + println("Topping ${order.orderNumber}") + send(order.copy(orderStatus = TOPPED)) + } +} + +@ExperimentalCoroutinesApi +fun CoroutineScope.produceOrders(count: Int) = produce { + repeat(count) { + delay(50) + send(PizzaOrder(orderNumber = it + 1)) + } +} + +@ObsoleteCoroutinesApi +@ExperimentalCoroutinesApi +fun main() = runBlocking { + val orders = produceOrders(3) + + val readyOrders = topping(baking(orders)) + + for (order in readyOrders) { + println("Serving ${order.orderNumber}") + } + + delay(3000) + println("End!") + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt new file mode 100644 index 0000000000..50687b909a --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt @@ -0,0 +1,22 @@ +package com.baeldung.channles + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.channels.ReceiveChannel +import kotlinx.coroutines.channels.produce +import kotlinx.coroutines.runBlocking + +@ExperimentalCoroutinesApi +fun CoroutineScope.produceFruits(): ReceiveChannel = produce { + val fruits = listOf("Apple", "Orange", "Apple") + for (fruit in fruits) send(fruit) +} + +@ExperimentalCoroutinesApi +fun main() = runBlocking { + val fruitChannel = produceFruits() + for (fruit in fruitChannel) { + println(fruit) + } + println("End!") +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt new file mode 100644 index 0000000000..e046e86e29 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt @@ -0,0 +1,26 @@ +package com.baeldung.channles + +import kotlinx.coroutines.* +import kotlinx.coroutines.channels.Channel + +fun main() = runBlocking { + val basket = Channel() + + launch { // coroutine1 + val fruits = listOf("Apple", "Orange", "Banana") + for (fruit in fruits) { + println("coroutine1: Sending $fruit") + basket.send(fruit) + } + } + + launch { // coroutine2 + repeat(3) { + delay(100) + println("coroutine2: Received ${basket.receive()}") + } + } + + delay(2000) + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt new file mode 100644 index 0000000000..fd2c046f97 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt @@ -0,0 +1,36 @@ +package com.baeldung.channles + +import kotlinx.coroutines.cancelChildren +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.SendChannel +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +suspend fun fetchYoutubeVideos(channel: SendChannel) { + val videos = listOf("cat video", "food video") + for (video in videos) { + delay(100) + channel.send(video) + } +} + +suspend fun fetchTweets(channel: SendChannel) { + val tweets = listOf("tweet: Earth is round", "tweet: Coroutines and channels are cool") + for (tweet in tweets) { + delay(100) + channel.send(tweet) + } +} + +fun main() = runBlocking { + val aggregate = Channel() + launch { fetchYoutubeVideos(aggregate) } + launch { fetchTweets(aggregate) } + + repeat(4) { + println(aggregate.receive()) + } + + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt new file mode 100644 index 0000000000..bff1609b35 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt @@ -0,0 +1,31 @@ +package com.baeldung.channles + +import kotlinx.coroutines.* +import kotlinx.coroutines.channels.ReceiveChannel +import kotlinx.coroutines.channels.produce + +@ExperimentalCoroutinesApi +fun CoroutineScope.producePizzaOrders(): ReceiveChannel = produce { + var x = 1 + while (true) { + send("Pizza Order No. ${x++}") + delay(100) + } +} + +fun CoroutineScope.pizzaOrderProcessor(id: Int, orders: ReceiveChannel) = launch { + for (order in orders) { + println("Processor #$id is processing $order") + } +} + +@ExperimentalCoroutinesApi +fun main() = runBlocking { + val pizzaOrders = producePizzaOrders() + repeat(3) { + pizzaOrderProcessor(it + 1, pizzaOrders) + } + + delay(1000) + pizzaOrders.cancel() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt new file mode 100644 index 0000000000..febcbd1534 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt @@ -0,0 +1,24 @@ +package com.baeldung.channles + +import kotlinx.coroutines.channels.ticker +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import java.time.Duration +import kotlin.random.Random + +fun stockPrice(stock: String): Double { + log("Fetching stock price of $stock") + return Random.nextDouble(2.0, 3.0) +} + +fun main() = runBlocking { + val tickerChannel = ticker(Duration.ofSeconds(5).toMillis()) + + repeat(3) { + tickerChannel.receive() + log(stockPrice("TESLA")) + } + + delay(Duration.ofSeconds(11).toMillis()) + tickerChannel.cancel() +} diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt new file mode 100644 index 0000000000..9b01bcee54 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt @@ -0,0 +1,28 @@ +package com.baeldung.channles + +import kotlinx.coroutines.cancelChildren +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + val channel = Channel(UNLIMITED) + + launch { // coroutine1 + repeat(100) { + println("coroutine1: Sending $it") + channel.send(it) + } + } + + launch { // coroutine2 + repeat(100) { + println("coroutine2: Received ${channel.receive()}") + } + } + + delay(2000) + coroutineContext.cancelChildren() +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt new file mode 100644 index 0000000000..fdc4c295f8 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt @@ -0,0 +1,8 @@ +package com.baeldung.channles + +import java.text.SimpleDateFormat +import java.util.* + +fun log(value: Any) { + println(SimpleDateFormat("HH:MM:ss").format(Date()) + " - $value") +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt new file mode 100644 index 0000000000..245282dafc --- /dev/null +++ b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt @@ -0,0 +1,29 @@ +package com.baeldung.channels + +import kotlinx.coroutines.async +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class ChannelsTest { + @Test + fun should_pass_data_from_one_coroutine_to_another() { + runBlocking { + // given + val channel = Channel() + + // when + launch { // coroutine1 + channel.send("Hello World!") + } + val result = async { // coroutine 2 + channel.receive() + } + + // then + assertThat(result.await()).isEqualTo("Hello World!") + } + } +} \ No newline at end of file From 5116a45d1e05210176bac3c157d09c3d5351b17f Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Tue, 3 Nov 2020 20:37:30 +0100 Subject: [PATCH 111/590] Feature/bael 4662 sealed classes (#10224) * BAEL-4662: Initial commit of new module * BAEL-4662: Example with Records * BAEL-4662: Example with Interface * BAEL-4662: Add test classes * BAEL-4662: Update examples and tests * BAEL-4662: Rename test classes --- .../core-java-15/.mvn/jvm.config | 1 + core-java-modules/core-java-15/README.md | 7 ++ core-java-modules/core-java-15/pom.xml | 77 +++++++++++++++++++ .../baeldung/sealed/alternative/Vehicles.java | 49 ++++++++++++ .../java/com/baeldung/sealed/classes/Car.java | 21 +++++ .../com/baeldung/sealed/classes/Service.java | 11 +++ .../com/baeldung/sealed/classes/Truck.java | 21 +++++ .../com/baeldung/sealed/classes/Vehicle.java | 15 ++++ .../java/com/baeldung/sealed/records/Car.java | 14 ++++ .../com/baeldung/sealed/records/Truck.java | 14 ++++ .../com/baeldung/sealed/records/Vehicle.java | 7 ++ .../sealed/classes/VehicleUnitTest.java | 76 ++++++++++++++++++ .../sealed/records/VehicleUnitTest.java | 76 ++++++++++++++++++ 13 files changed, 389 insertions(+) create mode 100644 core-java-modules/core-java-15/.mvn/jvm.config create mode 100644 core-java-modules/core-java-15/README.md create mode 100644 core-java-modules/core-java-15/pom.xml create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java create mode 100644 core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java create mode 100644 core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java create mode 100644 core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java diff --git a/core-java-modules/core-java-15/.mvn/jvm.config b/core-java-modules/core-java-15/.mvn/jvm.config new file mode 100644 index 0000000000..50f549be0a --- /dev/null +++ b/core-java-modules/core-java-15/.mvn/jvm.config @@ -0,0 +1 @@ +--enable-preview \ No newline at end of file diff --git a/core-java-modules/core-java-15/README.md b/core-java-modules/core-java-15/README.md new file mode 100644 index 0000000000..53989f5cbb --- /dev/null +++ b/core-java-modules/core-java-15/README.md @@ -0,0 +1,7 @@ +## Core Java 15 + +This module contains articles about Java 15. + +### Relevant articles + +- TODO: add article links here diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml new file mode 100644 index 0000000000..c6f1454078 --- /dev/null +++ b/core-java-modules/core-java-15/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + core-java-15 + core-java-15 + jar + http://maven.apache.org + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../pom.xml + + + + + org.apache.commons + commons-lang3 + ${apache-commons-lang3.version} + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.release} + --enable-preview + 15 + 15 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + --enable-preview + + + + + + + 15 + 3.11 + 3.17.2 + 3.8.1 + 3.0.0-M3 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java new file mode 100644 index 0000000000..091c5841bf --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java @@ -0,0 +1,49 @@ +package com.baeldung.sealed.alternative; + +public class Vehicles { + + abstract static class Vehicle { + + private final String registrationNumber; + + public Vehicle(String registrationNumber) { + this.registrationNumber = registrationNumber; + } + + public String getRegistrationNumber() { + return registrationNumber; + } + + } + + public static final class Car extends Vehicle { + + private final int numberOfSeats; + + public Car(int numberOfSeats, String registrationNumber) { + super(registrationNumber); + this.numberOfSeats = numberOfSeats; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + } + + public static final class Truck extends Vehicle { + + private final int loadCapacity; + + public Truck(int loadCapacity, String registrationNumber) { + super(registrationNumber); + this.loadCapacity = loadCapacity; + } + + public int getLoadCapacity() { + return loadCapacity; + } + + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java new file mode 100644 index 0000000000..7dce266da7 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java @@ -0,0 +1,21 @@ +package com.baeldung.sealed.classes; + +public non-sealed class Car extends Vehicle implements Service { + + private final int numberOfSeats; + + public Car(int numberOfSeats, String registrationNumber) { + super(registrationNumber); + this.numberOfSeats = numberOfSeats; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + @Override + public int getMaxServiceIntervalInMonths() { + return 12; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java new file mode 100644 index 0000000000..9486b302f1 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java @@ -0,0 +1,11 @@ +package com.baeldung.sealed.classes; + +public sealed interface Service permits Car, Truck { + + int getMaxServiceIntervalInMonths(); + + default int getMaxDistanceBetweenServicesInKilometers() { + return 100000; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java new file mode 100644 index 0000000000..8d5234342b --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java @@ -0,0 +1,21 @@ +package com.baeldung.sealed.classes; + +public final class Truck extends Vehicle implements Service { + + private final int loadCapacity; + + public Truck(int loadCapacity, String registrationNumber) { + super(registrationNumber); + this.loadCapacity = loadCapacity; + } + + public int getLoadCapacity() { + return loadCapacity; + } + + @Override + public int getMaxServiceIntervalInMonths() { + return 18; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java new file mode 100644 index 0000000000..79eda0c790 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java @@ -0,0 +1,15 @@ +package com.baeldung.sealed.classes; + +public abstract sealed class Vehicle permits Car, Truck { + + protected final String registrationNumber; + + public Vehicle(String registrationNumber) { + this.registrationNumber = registrationNumber; + } + + public String getRegistrationNumber() { + return registrationNumber; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java new file mode 100644 index 0000000000..74b6ed1405 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java @@ -0,0 +1,14 @@ +package com.baeldung.sealed.records; + +public record Car(int numberOfSeats, String registrationNumber) implements Vehicle { + + @Override + public String getRegistrationNumber() { + return registrationNumber; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java new file mode 100644 index 0000000000..1b887ae014 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java @@ -0,0 +1,14 @@ +package com.baeldung.sealed.records; + +public record Truck(int loadCapacity, String registrationNumber) implements Vehicle { + + @Override + public String getRegistrationNumber() { + return registrationNumber; + } + + public int getLoadCapacity() { + return loadCapacity; + } + +} diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java new file mode 100644 index 0000000000..c51f8e97c6 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java @@ -0,0 +1,7 @@ +package com.baeldung.sealed.records; + +public sealed interface Vehicle permits Car, Truck { + + String getRegistrationNumber(); + +} diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java new file mode 100644 index 0000000000..b614981a43 --- /dev/null +++ b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.sealed.classes; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.lang.constant.ClassDesc; + +public class VehicleUnitTest { + + private static Vehicle car; + private static Vehicle truck; + + @BeforeAll + public static void createInstances() { + car = new Car(5, "VZ500DA"); + truck = new Truck(19000, "VZ600TA"); + } + + @Test + public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() { + Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false); + Assertions.assertThat(car.getClass().getSuperclass().isSealed()).isEqualTo(true); + Assertions.assertThat(car.getClass().getSuperclass().permittedSubclasses()) + .contains(ClassDesc.of(car.getClass().getCanonicalName())); + } + + @Test + public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() { + Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false); + Assertions.assertThat(truck.getClass().getSuperclass().isSealed()).isEqualTo(true); + Assertions.assertThat(truck.getClass().getSuperclass().permittedSubclasses()) + .contains(ClassDesc.of(truck.getClass().getCanonicalName())); + } + + @Test + public void givenCar_whenGettingPropertyTraditionalWay_thenNumberOfSeatsPropertyIsReturned() { + Assertions.assertThat(getPropertyTraditionalWay(car)).isEqualTo(5); + } + + @Test + public void givenCar_whenGettingPropertyViaPatternMatching_thenNumberOfSeatsPropertyIsReturned() { + Assertions.assertThat(getPropertyViaPatternMatching(car)).isEqualTo(5); + } + + @Test + public void givenTruck_whenGettingPropertyTraditionalWay_thenLoadCapacityIsReturned() { + Assertions.assertThat(getPropertyTraditionalWay(truck)).isEqualTo(19000); + } + + @Test + public void givenTruck_whenGettingPropertyViaPatternMatching_thenLoadCapacityIsReturned() { + Assertions.assertThat(getPropertyViaPatternMatching(truck)).isEqualTo(19000); + } + + private int getPropertyTraditionalWay(Vehicle vehicle) { + if (vehicle instanceof Car) { + return ((Car) vehicle).getNumberOfSeats(); + } else if (vehicle instanceof Truck) { + return ((Truck) vehicle).getLoadCapacity(); + } else { + throw new RuntimeException("Unknown instance of Vehicle"); + } + } + + private int getPropertyViaPatternMatching(Vehicle vehicle) { + if (vehicle instanceof Car car) { + return car.getNumberOfSeats(); + } else if (vehicle instanceof Truck truck) { + return truck.getLoadCapacity(); + } else { + throw new RuntimeException("Unknown instance of Vehicle"); + } + } + +} diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java new file mode 100644 index 0000000000..ac8a8c953c --- /dev/null +++ b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.sealed.records; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.lang.constant.ClassDesc; + +public class VehicleUnitTest { + + private static Vehicle car; + private static Vehicle truck; + + @BeforeAll + public static void createInstances() { + car = new Car(4, "VZ500DA"); + truck = new Truck(16000, "VZ600TA"); + } + + @Test + public void givenCar_whenUsingReflectionAPI_thenInterfaceIsSealed() { + Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false); + Assertions.assertThat(car.getClass().getInterfaces()[0].isSealed()).isEqualTo(true); + Assertions.assertThat(car.getClass().getInterfaces()[0].permittedSubclasses()) + .contains(ClassDesc.of(car.getClass().getCanonicalName())); + } + + @Test + public void givenTruck_whenUsingReflectionAPI_thenInterfaceIsSealed() { + Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false); + Assertions.assertThat(truck.getClass().getInterfaces()[0].isSealed()).isEqualTo(true); + Assertions.assertThat(truck.getClass().getInterfaces()[0].permittedSubclasses()) + .contains(ClassDesc.of(truck.getClass().getCanonicalName())); + } + + @Test + public void givenCar_whenGettingPropertyTraditionalWay_thenNumberOfSeatsPropertyIsReturned() { + Assertions.assertThat(getPropertyTraditionalWay(car)).isEqualTo(4); + } + + @Test + public void givenCar_whenGettingPropertyViaPatternMatching_thenNumberOfSeatsPropertyIsReturned() { + Assertions.assertThat(getPropertyViaPatternMatching(car)).isEqualTo(4); + } + + @Test + public void givenTruck_whenGettingPropertyTraditionalWay_thenLoadCapacityIsReturned() { + Assertions.assertThat(getPropertyTraditionalWay(truck)).isEqualTo(16000); + } + + @Test + public void givenTruck_whenGettingPropertyViaPatternMatching_thenLoadCapacityIsReturned() { + Assertions.assertThat(getPropertyViaPatternMatching(truck)).isEqualTo(16000); + } + + private int getPropertyTraditionalWay(Vehicle vehicle) { + if (vehicle instanceof Car) { + return ((Car) vehicle).getNumberOfSeats(); + } else if (vehicle instanceof Truck) { + return ((Truck) vehicle).getLoadCapacity(); + } else { + throw new RuntimeException("Unknown instance of Vehicle"); + } + } + + private int getPropertyViaPatternMatching(Vehicle vehicle) { + if (vehicle instanceof Car car) { + return car.getNumberOfSeats(); + } else if (vehicle instanceof Truck truck) { + return truck.getLoadCapacity(); + } else { + throw new RuntimeException("Unknown instance of Vehicle"); + } + } + +} From 6e8b8c086de2d100d5212f354dd70cc42b540b18 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Wed, 4 Nov 2020 10:36:43 +0200 Subject: [PATCH 112/590] BAEL-4687: updated jackson configuration --- .../jackson/config/CoffeeConfiguration.java | 9 ++++++ .../config/CoffeeWebConfiguration.java | 32 ------------------- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java index a6804a12f0..d13ce51e9b 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import java.time.format.DateTimeFormatter; @@ -18,6 +19,14 @@ public class CoffeeConfiguration { public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); + @Bean + public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { + Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() + .serializers(localDateTimeSerializer) + .serializationInclusion(JsonInclude.Include.NON_NULL); + return new MappingJackson2HttpMessageConverter(builder.build()); + } + @Bean public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL) diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java deleted file mode 100644 index a53ab3a805..0000000000 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.boot.jackson.config; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.time.format.DateTimeFormatter; -import java.util.List; - -@Configuration -public class CoffeeWebConfiguration implements WebMvcConfigurer { - public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; - private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); - - @Override - public void configureMessageConverters(List> converters) { - converters.add(mappingJackson2HttpMessageConverter()); - } - - @Bean - public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { - Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) - .serializationInclusion(JsonInclude.Include.NON_NULL); - return new MappingJackson2HttpMessageConverter(builder.build()); - } -} From 1fba6f01270e13debfb4ecd5a48d5e5eb7b266d5 Mon Sep 17 00:00:00 2001 From: Tarun Jain Date: Wed, 4 Nov 2020 14:09:33 +0530 Subject: [PATCH 113/590] BAEL-4645|Transient keyword in Java --- .../java/com/baeldung/transientkw/Book.java | 42 ++++++++++++++++++ .../com/baeldung/transientkw/BookSerDe.java | 44 +++++++++++++++++++ .../transientkw/TransientUnitTest.java | 35 +++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java new file mode 100644 index 0000000000..5822d83841 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java @@ -0,0 +1,42 @@ +package com.baeldung.transientkw; + +import java.io.Serializable; + +public class Book implements Serializable { + + private static final long serialVersionUID = -2936687026040726549L; + + private String bookName; + private transient String description; + private transient int copies; + private final transient String bookCategory = "Fiction"; + + public String getBookName() { + return bookName; + } + + public void setBookName(String bookName) { + this.bookName = bookName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getCopies() { + return copies; + } + + public void setCopies(int copies) { + this.copies = copies; + } + + public String getBookCategory() { + return bookCategory; + } + +} diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java new file mode 100644 index 0000000000..38e018baa3 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java @@ -0,0 +1,44 @@ +package com.baeldung.transientkw; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class BookSerDe { + static String fileName = "book.ser"; + + /** + * Method to serialize Book objects to the file + * @throws FileNotFoundException + */ + public static void serialize(Book book) throws Exception { + FileOutputStream file = new FileOutputStream(fileName); + ObjectOutputStream out = new ObjectOutputStream(file); + + out.writeObject(book); + + out.close(); + file.close(); + } + + /** + * Method to deserialize the person object + * @return book + * @throws IOException, ClassNotFoundException + */ + public static Book deserialize() throws Exception { + FileInputStream file = new FileInputStream(fileName); + ObjectInputStream in = new ObjectInputStream(file); + + Book book = (Book) in.readObject(); + + in.close(); + file.close(); + + return book; + } + +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java new file mode 100644 index 0000000000..cf63a0ddda --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.transientkw; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +class TransientUnitTest { + + @Test + void givenTransient_whenSerDe_thenVerifyValues() throws Exception { + Book book = new Book(); + book.setBookName("Java Reference"); + book.setDescription("will not be saved"); + book.setCopies(25); + + BookSerDe.serialize(book); + Book book2 = BookSerDe.deserialize(); + + assertEquals("Java Reference", book2.getBookName()); + assertNull(book2.getDescription()); + assertEquals(0, book2.getCopies()); + } + + @Test + void givenFinalTransient_whenSerDe_thenValuePersisted() throws Exception { + Book book = new Book(); + + BookSerDe.serialize(book); + Book book2 = BookSerDe.deserialize(); + + assertEquals("Fiction", book2.getBookCategory()); + } + +} From d584f37af0cb3723027c6b5afa6486e42ced0ee6 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 31 Oct 2020 17:40:52 +0330 Subject: [PATCH 114/590] add test file --- .../core-java-security-2/src/test/resources/baeldung.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core-java-modules/core-java-security-2/src/test/resources/baeldung.txt diff --git a/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt b/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt new file mode 100644 index 0000000000..dc6988d2f9 --- /dev/null +++ b/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt @@ -0,0 +1,2 @@ +Hello Baeldung +This is AES file encryption sample \ No newline at end of file From cb48f0bd64e75c0327acbe3e69550cbd5d240c99 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 31 Oct 2020 17:41:10 +0330 Subject: [PATCH 115/590] update assertj version --- core-java-modules/core-java-security-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml index 890b4147ca..895509410d 100644 --- a/core-java-modules/core-java-security-2/pom.xml +++ b/core-java-modules/core-java-security-2/pom.xml @@ -53,7 +53,7 @@ 1.11 - 3.10.0 + 3.18.0 2.3.1 From 01baf5c7525383eff7deba29780de274af51d5d4 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 31 Oct 2020 17:41:37 +0330 Subject: [PATCH 116/590] add aes main source --- .../main/java/com/baeldung/aes/AESUtil.java | 183 ++++++++++++++++++ .../main/java/com/baeldung/aes/Student.java | 29 +++ .../com/baeldung/aes/AESUtilUnitTest.java | 89 +++++++++ 3 files changed, 301 insertions(+) create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java new file mode 100644 index 0000000000..c4568623d0 --- /dev/null +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java @@ -0,0 +1,183 @@ +package com.baeldung.crypto; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.*; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.util.Base64; + +public class AESUtil { + static Logger logger = LoggerFactory.getLogger(AESUtil.class); + + public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + byte[] cipherText = cipher.doFinal(input.getBytes()); + return Base64.getEncoder().encodeToString(cipherText); + } catch (NoSuchAlgorithmException | NoSuchPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | IllegalBlockSizeException | BadPaddingException exp) { + logger.error(exp.getMessage()); + } + return null; + } + + public static String decrypt(String algorithm, String cipherText, SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + byte[] plainText = cipher.doFinal(Base64.getDecoder().decode(cipherText)); + return new String(plainText); + } catch (NoSuchAlgorithmException | NoSuchPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | IllegalBlockSizeException | BadPaddingException exp) { + logger.error(exp.getMessage()); + } + return null; + } + + public static SecretKey generateKey(int n) throws NoSuchAlgorithmException { + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + keyGenerator.init(n); + SecretKey key = keyGenerator.generateKey(); + return key; + } + + public static SecretKey getKeyFromPassword(String password, String salt) + throws NoSuchAlgorithmException, InvalidKeySpecException { + SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); + KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 65536, 256); + SecretKey secret = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); + return secret; + } + + public static IvParameterSpec generateIv() { + byte[] iv = new byte[16]; + new SecureRandom().nextBytes(iv); + return new IvParameterSpec(iv); + } + + public static void encryptFile(String algorithm, SecretKey key, IvParameterSpec iv + , File inputFile, File outputFile) throws IOException { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + FileInputStream inputStream = new FileInputStream(inputFile); + FileOutputStream outputStream = new FileOutputStream(outputFile); + byte[] buffer = new byte[64]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + byte[] output = cipher.update(buffer, 0, bytesRead); + if (output != null) { + outputStream.write(output); + } + } + byte[] outputBytes = cipher.doFinal(); + if (outputBytes != null) { + outputStream.write(outputBytes); + } + inputStream.close(); + outputStream.close(); + } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException + | NoSuchPaddingException | BadPaddingException + | IllegalBlockSizeException | InvalidKeyException exp) { + logger.error(exp.getMessage()); + } + } + + public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv + , File encryptedFile, File decryptedFile) throws IOException { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + FileInputStream inputStream = new FileInputStream(encryptedFile); + FileOutputStream outputStream = new FileOutputStream(decryptedFile); + byte[] buffer = new byte[64]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + byte[] output = cipher.update(buffer, 0, bytesRead); + if (output != null) { + outputStream.write(output); + } + } + byte[] output = cipher.doFinal(); + if (output != null) { + outputStream.write(output); + } + inputStream.close(); + outputStream.close(); + } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException + | NoSuchPaddingException | BadPaddingException + | IllegalBlockSizeException | InvalidKeyException exp) { + logger.error(exp.getMessage()); + } + } + + public static SealedObject encryptObject(String algorithm, Serializable object, SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + SealedObject sealedObject = new SealedObject(object, cipher); + return sealedObject; + } catch (NoSuchAlgorithmException | NoSuchPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | IOException | IllegalBlockSizeException exp) { + logger.error(exp.getMessage()); + } + return null; + } + + public static Serializable decryptObject(String algorithm, SealedObject sealedObject + , SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + Serializable unsealObject = (Serializable) sealedObject.getObject(cipher); + return unsealObject; + } catch (NoSuchAlgorithmException | NoSuchPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | IOException | ClassNotFoundException | IllegalBlockSizeException + | BadPaddingException exp) { + logger.error(exp.getMessage()); + } + return null; + } + + public static String encryptPasswordBased(String plainText, SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + return Base64.getEncoder().encodeToString(cipher.doFinal(plainText.getBytes())); + } catch (NoSuchAlgorithmException | BadPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | NoSuchPaddingException | IllegalBlockSizeException exp) { + logger.error(exp.getMessage()); + } + return null; + } + + public static String decryptPasswordBased(String cipherText, SecretKey key, IvParameterSpec iv) { + try { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + return new String(cipher.doFinal(Base64.getDecoder().decode(cipherText))); + } catch (NoSuchAlgorithmException | BadPaddingException + | InvalidKeyException | InvalidAlgorithmParameterException + | NoSuchPaddingException | IllegalBlockSizeException exp) { + logger.error(exp.getMessage()); + } + return null; + } + +} diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java new file mode 100644 index 0000000000..be87d4b06f --- /dev/null +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java @@ -0,0 +1,29 @@ +package com.baeldung.crypto; + +import java.io.Serializable; + +public class Student implements Serializable { + private String name; + private int age; + + public Student(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } +} diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java new file mode 100644 index 0000000000..fd51ce6a62 --- /dev/null +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -0,0 +1,89 @@ +package com.baeldung.crypto; + +import org.assertj.core.api.WithAssertions; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.crypto.*; +import javax.crypto.spec.IvParameterSpec; +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; + +//@SpringBootTest +class AESUtilUnitTest implements WithAssertions { + + @Test + void contextLoads() { + } + + @Test + void givenString_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException { + // given + String input = "baeldung"; + SecretKey key = AESUtil.generateKey(128); + IvParameterSpec ivParameterSpec = AESUtil.generateIv(); + String algorithm = "AES/CBC/PKCS5Padding"; + + // when + String cipherText = AESUtil.encrypt(algorithm, input, key, ivParameterSpec); + String plainText = AESUtil.decrypt(algorithm, cipherText, key, ivParameterSpec); + + // then + Assertions.assertEquals(input, plainText); + } + + @Test + void givenFile_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException, IOException { + // given + SecretKey key = AESUtil.generateKey(128); + String algorithm = "AES/CBC/PKCS5Padding"; + IvParameterSpec ivParameterSpec = AESUtil.generateIv(); + File inputFile = Paths.get("src/test/resources/baeldung.txt").toFile(); + File encryptedFile = new File("classpath:baeldung.encrypted"); + File decryptedFile = new File("document.decrypted"); + + // when + AESUtil.encryptFile(algorithm, key, ivParameterSpec, inputFile, encryptedFile); + AESUtil.decryptFile(algorithm, key, ivParameterSpec, encryptedFile, decryptedFile); + + // then + assertThat(inputFile).hasSameTextualContentAs(decryptedFile); + } + + @Test + void givenObject_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException { + // given + Student student = new Student("Baeldung", 20); + SecretKey key = AESUtil.generateKey(128); + IvParameterSpec ivParameterSpec = AESUtil.generateIv(); + String algorithm = "AES/CBC/PKCS5Padding"; + + // when + SealedObject sealedObject = AESUtil.encryptObject(algorithm, student, key, ivParameterSpec); + Student object = (Student) AESUtil.decryptObject(algorithm, sealedObject, key, ivParameterSpec); + + // then + assertThat(student).isEqualToComparingFieldByField(object); + } + + @Test + void givenPassword_whenEncrypt_thenSuccess() throws InvalidKeySpecException, NoSuchAlgorithmException { + // given + String plainText = "www.baeldung.com"; + String password = "baeldung"; + String salt = "12345678"; + IvParameterSpec ivParameterSpec = AESUtil.generateIv(); + SecretKey key = AESUtil.getKeyFromPassword(password,salt); + + // when + String cipherText = AESUtil.encryptPasswordBased(plainText, key, ivParameterSpec); + String decryptedCipherText = AESUtil.decryptPasswordBased(cipherText, key, ivParameterSpec); + + // then + Assertions.assertEquals(plainText, decryptedCipherText); + } +} + From 6f785fdef57d90cc4689a3dd9ac351c5a47f5d1d Mon Sep 17 00:00:00 2001 From: sharifi Date: Sat, 31 Oct 2020 17:40:22 +0330 Subject: [PATCH 117/590] update README file --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index 03a5a94acc..f6bc410900 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -12,4 +12,5 @@ This module contains articles about core Java Security - [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) - [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms) - [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates) +- [Java AES encryption and decryption](https://www.baeldung.com/) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From e13f7952b13463ad6f274425e0b9e9d52826b1b2 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Wed, 4 Nov 2020 19:34:50 +0530 Subject: [PATCH 118/590] BAEL-4399: Changes for removing tab spaces --- .../exceptions/nosuchfielderror/Dependent.java | 4 +++- .../nosuchfielderror/FieldErrorExample.java | 12 ++++++++---- .../nosuchfielderror/FieldErrorExampleUnitTest.java | 6 ++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java index d838eafdd9..9e222c5a87 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java @@ -1,6 +1,8 @@ package com.baeldung.exceptions.nosuchfielderror; public class Dependent { + // This needed to be commented post compilation of NoSuchFielDError and Compile public static String message = "Hello Baeldung!!"; -} + +} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java index 71099201b8..d2b0bccad0 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java @@ -1,16 +1,20 @@ package com.baeldung.exceptions.nosuchfielderror; public class FieldErrorExample { - + public static void main(String... args) { + fetchAndPrint(); } - + public static String getDependentMessage() { + return Dependent.message; } - + public static void fetchAndPrint() { + System.out.println(getDependentMessage()); } -} + +} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java index 5b18b92079..d9a3efacc8 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java @@ -5,10 +5,12 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; public class FieldErrorExampleUnitTest { - + @Test public void whenDependentMessage_returnMessage() { + String dependentMessage = FieldErrorExample.getDependentMessage(); assertTrue("Hello Baeldung!!".equals(dependentMessage)); } -} + +} \ No newline at end of file From 06c800c526cf8f40906c02214cfffed687108c46 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Thu, 29 Oct 2020 00:16:53 +0800 Subject: [PATCH 119/590] BAEL-4643: JPA CascadeType.REMOVE vs orphanRemoval * Defines the Domain: ShipmentInfo, LineItem and OrderRequest entity * Adds CascadeTypeRemoveIntegrationTest * Adds OrphanRemovalIntegrationTest --- .../com/baeldung/jpa/removal/LineItem.java | 42 ++++++++++ .../baeldung/jpa/removal/OrderRequest.java | 38 +++++++++ .../baeldung/jpa/removal/ShipmentInfo.java | 22 ++++++ .../main/resources/META-INF/persistence.xml | 18 +++++ .../CascadeTypeRemoveIntegrationTest.java | 72 +++++++++++++++++ .../removal/OrphanRemovalIntegrationTest.java | 78 +++++++++++++++++++ 6 files changed, 270 insertions(+) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java new file mode 100644 index 0000000000..c926785acc --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java @@ -0,0 +1,42 @@ +package com.baeldung.jpa.removal; + +import java.util.Objects; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class LineItem { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @ManyToOne + private OrderRequest orderRequest; + + public LineItem(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LineItem lineItem = (LineItem) o; + + return Objects.equals(id, lineItem.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected LineItem() {} +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java new file mode 100644 index 0000000000..ada0459054 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java @@ -0,0 +1,38 @@ +package com.baeldung.jpa.removal; + +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + +@Entity +public class OrderRequest { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @OneToOne(cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) + private ShipmentInfo shipmentInfo; + + @OneToMany(orphanRemoval = true, cascade = CascadeType.PERSIST, mappedBy = "orderRequest") + private List lineItems; + + public OrderRequest(ShipmentInfo shipmentInfo) { + this.shipmentInfo = shipmentInfo; + } + + public OrderRequest(List lineItems) { + this.lineItems = lineItems; + } + + public void removeLineItem(LineItem lineItem) { + lineItems.remove(lineItem); + } + + protected OrderRequest() {} +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java new file mode 100644 index 0000000000..67c8151801 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java @@ -0,0 +1,22 @@ +package com.baeldung.jpa.removal; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class ShipmentInfo { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + public ShipmentInfo(String name) { + this.name = name; + } + + protected ShipmentInfo() {} +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 28a929f912..39d55695c4 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -22,4 +22,22 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.removal.ShipmentInfo + com.baeldung.jpa.removal.LineItem + com.baeldung.jpa.removal.OrderRequest + true + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java new file mode 100644 index 0000000000..11050a14ee --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java @@ -0,0 +1,72 @@ +package com.baeldung.jpa.removal; + +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class CascadeTypeRemoveIntegrationTest { + + private static EntityManagerFactory factory; + private static EntityManager entityManager; + + @BeforeClass + public static void setup() { + factory = Persistence.createEntityManagerFactory("jpa-h2-removal"); + entityManager = factory.createEntityManager(); + } + + @Test + public void whenOrderRequestIsDeleted_thenDeleteShipmentInfo() { + createOrderRequestWithShipmentInfo(); + + OrderRequest orderRequest = entityManager.find(OrderRequest.class, 1L); + + entityManager.getTransaction().begin(); + entityManager.remove(orderRequest); + entityManager.getTransaction().commit(); + + Assert.assertEquals(0, findAllOrderRequest().size()); + Assert.assertEquals(0, findAllShipmentInfo().size()); + } + + private void createOrderRequestWithShipmentInfo() { + ShipmentInfo shipmentInfo = new ShipmentInfo("name"); + OrderRequest orderRequest = new OrderRequest(shipmentInfo); + + entityManager.getTransaction().begin(); + entityManager.persist(orderRequest); + entityManager.getTransaction().commit(); + + Assert.assertEquals(1, findAllOrderRequest().size()); + Assert.assertEquals(1, findAllShipmentInfo().size()); + } + + private List findAllOrderRequest() { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(OrderRequest.class); + Root root = cq.from(OrderRequest.class); + CriteriaQuery findAll = cq.select(root); + TypedQuery findAllQuery = entityManager.createQuery(findAll); + + return findAllQuery.getResultList(); + } + + private List findAllShipmentInfo() { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(ShipmentInfo.class); + Root root = cq.from(ShipmentInfo.class); + CriteriaQuery findAll = cq.select(root); + TypedQuery findAllQuery = entityManager.createQuery(findAll); + + return findAllQuery.getResultList(); + } + +} diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java new file mode 100644 index 0000000000..75bb321ef4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java @@ -0,0 +1,78 @@ +package com.baeldung.jpa.removal; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class OrphanRemovalIntegrationTest { + + private static EntityManagerFactory factory; + private static EntityManager entityManager; + + @BeforeClass + public static void setup() { + factory = Persistence.createEntityManagerFactory("jpa-h2-removal"); + entityManager = factory.createEntityManager(); + } + + @Test + public void whenLineItemIsRemovedFromOrderRequest_thenDeleteOrphanedLineItem() { + createOrderRequestWithLineItems(); + + OrderRequest orderRequest = entityManager.find(OrderRequest.class, 1L); + LineItem lineItem = entityManager.find(LineItem.class, 2L); + orderRequest.removeLineItem(lineItem); + + entityManager.getTransaction().begin(); + entityManager.merge(orderRequest); + entityManager.getTransaction().commit(); + + Assert.assertEquals(1, findAllOrderRequest().size()); + Assert.assertEquals(2, findAllLineItem().size()); + } + + private void createOrderRequestWithLineItems() { + List lineItems = new ArrayList<>(); + lineItems.add(new LineItem("line item 1")); + lineItems.add(new LineItem("line item 2")); + lineItems.add(new LineItem("line item 3")); + + OrderRequest orderRequest = new OrderRequest(lineItems); + + entityManager.getTransaction().begin(); + entityManager.persist(orderRequest); + entityManager.getTransaction().commit(); + + Assert.assertEquals(1, findAllOrderRequest().size()); + Assert.assertEquals(3, findAllLineItem().size()); + } + + private List findAllOrderRequest() { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(OrderRequest.class); + Root root = cq.from(OrderRequest.class); + CriteriaQuery findAll = cq.select(root); + TypedQuery findAllQuery = entityManager.createQuery(findAll); + + return findAllQuery.getResultList(); + } + + private List findAllLineItem() { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(LineItem.class); + Root root = cq.from(LineItem.class); + CriteriaQuery findAll = cq.select(root); + TypedQuery findAllQuery = entityManager.createQuery(findAll); + + return findAllQuery.getResultList(); + } +} From 3139be94685028526a9943bea34d872cec7e40e4 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Tue, 3 Nov 2020 19:11:44 +0800 Subject: [PATCH 120/590] BAEL-4643: JPA CascadeType.REMOVE vs orphanRemoval * Reformats code using the provided intelliJ-formatter.xml --- .../com/baeldung/jpa/removal/LineItem.java | 11 ++- .../baeldung/jpa/removal/OrderRequest.java | 5 +- .../baeldung/jpa/removal/ShipmentInfo.java | 3 +- .../main/resources/META-INF/persistence.xml | 78 +++++++++---------- .../CascadeTypeRemoveIntegrationTest.java | 9 ++- .../removal/OrphanRemovalIntegrationTest.java | 11 +-- 6 files changed, 62 insertions(+), 55 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java index c926785acc..9ab2dd4e74 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/LineItem.java @@ -1,11 +1,11 @@ package com.baeldung.jpa.removal; -import java.util.Objects; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; +import java.util.Objects; @Entity public class LineItem { @@ -25,8 +25,10 @@ public class LineItem { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; LineItem lineItem = (LineItem) o; @@ -38,5 +40,6 @@ public class LineItem { return id != null ? id.hashCode() : 0; } - protected LineItem() {} + protected LineItem() { + } } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java index ada0459054..16ee3e0109 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java @@ -1,6 +1,5 @@ package com.baeldung.jpa.removal; -import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,6 +7,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; +import java.util.List; @Entity public class OrderRequest { @@ -34,5 +34,6 @@ public class OrderRequest { lineItems.remove(lineItem); } - protected OrderRequest() {} + protected OrderRequest() { + } } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java index 67c8151801..12274bcadf 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/ShipmentInfo.java @@ -18,5 +18,6 @@ public class ShipmentInfo { this.name = name; } - protected ShipmentInfo() {} + protected ShipmentInfo() { + } } diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 39d55695c4..88378bd8db 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -1,43 +1,43 @@ - - org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.equality.EqualByJavaDefault - com.baeldung.jpa.equality.EqualById - com.baeldung.jpa.equality.EqualByBusinessKey - true - - - - - - - - - - - - - - org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.removal.ShipmentInfo - com.baeldung.jpa.removal.LineItem - com.baeldung.jpa.removal.OrderRequest - true - - - - - - - - - - - - + version="2.2"> + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.equality.EqualByJavaDefault + com.baeldung.jpa.equality.EqualById + com.baeldung.jpa.equality.EqualByBusinessKey + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.removal.ShipmentInfo + com.baeldung.jpa.removal.LineItem + com.baeldung.jpa.removal.OrderRequest + true + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java index 11050a14ee..8f99723ac6 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/CascadeTypeRemoveIntegrationTest.java @@ -1,6 +1,9 @@ package com.baeldung.jpa.removal; -import java.util.List; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; @@ -8,9 +11,7 @@ import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import java.util.List; public class CascadeTypeRemoveIntegrationTest { diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java index 75bb321ef4..0ab6e4cfbc 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java @@ -1,7 +1,9 @@ package com.baeldung.jpa.removal; -import java.util.ArrayList; -import java.util.List; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; @@ -9,9 +11,8 @@ import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import java.util.ArrayList; +import java.util.List; public class OrphanRemovalIntegrationTest { From bc501e36b354cc5b02f9f9799b90baf172385a9a Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Wed, 4 Nov 2020 23:38:29 +0800 Subject: [PATCH 121/590] BAEL-4643: JPA CascadeType.REMOVE vs orphanRemoval * Adds a test to OrphanRemovalIntegrationTest that expects a PersistenceException --- .../baeldung/jpa/removal/OrderRequest.java | 4 ++++ .../removal/OrphanRemovalIntegrationTest.java | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java index 16ee3e0109..739c110d8c 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/removal/OrderRequest.java @@ -34,6 +34,10 @@ public class OrderRequest { lineItems.remove(lineItem); } + public void setLineItems(List lineItems) { + this.lineItems = lineItems; + } + protected OrderRequest() { } } diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java index 0ab6e4cfbc..615e8cf3a8 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/removal/OrphanRemovalIntegrationTest.java @@ -1,12 +1,13 @@ package com.baeldung.jpa.removal; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; +import javax.persistence.PersistenceException; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -19,8 +20,8 @@ public class OrphanRemovalIntegrationTest { private static EntityManagerFactory factory; private static EntityManager entityManager; - @BeforeClass - public static void setup() { + @Before + public void setup() { factory = Persistence.createEntityManagerFactory("jpa-h2-removal"); entityManager = factory.createEntityManager(); } @@ -41,6 +42,18 @@ public class OrphanRemovalIntegrationTest { Assert.assertEquals(2, findAllLineItem().size()); } + @Test(expected = PersistenceException.class) + public void whenLineItemsIsReassigned_thenThrowAnException() { + createOrderRequestWithLineItems(); + + OrderRequest orderRequest = entityManager.find(OrderRequest.class, 1L); + orderRequest.setLineItems(new ArrayList<>()); + + entityManager.getTransaction().begin(); + entityManager.merge(orderRequest); + entityManager.getTransaction().commit(); + } + private void createOrderRequestWithLineItems() { List lineItems = new ArrayList<>(); lineItems.add(new LineItem("line item 1")); From 99689edd888206463c9b671fab7baa1905168873 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 13:55:30 +0800 Subject: [PATCH 122/590] Update README.md --- libraries-http-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-http-2/README.md b/libraries-http-2/README.md index 5ba45eb4a9..c0d6e76f1b 100644 --- a/libraries-http-2/README.md +++ b/libraries-http-2/README.md @@ -6,5 +6,6 @@ This module contains articles about HTTP libraries. - [Jetty ReactiveStreams HTTP Client](https://www.baeldung.com/jetty-reactivestreams-http-client) - [Decode an OkHttp JSON Response](https://www.baeldung.com/okhttp-json-response) +- [Retrofit 2 – Dynamic URL](https://www.baeldung.com/retrofit-dynamic-url) - More articles [[<-- prev]](/libraries-http) From dc34794a5f5cffade1087c1dc7f01bef8ed6f6a4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 13:58:00 +0800 Subject: [PATCH 123/590] Update README.md --- spring-boot-modules/spring-boot-swagger-jwt/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-swagger-jwt/README.md b/spring-boot-modules/spring-boot-swagger-jwt/README.md index 97c76dc431..f04dd5957a 100644 --- a/spring-boot-modules/spring-boot-swagger-jwt/README.md +++ b/spring-boot-modules/spring-boot-swagger-jwt/README.md @@ -1,2 +1,3 @@ ## Relevant Articles: +- [Set JWT with Spring Boot and Swagger UI](https://www.baeldung.com/spring-boot-swagger-jwt) From a3e67d1f8728153bb889ff9fd18d9b24ce4239c8 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:07:07 +0800 Subject: [PATCH 124/590] Update README.md --- gradle/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/README.md b/gradle/README.md index 84a8508e2c..cf002a7114 100644 --- a/gradle/README.md +++ b/gradle/README.md @@ -8,3 +8,4 @@ This module contains articles about Gradle - [Creating a Fat Jar in Gradle](https://www.baeldung.com/gradle-fat-jar) - [A Custom Task in Gradle](https://www.baeldung.com/gradle-custom-task) - [Using JUnit 5 with Gradle](https://www.baeldung.com/junit-5-gradle) +- [Dependency Management in Gradle](https://www.baeldung.com/gradle-dependency-management) From d927293989d47f2733af03ad53b7452e65579e88 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:09:02 +0800 Subject: [PATCH 125/590] Update README.md --- libraries-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-6/README.md b/libraries-6/README.md index f91ad43bbe..ecad499e07 100644 --- a/libraries-6/README.md +++ b/libraries-6/README.md @@ -17,4 +17,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Introduction to Protonpack](https://www.baeldung.com/java-protonpack) - [Java-R Integration](https://www.baeldung.com/java-r-integration) - [Using libphonenumber to Validate Phone Numbers](https://www.baeldung.com/java-libphonenumber) +- [Apache Commons Collections vs Google Guava](https://www.baeldung.com/apache-commons-collections-vs-guava) - More articles [[<-- prev]](/libraries-5) From 95cc0130a7c9f3c395e60f80bf0c7d86a61d72f4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:10:38 +0800 Subject: [PATCH 126/590] Update README.md --- persistence-modules/spring-boot-persistence-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-boot-persistence-2/README.md b/persistence-modules/spring-boot-persistence-2/README.md index e7f32053e4..d7c13fd363 100644 --- a/persistence-modules/spring-boot-persistence-2/README.md +++ b/persistence-modules/spring-boot-persistence-2/README.md @@ -6,4 +6,5 @@ - [List of In-Memory Databases](https://www.baeldung.com/java-in-memory-databases) - [Oracle Connection Pooling With Spring](https://www.baeldung.com/spring-oracle-connection-pooling) - [Object States in Hibernate’s Session](https://www.baeldung.com/hibernate-session-object-states) +- [Storing Files Indexed by a Database](https://www.baeldung.com/java-db-storing-files) - More articles: [[<-- prev]](../spring-boot-persistence) From ff17ea49cf55a69df0dd6c7f711071c307ea5a82 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:12:52 +0800 Subject: [PATCH 127/590] 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 4e3dd22bb8..f136a73daf 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -3,3 +3,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) +- [AbstractMethodError in Java](https://www.baeldung.com/java-abstractmethoderror) From 8cdfd5051dad6f8f48478ff2936cf08b51df4868 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:17:57 +0800 Subject: [PATCH 128/590] Update README.md --- java-numbers-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-4/README.md b/java-numbers-4/README.md index 344d348733..7db25b283c 100644 --- a/java-numbers-4/README.md +++ b/java-numbers-4/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Probability in Java](https://www.baeldung.com/java-probability) +- [Understanding the & 0xff Value in Java](https://www.baeldung.com/java-and-0xff) From 0a4fc2ef66a67ba9336861c9e7d7928de9f4f8d7 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 5 Nov 2020 08:58:04 +0100 Subject: [PATCH 129/590] JAVA-3384: Fix integration tests in the spring-boot-properties --- .../ConfigPropertiesDemoApplication.java | 5 +---- .../ConfigPropertiesIntegrationTest.java | 22 +++++++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java index 1e5e88921a..c435f9e320 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java @@ -1,13 +1,10 @@ package com.baeldung.properties; -import com.baeldung.buildproperties.Application; +import com.baeldung.configurationproperties.ConfigProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.ComponentScan; -import com.baeldung.configurationproperties.ConfigProperties; - @SpringBootApplication @ComponentScan(basePackageClasses = {ConfigProperties.class, AdditionalProperties.class}) public class ConfigPropertiesDemoApplication { diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java index 3b80fa66fe..7f239cbcff 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java @@ -4,12 +4,10 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.configurationproperties.ConfigProperties; import com.baeldung.properties.AdditionalProperties; import com.baeldung.properties.ConfigPropertiesDemoApplication; @@ -19,34 +17,34 @@ import com.baeldung.properties.ConfigPropertiesDemoApplication; public class ConfigPropertiesIntegrationTest { @Autowired - private ConfigProperties properties; + private ConfigProperties configProperties; @Autowired private AdditionalProperties additionalProperties; @Test public void whenSimplePropertyQueriedthenReturnsProperty() throws Exception { - Assert.assertTrue("From address is read as null!", properties.getFrom() != null); + Assert.assertTrue("From address is read as null!", configProperties.getFrom() != null); } @Test public void whenListPropertyQueriedthenReturnsProperty() throws Exception { - Assert.assertTrue("Couldn't bind list property!", properties.getDefaultRecipients().size() == 2); - Assert.assertTrue("Incorrectly bound list property. Expected 2 entries!", properties.getDefaultRecipients().size() == 2); + Assert.assertTrue("Couldn't bind list property!", configProperties.getDefaultRecipients().size() == 2); + Assert.assertTrue("Incorrectly bound list property. Expected 2 entries!", configProperties.getDefaultRecipients().size() == 2); } @Test public void whenMapPropertyQueriedthenReturnsProperty() throws Exception { - Assert.assertTrue("Couldn't bind map property!", properties.getAdditionalHeaders() != null); - Assert.assertTrue("Incorrectly bound map property. Expected 3 Entries!", properties.getAdditionalHeaders().size() == 3); + Assert.assertTrue("Couldn't bind map property!", configProperties.getAdditionalHeaders() != null); + Assert.assertTrue("Incorrectly bound map property. Expected 3 Entries!", configProperties.getAdditionalHeaders().size() == 3); } @Test public void whenObjectPropertyQueriedthenReturnsProperty() throws Exception { - Assert.assertTrue("Couldn't bind map property!", properties.getCredentials() != null); - Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials().getAuthMethod().equals("SHA1")); - Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials().getUsername().equals("john")); - Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials().getPassword().equals("password")); + Assert.assertTrue("Couldn't bind map property!", configProperties.getCredentials() != null); + Assert.assertTrue("Incorrectly bound object property!", configProperties.getCredentials().getAuthMethod().equals("SHA1")); + Assert.assertTrue("Incorrectly bound object property!", configProperties.getCredentials().getUsername().equals("john")); + Assert.assertTrue("Incorrectly bound object property!", configProperties.getCredentials().getPassword().equals("password")); } @Test From c5236f0acb165305227e64ad73cce91a6918adab Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 6 Nov 2020 09:08:16 +0100 Subject: [PATCH 130/590] JAVA-3384: Add missing commons-collections4 dependency --- libraries-6/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index 7bb6028f17..0f129c27c9 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -76,6 +76,11 @@ commons-lang3 ${commons-lang3.version} + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + commons-net commons-net @@ -156,6 +161,7 @@ RELEASE 3.0 1.8.1 + 4.4 8.12.9 From bd6e3a5328fcdb55bd9b075945932b9fd04d5257 Mon Sep 17 00:00:00 2001 From: GilvanOrnelas Date: Fri, 6 Nov 2020 06:04:33 -0300 Subject: [PATCH 131/590] Fixing db indexing integration tests (#10229) Co-authored-by: Gilvan Ornelas Fernandes Filho --- .../java/com/baeldung/db/indexing/Image.java | 4 ++++ .../FileSystemImageIntegrationTest.java | 6 +++++- .../db/indexing/ImageIntegrationTest.java | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java index 5348788c12..e3fcf53f81 100644 --- a/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java +++ b/persistence-modules/spring-boot-persistence-2/src/main/java/com/baeldung/db/indexing/Image.java @@ -22,6 +22,10 @@ class Image { public Image() { } + public Image(Long id) { + this.id = id; + } + public Image(String name, String location) { this.name = name; this.location = location; diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java index 3082f16a78..83f5bae095 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/FileSystemImageIntegrationTest.java @@ -35,8 +35,12 @@ class FileSystemImageIntegrationTest { ClassLoader classLoader = ClassLoader.getSystemClassLoader(); InputStream image = classLoader.getResourceAsStream("baeldung.jpeg"); + MockMultipartFile jpegImage = new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image); MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/file-system/image") - .file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image)); + .file(jpegImage); + + given(fileLocationService.save(jpegImage.getBytes(), "baeldung")) + .willReturn(1L); MvcResult result = mockMvc.perform(multipartRequest) .andExpect(status().isOk()) diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java index f7d4ecf129..e38e0a21a9 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/db/indexing/ImageIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.db.indexing; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -34,13 +35,10 @@ class ImageIntegrationTest { @Test void givenBaeldungJpegImage_whenUploadIt_thenReturnItsId() throws Exception { - ClassLoader classLoader = ClassLoader.getSystemClassLoader(); - InputStream image = classLoader.getResourceAsStream("baeldung.jpeg"); + given(imageRepository.save(any())) + .willReturn(new Image(1L)); - MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/image") - .file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image)); - - MvcResult result = mockMvc.perform(multipartRequest) + MvcResult result = mockMvc.perform(createUploadImageRequest()) .andExpect(status().isOk()) .andReturn(); @@ -60,6 +58,14 @@ class ImageIntegrationTest { .andExpect(status().isOk()); } + private MockMultipartHttpServletRequestBuilder createUploadImageRequest() throws IOException { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + InputStream image = classLoader.getResourceAsStream("baeldung.jpeg"); + + return MockMvcRequestBuilders.multipart("/image") + .file(new MockMultipartFile("multipartImage", "baeldung", MediaType.TEXT_PLAIN_VALUE, image)); + } + private Image baeldungImage() throws IOException { ClassLoader classLoader = ClassLoader.getSystemClassLoader(); From 1a0d8f4be01088aeba401135699de4a6a1f79efd Mon Sep 17 00:00:00 2001 From: "Amitabh.Tiwari" Date: Fri, 6 Nov 2020 16:02:36 +0530 Subject: [PATCH 132/590] Added changes to remove unwanted spaces --- .../nosuchfielderror/FieldErrorExample.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java index d2b0bccad0..a55bacab75 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java @@ -1,20 +1,20 @@ package com.baeldung.exceptions.nosuchfielderror; public class FieldErrorExample { - + public static void main(String... args) { - + fetchAndPrint(); } - + public static String getDependentMessage() { - + return Dependent.message; } - + public static void fetchAndPrint() { - + System.out.println(getDependentMessage()); } - + } \ No newline at end of file From e09ae1ff5183b59d52cd3dcfc2c795240da2691b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 6 Nov 2020 12:14:07 -0300 Subject: [PATCH 133/590] fixed tests in spring-5-reactive module --- ...g5ReactiveServerClientIntegrationTest.java | 63 +++++++------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java index b8dd9c9509..14e9ed96c0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java @@ -7,8 +7,10 @@ import java.time.Duration; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; +import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; @@ -22,6 +24,7 @@ import reactor.netty.http.server.HttpServer; public class Spring5ReactiveServerClientIntegrationTest { private static DisposableServer disposableServer; + private static WebTestClient webTestClient; @BeforeAll public static void setUp() throws Exception { @@ -37,6 +40,9 @@ public class Spring5ReactiveServerClientIntegrationTest { ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); disposableServer = server.handle(adapter) .bindNow(); + webTestClient = WebTestClient.bindToServer() + .baseUrl("http://localhost:8080") + .build(); } @AfterAll @@ -44,49 +50,22 @@ public class Spring5ReactiveServerClientIntegrationTest { disposableServer.disposeNow(); } - // @Test - // public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception { - // WebClient client = WebClient.create("http://localhost:8080"); - // Mono result = client - // .get() - // .uri("/task") - // .exchange() - // .then(response -> response.bodyToMono(String.class)); - // - // assertThat(result.block()).isInstanceOf(String.class); - // } + @Test + public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception { + webTestClient.get() + .uri("/task") + .exchange() + .expectBody(String.class); + } - // @Test - // public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception { - // URI uri = URI.create("http://localhost:8080/task/process"); - // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); - // ClientRequest request = ClientRequest - // .method(HttpMethod.POST, uri) - // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) - // .build(); - // - // Flux taskResponse = exchange - // .exchange(request) - // .flatMap(response -> response.bodyToFlux(Task.class)); - // - // assertThat(taskResponse.blockFirst()).isInstanceOf(Task.class); - // } - - // @Test - // public void givenCheckTask_whenServerHandle_thenOragicServerResponseALiveString() throws Exception { - // URI uri = URI.create("http://localhost:8080/task"); - // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); - // ClientRequest request = ClientRequest - // .method(HttpMethod.GET, uri) - // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) - // .build(); - // - // Flux taskResponse = exchange - // .exchange(request) - // .flatMap(response -> response.bodyToFlux(String.class)); - // - // assertThat(taskResponse.blockFirst()).isInstanceOf(String.class); - // } + @Test + public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception { + webTestClient.post() + .uri("/task/process") + .body(getLatLngs(), Task.class) + .exchange() + .expectBodyList(Task.class); + } private static Flux getLatLngs() { return Flux.range(0, 3) From 66860c1b03e3ed91e9be33a9968aa8b49d102566 Mon Sep 17 00:00:00 2001 From: Vishal Date: Sat, 7 Nov 2020 12:01:26 +0530 Subject: [PATCH 134/590] BAEL-4236 | delete duplicate classes --- .../CopyListUsingAddAllMethodDemo.java | 24 ------------------- ...opyListUsingCollectionsCopyMethodDemo.java | 21 ---------------- .../CopyListUsingConstructorDemo.java | 21 ---------------- .../CopyListUsingJava8StreamDemo.java | 22 ----------------- 4 files changed, 88 deletions(-) delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java deleted file mode 100644 index a7d24cdec8..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingAddAllMethodDemo.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class CopyListUsingAddAllMethodDemo { - - static List copyList(List source) { - List destination = new ArrayList<>(); - - destination.addAll(source); - - return destination; - } - - public static void main(String[] args) { - List source = Arrays.asList(11, 22, 33); - - List destination = copyList(source); - - System.out.println("copy = " + destination); - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java deleted file mode 100644 index bdf6726924..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingCollectionsCopyMethodDemo.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class CopyListUsingCollectionsCopyMethodDemo { - - static void copyList(List source, List destination) { - Collections.copy(destination, source); - } - - public static void main(String[] args) { - List source = Arrays.asList(11, 22, 33); - List destination = Arrays.asList(1, 2, 3, 4, 5); - - copyList(source, destination); - - System.out.println("copy = " + destination); - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java deleted file mode 100644 index b76a1448d4..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingConstructorDemo.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class CopyListUsingConstructorDemo { - - static List copyList(List source) { - - return new ArrayList<>(source); - } - - public static void main(String[] args) { - List source = Arrays.asList(11, 22, 33); - - List destination = copyList(source); - - System.out.println("copy = " + destination); - } -} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java deleted file mode 100644 index 81ae533505..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/CopyListUsingJava8StreamDemo.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class CopyListUsingJava8StreamDemo { - - static List copyList(List source) { - return source - .stream() - .collect(Collectors.toList()); - } - - public static void main(String[] args) { - List source = Arrays.asList(11, 22, 33); - - List destination = copyList(source); - - System.out.println("copy = " + destination); - } -} From 8ab6e4ad440423ccd6c55c9bdef5b9fc758afe14 Mon Sep 17 00:00:00 2001 From: Vishal Date: Sat, 7 Nov 2020 12:19:25 +0530 Subject: [PATCH 135/590] BAEL-4236 | delete duplicate class IndexOutOfBoundsException.java --- .../exception/IndexOutOfBoundsException.java | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java deleted file mode 100644 index a1b6bf1151..0000000000 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/IndexOutOfBoundsException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.exception; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * This example produces an IndexOutOfBoundsException, when we try to copy a list using the Collections.copy method. - * As the destination list doesn't have enough space/size to copy elements from source list. - */ -public class IndexOutOfBoundsException { - - static List copyList(List source) { - List destination = new ArrayList<>(source.size()); - Collections.copy(destination, source); - return destination; - } - - public static void main(String[] args) { - List source = Arrays.asList(1, 2, 3, 4, 5); - List copy = copyList(source); - - System.out.println("copy = " + copy); - } - -} From fe8f0c91a11d2befc2dbe7dda78be89896c70e3c Mon Sep 17 00:00:00 2001 From: Vishal Date: Sat, 7 Nov 2020 12:21:21 +0530 Subject: [PATCH 136/590] BAEL-4236 | move all classes to package com.baeldung.exception.indexoutofbounds --- .../indexoutofbounds/CopyListUsingAddAllMethodDemo.java | 2 +- .../CopyListUsingCollectionsCopyMethodDemo.java | 2 +- .../indexoutofbounds/CopyListUsingConstructorDemo.java | 2 +- .../indexoutofbounds/CopyListUsingJava8StreamDemo.java | 2 +- .../indexoutofbounds/IndexOutOfBoundsExceptionDemo.java | 2 +- .../indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java | 2 +- .../CopyListUsingCollectionsCopyMethodDemoUnitTest.java | 2 +- .../indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java | 2 +- .../indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java | 2 +- .../indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingAddAllMethodDemo.java (85%) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java (83%) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingConstructorDemo.java (80%) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingJava8StreamDemo.java (84%) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/{ => exception}/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java (87%) rename core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java (88%) rename core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java (95%) rename core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java (89%) rename core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/{ => exception}/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java (89%) rename core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/{ => exception}/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java (94%) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java similarity index 85% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java index d3e88029c9..34e6f1c998 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemo.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import java.util.ArrayList; import java.util.List; diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java similarity index 83% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java index 6f897fdfbd..664e2152d8 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import java.util.Collections; import java.util.List; diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java similarity index 80% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java index 6c6da80a46..493031ba0a 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemo.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import java.util.ArrayList; import java.util.List; diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java similarity index 84% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java index 1b5a4c2e01..d9d0247d2f 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemo.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import java.util.List; import java.util.stream.Collectors; diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java similarity index 87% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java index 3088811d60..78b7b03bc1 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import java.util.ArrayList; import java.util.Collections; diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java similarity index 88% rename from core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java rename to core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java index c16c7bca7c..204bbff696 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import org.junit.jupiter.api.Test; diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java similarity index 95% rename from core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java rename to core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java index 49d66b855c..7ebf7461a6 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import org.junit.jupiter.api.Test; diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java similarity index 89% rename from core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java rename to core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java index 9978b57ca1..cd15c5055c 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import org.junit.jupiter.api.Test; diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java similarity index 89% rename from core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java rename to core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java index 1d541b03fa..9fb8e16b2a 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import org.junit.jupiter.api.Test; diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java similarity index 94% rename from core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java rename to core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java index 6a53ce8dfc..9929fa78d3 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.indexoutofbounds; +package com.baeldung.exception.indexoutofbounds; import org.junit.jupiter.api.Test; From b4ae0bfb63ba0995b03e4db64e772619c2ff6c3d Mon Sep 17 00:00:00 2001 From: Loredana Date: Sat, 7 Nov 2020 11:57:38 +0200 Subject: [PATCH 137/590] JAVA-3498 rename test to exclude it from build temporarily --- ...ontrollerUnitTest.java => GreetingControllerManualTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/{GreetingControllerUnitTest.java => GreetingControllerManualTest.java} (99%) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerUnitTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java similarity index 99% rename from spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerUnitTest.java rename to spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java index d23ec836f9..4d3cede534 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerUnitTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java @@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.SpringRunner; @AutoConfigureTestDatabase @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class GreetingControllerUnitTest { +public class GreetingControllerManualTest { private static final String SIMPLE_GREETING = "/greeting/simple"; private static final String ADVANCED_GREETING = "/greeting/advanced"; From fa2387c8364511bd624f8516ed04b9e6f8866555 Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Sat, 7 Nov 2020 15:16:21 +0000 Subject: [PATCH 138/590] Updates to Delegated Properties article for Kotlin 1.4 (#10220) --- .../core-kotlin-lang-oop-2/pom.xml | 55 ++++++++++++++++++- .../kotlin/delegates/DelegateProviderTest.kt | 42 ++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml b/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml index f0adea121e..f952911ae1 100644 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml +++ b/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml @@ -22,4 +22,57 @@ - \ No newline at end of file + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib-common + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test-junit + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test-common + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test-annotations-common + ${kotlin.version} + + + + + + 1.4.10 + + diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt new file mode 100644 index 0000000000..2959ea0e3c --- /dev/null +++ b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt @@ -0,0 +1,42 @@ +package com.baeldung.kotlin.delegates + +import org.junit.Test +import kotlin.properties.PropertyDelegateProvider +import kotlin.reflect.KProperty +import kotlin.test.assertEquals + +class DelegateProvider(private val field: String, private val id: Int) + : PropertyDelegateProvider> { + override operator fun provideDelegate(thisRef: T, prop: KProperty<*>): DatabaseDelegate { + println("Providing delegate for field $field and ID $id") + prop.returnType.isMarkedNullable + return DatabaseDelegate(field, id) + } +} + +class DelegateProvidingUser(val id: Int) { + var name: String by DelegateProvider("name", id) + var age: Int by DelegateProvider("age", id) +} + +class DelegateProviderTest { + @Test + fun testGetKnownFields() { + val user = DelegateProvidingUser(1) + assertEquals("George", user.name) + assertEquals(4, user.age) + } + + @Test + fun testSetKnownFields() { + val user = DelegateProvidingUser(2) + user.age = 3 + assertEquals(3, user.age) + } + + @Test(expected = NoRecordFoundException::class) + fun testGetKnownField() { + val user = DelegateProvidingUser(3) + user.name + } +} From 42276ed18a21a1da2b7e3c61804f68459f4f73b0 Mon Sep 17 00:00:00 2001 From: MeenaGawande <45625809+MeenaGawande@users.noreply.github.com> Date: Sat, 7 Nov 2020 20:48:40 +0530 Subject: [PATCH 139/590] [BAEL-4556] How to Check if a Java Program Is Running in 64-Bit JVM or 32-Bit JVM (#10139) * How to Check if a Java Program Is Running in 64-Bit JVM or 32-Bit JVM How to Check if a Java Program Is Running in 64-Bit JVM or 32-Bit JVM * baeldung-articlesBAEL-4556 How can I tell if I'm running in 64-bit JVM or 32-bit JVM Changes as per review comments . 1.Package Name change 2.Variable change from static to instance 3.Test Method name change * Update JVMBitVersionUnitTest.java [BAEL-4556] How to Check if a Java Program Is Running in 64-Bit JVM or 32-Bit JVM * [BAEL-4556]Added code and Junits for JVMBitVersion * [BAEL-4556]Removed code and Junits for os.arch property to check JVMBitVersion Co-authored-by: MeenaGawande --- .../baeldung/jvmbitversion/JVMBitVersion.java | 24 ++++++++++ .../jvmbitversion/JVMBitVersionUnitTest.java | 46 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 java-native/src/main/java/com/baeldung/jvmbitversion/JVMBitVersion.java create mode 100644 java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java diff --git a/java-native/src/main/java/com/baeldung/jvmbitversion/JVMBitVersion.java b/java-native/src/main/java/com/baeldung/jvmbitversion/JVMBitVersion.java new file mode 100644 index 0000000000..63684fec49 --- /dev/null +++ b/java-native/src/main/java/com/baeldung/jvmbitversion/JVMBitVersion.java @@ -0,0 +1,24 @@ +package com.baeldung.jvmbitversion; + +import com.sun.jna.Platform; + +public class JVMBitVersion { + + public String getUsingSystemClass() { + return System.getProperty("sun.arch.data.model") + "-bit"; + } + + public String getUsingNativeClass() { + if (com.sun.jna.Native.POINTER_SIZE == 8) { + return "64-bit"; + } else if (com.sun.jna.Native.POINTER_SIZE == 4) { + return "32-bit"; + } else + return "unknown"; + } + + public boolean getUsingPlatformClass() { + return (Platform.is64Bit()); + } + +} diff --git a/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java b/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java new file mode 100644 index 0000000000..152008e5e2 --- /dev/null +++ b/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.jvmbitversion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.jvmbitversion.JVMBitVersion; +import com.sun.jna.Platform; + +public class JVMBitVersionUnitTest { + + private JVMBitVersion jvmVersion; + + @Before + public void setup() { + jvmVersion = new JVMBitVersion(); + } + + @Test + public void whenUsingSystemClass_thenOutputIsAsExpected() { + if (System.getProperty("sun.arch.data.model") == "64") { + assertEquals("64-bit", jvmVersion.getUsingSystemClass()); + } else if (System.getProperty("sun.arch.data.model") == "32") { + assertEquals("32-bit", jvmVersion.getUsingSystemClass()); + } + } + + @Test + public void whenUsingNativeClass_thenResultIsAsExpected() { + if (com.sun.jna.Native.POINTER_SIZE == 8) { + assertEquals("64-bit", jvmVersion.getUsingNativeClass()); + } else if (com.sun.jna.Native.POINTER_SIZE == 4) { + assertEquals("32-bit", jvmVersion.getUsingNativeClass()); + } + } + + @Test + public void whenUsingPlatformClass_thenResultIsAsExpected() { + if (Platform.is64Bit() == Boolean.TRUE) { + assertEquals(Boolean.TRUE, jvmVersion.getUsingPlatformClass()); + } else if (com.sun.jna.Native.POINTER_SIZE == 4) { + assertEquals(Boolean.FALSE, jvmVersion.getUsingPlatformClass()); + } + } +} From 7077a5f80cf6faf74923a4bf6c2fc42aa4bc23b3 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 8 Nov 2020 11:15:42 +0100 Subject: [PATCH 140/590] BAEL-4717: Create new collections module --- .../core-java-collections-4/README.md | 7 +++++ .../core-java-collections-4/pom.xml | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 core-java-modules/core-java-collections-4/README.md create mode 100644 core-java-modules/core-java-collections-4/pom.xml diff --git a/core-java-modules/core-java-collections-4/README.md b/core-java-modules/core-java-collections-4/README.md new file mode 100644 index 0000000000..1c680b86ba --- /dev/null +++ b/core-java-modules/core-java-collections-4/README.md @@ -0,0 +1,7 @@ +========= + +## Core Java Collections Cookbooks and Examples + +### Relevant Articles: + +- TODO: add article links here diff --git a/core-java-modules/core-java-collections-4/pom.xml b/core-java-modules/core-java-collections-4/pom.xml new file mode 100644 index 0000000000..23baa51d0d --- /dev/null +++ b/core-java-modules/core-java-collections-4/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + core-java-collections-3 + 0.1.0-SNAPSHOT + core-java-collections-3 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + 3.18.0 + + + From eb3631f36f8e6ab3728b3faffe4169988f84c914 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sun, 8 Nov 2020 13:23:31 +0100 Subject: [PATCH 141/590] BAEL-4687 Testing Kafka and Spring Boot --- spring-kafka/pom.xml | 20 ++- .../kafka/embedded/KafkaConsumer.java | 39 ++++++ .../kafka/embedded/KafkaProducer.java | 22 +++ .../KafkaProducerConsumerApplication.java | 15 ++ .../com/baeldung/SpringContextLiveTest.java | 17 --- .../com/baeldung/SpringContextManualTest.java | 17 --- .../EmbeddedKafkaIntegrationTest.java | 55 ++++++++ .../KafkaTestContainersIntegrationTest.java | 132 ++++++++++++++++++ .../src/test/resources/application.yml | 7 + spring-kafka/src/test/resources/logback.xml | 13 ++ 10 files changed, 297 insertions(+), 40 deletions(-) create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java delete mode 100644 spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java delete mode 100644 spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java create mode 100644 spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java create mode 100644 spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java create mode 100644 spring-kafka/src/test/resources/application.yml create mode 100644 spring-kafka/src/test/resources/logback.xml diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index 2b4a0914e6..3673fe8fa5 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -1,9 +1,9 @@ - + 4.0.0 spring-kafka - 0.0.1-SNAPSHOT spring-kafka Intro to Kafka with Spring @@ -15,21 +15,29 @@ - org.springframework.boot spring-boot-starter - org.springframework.kafka spring-kafka - com.fasterxml.jackson.core jackson-databind + + org.springframework.kafka + spring-kafka-test + test + + + org.testcontainers + kafka + test + 1.15.0-rc2 + diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java new file mode 100644 index 0000000000..48a194b4e3 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java @@ -0,0 +1,39 @@ +package com.baeldung.kafka.embedded; + +import java.util.concurrent.CountDownLatch; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component +public class KafkaConsumer { + + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConsumer.class); + + private CountDownLatch latch = new CountDownLatch(1); + private String payload = null; + + @KafkaListener(topics = "${test.topic}") + public void receive(ConsumerRecord consumerRecord) { + LOGGER.info("received payload='{}'", consumerRecord.toString()); + setPayload(consumerRecord.toString()); + latch.countDown(); + } + + public CountDownLatch getLatch() { + return latch; + } + + public String getPayload() { + return payload; + } + + private void setPayload(String payload) { + this.payload = payload; + } + +} diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java new file mode 100644 index 0000000000..d7cbd35011 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java @@ -0,0 +1,22 @@ +package com.baeldung.kafka.embedded; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class KafkaProducer { + + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaProducer.class); + + @Autowired + private KafkaTemplate kafkaTemplate; + + public void send(String topic, String payload) { + LOGGER.info("sending payload='{}' to topic='{}'", payload, topic); + kafkaTemplate.send(topic, payload); + } + +} diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java new file mode 100644 index 0000000000..bf14251d75 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.kafka.embedded; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class KafkaProducerConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(KafkaProducerConsumerApplication.class, args); + } + +} diff --git a/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java deleted file mode 100644 index 60262df9d4..0000000000 --- a/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.spring.kafka.KafkaApplication; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = KafkaApplication.class) -public class SpringContextLiveTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java b/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java deleted file mode 100644 index 0d2c19136f..0000000000 --- a/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.spring.kafka.KafkaApplication; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = KafkaApplication.class) -public class SpringContextManualTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java new file mode 100644 index 0000000000..49ea080369 --- /dev/null +++ b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java @@ -0,0 +1,55 @@ +package com.baeldung.kafka.embedded; + +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.concurrent.TimeUnit; + +@RunWith(SpringRunner.class) +@SpringBootTest +@DirtiesContext +@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" }) +class EmbeddedKafkaIntegrationTest { + + @Autowired + public KafkaTemplate template; + + @Autowired + private KafkaConsumer consumer; + + @Autowired + private KafkaProducer producer; + + @Value("${test.topic}") + private String topic; + + @Test + public void givenEmbeddedKafkaBroker_whenSendingtoDefaultTemplate_thenMessageReceived() throws Exception { + template.send(topic, "Sending with default template"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @Test + public void givenEmbeddedKafkaBroker_whenSendingtoSimpleProducer_thenMessageReceived() throws Exception { + producer.send(topic, "Sending with own controller"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + +} diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java new file mode 100644 index 0000000000..cf941b770f --- /dev/null +++ b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java @@ -0,0 +1,132 @@ +package com.baeldung.kafka.testcontainers; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.core.ConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaProducerFactory; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.utility.DockerImageName; + +import com.baeldung.kafka.embedded.KafkaConsumer; +import com.baeldung.kafka.embedded.KafkaProducer; +import com.baeldung.kafka.embedded.KafkaProducerConsumerApplication; + +@RunWith(SpringRunner.class) +@Import(com.baeldung.kafka.testcontainers.KafkaTestContainersIntegrationTest.KafkaTestContainersConfiguration.class) +@SpringBootTest(classes = KafkaProducerConsumerApplication.class) +@DirtiesContext +public class KafkaTestContainersIntegrationTest { + + @ClassRule + public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")); + + @Autowired + public KafkaTemplate template; + + @Autowired + private KafkaConsumer consumer; + + @Autowired + private KafkaProducer producer; + + @Value("${test.topic}") + private String topic; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + kafka.start(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + kafka.stop(); + } + + @Test + public void givenKafkaDockerContainer_whenSendingtoDefaultTemplate_thenMessageReceived() throws Exception { + template.send(topic, "Sending with default template"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @Test + public void givenKafkaDockerContainer_whenSendingtoSimpleProducer_thenMessageReceived() throws Exception { + producer.send(topic, "Sending with own controller"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @TestConfiguration + static class KafkaTestContainersConfiguration { + + @Bean + ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { + ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory()); + return factory; + } + + @Bean + public ConsumerFactory consumerFactory() { + return new DefaultKafkaConsumerFactory<>(consumerConfigs()); + } + + @Bean + public Map consumerConfigs() { + Map props = new HashMap<>(); + props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); + props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + props.put(ConsumerConfig.GROUP_ID_CONFIG, "baeldung"); + props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + return props; + } + + @Bean + public ProducerFactory producerFactory() { + Map configProps = new HashMap<>(); + configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); + configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + return new DefaultKafkaProducerFactory<>(configProps); + } + + @Bean + public KafkaTemplate kafkaTemplate() { + return new KafkaTemplate<>(producerFactory()); + } + + } + +} diff --git a/spring-kafka/src/test/resources/application.yml b/spring-kafka/src/test/resources/application.yml new file mode 100644 index 0000000000..7d7997c6fd --- /dev/null +++ b/spring-kafka/src/test/resources/application.yml @@ -0,0 +1,7 @@ +spring: + kafka: + consumer: + auto-offset-reset: earliest + group-id: baeldung +test: + topic: embedded-test-topic \ No newline at end of file diff --git a/spring-kafka/src/test/resources/logback.xml b/spring-kafka/src/test/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-kafka/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file From 937f0fb7845ccbada7924d8cc37c43db84634d32 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sun, 8 Nov 2020 17:18:20 +0330 Subject: [PATCH 142/590] Revert "update README file" This reverts commit 6f785fde --- core-java-modules/core-java-security-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index f6bc410900..03a5a94acc 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -12,5 +12,4 @@ This module contains articles about core Java Security - [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) - [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms) - [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates) -- [Java AES encryption and decryption](https://www.baeldung.com/) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From a5d7f70a5f2f14eb5ed869884ac1cb6ea72514c7 Mon Sep 17 00:00:00 2001 From: Jordan Simpson Date: Sun, 8 Nov 2020 10:34:48 -0600 Subject: [PATCH 143/590] Bael 4700 (#10231) * Added code examples from the article. * Hide the revoked token * Reduce long line break indentation to 2 spaces, change "your" to "our," and use the -LiveTest convention for the test class. * Reduce Java version from 11 to 1.8 and add the new discord4j module to the root pom. * Remove test due to context failing to start up without a valid bot token. * Replace test class and add error handling for invalid tokens. --- discord4j/.gitignore | 33 ++++++++++ discord4j/pom.xml | 63 +++++++++++++++++++ .../baeldung/discordbot/BotConfiguration.java | 48 ++++++++++++++ .../discordbot/DiscordBotApplication.java | 12 ++++ .../discordbot/events/EventListener.java | 19 ++++++ .../events/MessageCreateListener.java | 19 ++++++ .../discordbot/events/MessageListener.java | 19 ++++++ .../events/MessageUpdateListener.java | 22 +++++++ discord4j/src/main/resources/application.yml | 1 + .../discordbot/DiscordBotLiveTest.java | 12 ++++ pom.xml | 2 + 11 files changed, 250 insertions(+) create mode 100644 discord4j/.gitignore create mode 100644 discord4j/pom.xml create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/DiscordBotApplication.java create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/events/EventListener.java create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/events/MessageCreateListener.java create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/events/MessageListener.java create mode 100644 discord4j/src/main/java/com/baeldung/discordbot/events/MessageUpdateListener.java create mode 100644 discord4j/src/main/resources/application.yml create mode 100644 discord4j/src/test/java/com/baeldung/discordbot/DiscordBotLiveTest.java diff --git a/discord4j/.gitignore b/discord4j/.gitignore new file mode 100644 index 0000000000..b56f1dd0d0 --- /dev/null +++ b/discord4j/.gitignore @@ -0,0 +1,33 @@ +README.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/discord4j/pom.xml b/discord4j/pom.xml new file mode 100644 index 0000000000..7687f63ad5 --- /dev/null +++ b/discord4j/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + + + com.baeldung + discord4j-bot + 0.0.1-SNAPSHOT + discord4j-bot + Demo Discord bot using Discord4J + Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + com.discord4j + discord4j-core + 3.1.1 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + diff --git a/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java b/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java new file mode 100644 index 0000000000..a60005e9b5 --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java @@ -0,0 +1,48 @@ +package com.baeldung.discordbot; + +import com.baeldung.discordbot.events.EventListener; +import discord4j.core.DiscordClientBuilder; +import discord4j.core.GatewayDiscordClient; +import discord4j.core.event.domain.Event; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@Configuration +public class BotConfiguration { + + private static final Logger log = LoggerFactory.getLogger( BotConfiguration.class ); + + @Value("${token}") + private String token; + + @Bean + public GatewayDiscordClient gatewayDiscordClient(List> eventListeners) { + GatewayDiscordClient client = null; + + try { + client = DiscordClientBuilder.create(token) + .build() + .login() + .block(); + + for(EventListener listener : eventListeners) { + client.on(listener.getEventType()) + .flatMap(listener::execute) + .onErrorResume(listener::handleError) + .subscribe(); + } + + client.onDisconnect().block(); + } + catch ( Exception exception ) { + log.error( "Be sure to use a valid bot token!", exception ); + } + + return client; + } +} diff --git a/discord4j/src/main/java/com/baeldung/discordbot/DiscordBotApplication.java b/discord4j/src/main/java/com/baeldung/discordbot/DiscordBotApplication.java new file mode 100644 index 0000000000..069a36635c --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/DiscordBotApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.discordbot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DiscordBotApplication { + + public static void main(String[] args) { + SpringApplication.run(DiscordBotApplication.class, args); + } +} diff --git a/discord4j/src/main/java/com/baeldung/discordbot/events/EventListener.java b/discord4j/src/main/java/com/baeldung/discordbot/events/EventListener.java new file mode 100644 index 0000000000..ca4c79de0d --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/events/EventListener.java @@ -0,0 +1,19 @@ +package com.baeldung.discordbot.events; + +import discord4j.core.event.domain.Event; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; + +public interface EventListener { + + Logger LOG = LoggerFactory.getLogger(EventListener.class); + + Class getEventType(); + Mono execute(T event); + + default Mono handleError(Throwable error) { + LOG.error("Unable to process " + getEventType().getSimpleName(), error); + return Mono.empty(); + } +} diff --git a/discord4j/src/main/java/com/baeldung/discordbot/events/MessageCreateListener.java b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageCreateListener.java new file mode 100644 index 0000000000..f545489804 --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageCreateListener.java @@ -0,0 +1,19 @@ +package com.baeldung.discordbot.events; + +import discord4j.core.event.domain.message.MessageCreateEvent; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class MessageCreateListener extends MessageListener implements EventListener { + + @Override + public Class getEventType() { + return MessageCreateEvent.class; + } + + @Override + public Mono execute(MessageCreateEvent event) { + return processCommand(event.getMessage()); + } +} diff --git a/discord4j/src/main/java/com/baeldung/discordbot/events/MessageListener.java b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageListener.java new file mode 100644 index 0000000000..e1f48468be --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageListener.java @@ -0,0 +1,19 @@ +package com.baeldung.discordbot.events; + +import discord4j.core.object.entity.Message; +import reactor.core.publisher.Mono; + +public abstract class MessageListener { + + public Mono processCommand(Message eventMessage) { + return Mono.just(eventMessage) + .filter(message -> message.getAuthor().map(user -> !user.isBot()).orElse(false)) + .filter(message -> message.getContent().equalsIgnoreCase("!todo")) + .flatMap(Message::getChannel) + .flatMap(channel -> channel.createMessage("Things to do today:\n" + + " - write a bot\n" + + " - eat lunch\n" + + " - play a game")) + .then(); + } +} diff --git a/discord4j/src/main/java/com/baeldung/discordbot/events/MessageUpdateListener.java b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageUpdateListener.java new file mode 100644 index 0000000000..62802d4903 --- /dev/null +++ b/discord4j/src/main/java/com/baeldung/discordbot/events/MessageUpdateListener.java @@ -0,0 +1,22 @@ +package com.baeldung.discordbot.events; + +import discord4j.core.event.domain.message.MessageUpdateEvent; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class MessageUpdateListener extends MessageListener implements EventListener { + + @Override + public Class getEventType() { + return MessageUpdateEvent.class; + } + + @Override + public Mono execute(MessageUpdateEvent event) { + return Mono.just(event) + .filter(MessageUpdateEvent::isContentChanged) + .flatMap(MessageUpdateEvent::getMessage) + .flatMap(super::processCommand); + } +} diff --git a/discord4j/src/main/resources/application.yml b/discord4j/src/main/resources/application.yml new file mode 100644 index 0000000000..e2079e33b4 --- /dev/null +++ b/discord4j/src/main/resources/application.yml @@ -0,0 +1 @@ +token: 'our-token-here' diff --git a/discord4j/src/test/java/com/baeldung/discordbot/DiscordBotLiveTest.java b/discord4j/src/test/java/com/baeldung/discordbot/DiscordBotLiveTest.java new file mode 100644 index 0000000000..8d9a285748 --- /dev/null +++ b/discord4j/src/test/java/com/baeldung/discordbot/DiscordBotLiveTest.java @@ -0,0 +1,12 @@ +package com.baeldung.discordbot; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class DiscordBotLiveTest { + + @Test + public void contextTest() { + } +} diff --git a/pom.xml b/pom.xml index cba7e33b03..6c96d8d77e 100644 --- a/pom.xml +++ b/pom.xml @@ -397,6 +397,7 @@ ddd deeplearning4j + discord4j disruptor dozer drools @@ -909,6 +910,7 @@ ddd deeplearning4j + discord4j disruptor dozer drools From 6866b51d52b8edc4ebceb77bcbe51c8b7ae8d562 Mon Sep 17 00:00:00 2001 From: Philippe Soares Date: Sun, 8 Nov 2020 11:38:17 -0500 Subject: [PATCH 144/590] Put html and js resources back to their original location. Split backend code so it doesn't modify existing examples. Added a bots.html page for the server push version. --- .../baeldung/websockets/BotsController.java | 21 +++++ .../ReactiveScheduledPushMessages.java | 2 +- .../websockets/ScheduledPushMessages.java | 5 +- .../baeldung/websockets/WebSocketConfig.java | 2 + spring-websockets/src/main/webapp/bots.html | 88 +++++++++++++++++++ .../resources}/js/sockjs-0.3.4.js | 0 .../public => webapp/resources}/js/stomp.js | 0 .../resources}/js/webSocketSendToUserApp.js | 0 8 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 spring-websockets/src/main/java/com/baeldung/websockets/BotsController.java create mode 100644 spring-websockets/src/main/webapp/bots.html rename spring-websockets/src/main/{resources/public => webapp/resources}/js/sockjs-0.3.4.js (100%) rename spring-websockets/src/main/{resources/public => webapp/resources}/js/stomp.js (100%) rename spring-websockets/src/main/{resources/public => webapp/resources}/js/webSocketSendToUserApp.js (100%) diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/BotsController.java b/spring-websockets/src/main/java/com/baeldung/websockets/BotsController.java new file mode 100644 index 0000000000..3f268f3794 --- /dev/null +++ b/spring-websockets/src/main/java/com/baeldung/websockets/BotsController.java @@ -0,0 +1,21 @@ +package com.baeldung.websockets; + +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.stereotype.Controller; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@Controller +public class BotsController { + + @MessageMapping("/chatwithbots") + @SendTo("/topic/pushmessages") + public OutputMessage send(final Message message) throws Exception { + + final String time = new SimpleDateFormat("HH:mm").format(new Date()); + return new OutputMessage(message.getFrom(), message.getText(), time); + } + +} diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java b/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java index cfaf981d96..36b1b886fc 100644 --- a/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java +++ b/spring-websockets/src/main/java/com/baeldung/websockets/ReactiveScheduledPushMessages.java @@ -27,6 +27,6 @@ public class ReactiveScheduledPushMessages implements InitializingBean { Flux.interval(Duration.ofSeconds(4L)) .map((n) -> new OutputMessage(faker.backToTheFuture().character(), faker.backToTheFuture().quote(), new SimpleDateFormat("HH:mm").format(new Date()))) - .subscribe(message -> simpMessagingTemplate.convertAndSend("/topic/messages", message)); + .subscribe(message -> simpMessagingTemplate.convertAndSend("/topic/pushmessages", message)); } } diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java b/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java index 3e27d840d9..2468b69713 100644 --- a/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java +++ b/spring-websockets/src/main/java/com/baeldung/websockets/ScheduledPushMessages.java @@ -5,11 +5,12 @@ import com.github.javafaker.Faker; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; +import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.Date; -@Controller +@Service public class ScheduledPushMessages { private final SimpMessagingTemplate simpMessagingTemplate; @@ -24,7 +25,7 @@ public class ScheduledPushMessages { @Scheduled(fixedRate = 5000) public void sendMessage() { final String time = new SimpleDateFormat("HH:mm").format(new Date()); - simpMessagingTemplate.convertAndSend("/topic/messages", + simpMessagingTemplate.convertAndSend("/topic/pushmessages", new OutputMessage("Chuck Norris", faker.chuckNorris().fact(), time)); } diff --git a/spring-websockets/src/main/java/com/baeldung/websockets/WebSocketConfig.java b/spring-websockets/src/main/java/com/baeldung/websockets/WebSocketConfig.java index 7b53dbc3f3..6179ec9c0d 100644 --- a/spring-websockets/src/main/java/com/baeldung/websockets/WebSocketConfig.java +++ b/spring-websockets/src/main/java/com/baeldung/websockets/WebSocketConfig.java @@ -20,6 +20,8 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { public void registerStompEndpoints(final StompEndpointRegistry registry) { registry.addEndpoint("/chat"); registry.addEndpoint("/chat").withSockJS(); + registry.addEndpoint("/chatwithbots"); + registry.addEndpoint("/chatwithbots").withSockJS(); } } \ No newline at end of file diff --git a/spring-websockets/src/main/webapp/bots.html b/spring-websockets/src/main/webapp/bots.html new file mode 100644 index 0000000000..38570d420c --- /dev/null +++ b/spring-websockets/src/main/webapp/bots.html @@ -0,0 +1,88 @@ + + + Chat WebSocket + + + + + + + + + + +
+ + +
+ +
+
+
+ + +
+
+
+ + +

+
+
+ + + \ No newline at end of file diff --git a/spring-websockets/src/main/resources/public/js/sockjs-0.3.4.js b/spring-websockets/src/main/webapp/resources/js/sockjs-0.3.4.js similarity index 100% rename from spring-websockets/src/main/resources/public/js/sockjs-0.3.4.js rename to spring-websockets/src/main/webapp/resources/js/sockjs-0.3.4.js diff --git a/spring-websockets/src/main/resources/public/js/stomp.js b/spring-websockets/src/main/webapp/resources/js/stomp.js similarity index 100% rename from spring-websockets/src/main/resources/public/js/stomp.js rename to spring-websockets/src/main/webapp/resources/js/stomp.js diff --git a/spring-websockets/src/main/resources/public/js/webSocketSendToUserApp.js b/spring-websockets/src/main/webapp/resources/js/webSocketSendToUserApp.js similarity index 100% rename from spring-websockets/src/main/resources/public/js/webSocketSendToUserApp.js rename to spring-websockets/src/main/webapp/resources/js/webSocketSendToUserApp.js From 141f05d1798a03bfac8af648e9c6d80741c56bb0 Mon Sep 17 00:00:00 2001 From: Cristian Stancalau Date: Mon, 9 Nov 2020 19:16:59 +0200 Subject: [PATCH 145/590] Rename Reptile to Amphibian --- .../classcastexception/{Reptile.java => Amphibian.java} | 2 +- .../java/com/baeldung/exceptions/classcastexception/Frog.java | 2 +- .../exceptions/classcastexception/CheckedCastsUnitTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/{Reptile.java => Amphibian.java} (75%) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Reptile.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java similarity index 75% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Reptile.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java index ed4b0273e5..cb15977cf8 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Reptile.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java @@ -1,6 +1,6 @@ package com.baeldung.exceptions.classcastexception; -public class Reptile implements Animal { +public class Amphibian implements Animal { @Override public String getName() { diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java index 0a0b2d1f63..a3837f4c2f 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java @@ -1,6 +1,6 @@ package com.baeldung.exceptions.classcastexception; -public class Frog extends Reptile { +public class Frog extends Amphibian { @Override public String getName() { diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java index 7fac000fa8..8e62a10e2f 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java @@ -11,7 +11,7 @@ public class CheckedCastsUnitTest { Animal animal = new Frog(); //A checked downcast to Mammal is incompatible from Frog because Frog is not a subtype of Mammal. - Mammal mammal = (Mammal) animal; + Mammal mammal1 = (Mammal) animal; } @Test(expected = ClassCastException.class) From ef3f984d8e21eba417fd24f81db39300f5acefc7 Mon Sep 17 00:00:00 2001 From: Cristian Stancalau Date: Mon, 9 Nov 2020 19:20:38 +0200 Subject: [PATCH 146/590] Rename Reptile to Amphibian --- .../com/baeldung/exceptions/classcastexception/Amphibian.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java index cb15977cf8..f31c19bc0f 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java @@ -4,6 +4,6 @@ public class Amphibian implements Animal { @Override public String getName() { - return "Reptile"; + return "Amphibian"; } } From 5f9cf2c661972ff6261ed30b0cc6872c51f7bd72 Mon Sep 17 00:00:00 2001 From: Cristian Stancalau Date: Mon, 9 Nov 2020 19:29:12 +0200 Subject: [PATCH 147/590] Fix typo --- .../exceptions/classcastexception/CheckedCastsUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java index 8e62a10e2f..7fac000fa8 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java @@ -11,7 +11,7 @@ public class CheckedCastsUnitTest { Animal animal = new Frog(); //A checked downcast to Mammal is incompatible from Frog because Frog is not a subtype of Mammal. - Mammal mammal1 = (Mammal) animal; + Mammal mammal = (Mammal) animal; } @Test(expected = ClassCastException.class) From 95e04696e6c9e464cd849919f3e612c20dd8d33f Mon Sep 17 00:00:00 2001 From: Bradley M Handy Date: Mon, 9 Nov 2020 12:37:47 -0500 Subject: [PATCH 148/590] BAEL-4209: Difference between e.getMessage() and e.getLocalizedMessage() (#10222) * - initial commit of sample code * BAEL-4209: Moving the localized exception module into core-java-exceptions-3. * BAEL-4209: Removed the old files for localizing exception messages. --- .../localization/LocalizedException.java | 47 ++++++++++++++ .../exceptions/localization/Messages.java | 27 ++++++++ .../src/main/resources/messages.properties | 1 + .../src/main/resources/messages_fr.properties | 1 + .../LocalizedExceptionUnitTest.java | 61 +++++++++++++++++++ .../localization/MessagesUnitTest.java | 25 ++++++++ 6 files changed, 162 insertions(+) create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java create mode 100644 core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties create mode 100644 core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java create mode 100644 core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java new file mode 100644 index 0000000000..c3f9980b99 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java @@ -0,0 +1,47 @@ +package com.baeldung.exceptions.localization; + +import java.util.Locale; + +public class LocalizedException extends Exception { + + private static final long serialVersionUID = 1L; + + private final String messageKey; + private final Locale locale; + + public LocalizedException(String messageKey) { + this(messageKey, Locale.getDefault()); + } + + public LocalizedException(String messageKey, Locale locale) { + this.messageKey = messageKey; + this.locale = locale; + } + + /** + * @return a localized message based on the messageKey provided at instantiation. + */ + public String getMessage() { + + /* + * This is a deliberate role reversal of the default implementation of getLocalizedMessage. + * some logging frameworks like Log4J 1 & 2 and Logback will use getMessage instead of + * getLocalizedMessage when logging Throwables. If we want to use these frameworks in client + * applications to log localized messages, then we'll need to override getMessage in a + * similar fashion to return the appropriate content. Or, you can call getLocalizedMessage + * on your own to create the log content. + */ + return getLocalizedMessage(); + } + + /** + * @return a localized message based on the messageKey provided at instantiation. + */ + public String getLocalizedMessage() { + + /* + * java.util.logging uses getLocalizedMessage when logging Throwables. + */ + return Messages.getMessageForLocale(messageKey, locale); + } +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java new file mode 100644 index 0000000000..1079bedd1a --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java @@ -0,0 +1,27 @@ +package com.baeldung.exceptions.localization; + +import java.util.Locale; +import java.util.ResourceBundle; + +public class Messages { + + /** + * Retrieves the value for the messageKey from the locale-specific messages.properties, or from + * the base messages.properties for unsupported locales. + * + * @param messageKey The key for the message in the messages.properties ResourceBundle. + * @param locale The locale to search the message key. + * @return The value defined for the messageKey in the provided locale. + */ + public static String getMessageForLocale(String messageKey, Locale locale) { + + /* + * For more complex implementations, you will want a var-args parameter for MessageFormat + * substitutions. Then we can read the value from the bundle and pass the value with the + * substitutions to MessageFormat to create the final message value. + */ + return ResourceBundle.getBundle("messages", locale) + .getString(messageKey); + } + +} diff --git a/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties b/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties new file mode 100644 index 0000000000..b6122d7f21 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties @@ -0,0 +1 @@ +message.exception = I am an exception. \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties b/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties new file mode 100644 index 0000000000..f28e0d54ff --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties @@ -0,0 +1 @@ +message.exception = Je suis une exception. \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java new file mode 100644 index 0000000000..a46ca05d23 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.exceptions.localization; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Locale; + +import static org.assertj.core.api.Assertions.assertThat; + +public class LocalizedExceptionUnitTest { + + private Locale originalDefaultLocale; + + @Before + public void saveOriginalDefaultLocale() { + originalDefaultLocale = Locale.getDefault(); + } + + @After + public void restoreOriginalDefaultLocale() { + Locale.setDefault(originalDefaultLocale); + } + + @Test + public void givenUsEnglishDefaultLocale_whenLocalizingMessage_thenMessageComesFromDefaultMessages() { + Locale.setDefault(Locale.US); + + LocalizedException localizedException = new LocalizedException("message.exception"); + String usEnglishLocalizedExceptionMessage = localizedException.getLocalizedMessage(); + + assertThat(usEnglishLocalizedExceptionMessage).isEqualTo("I am an exception."); + } + + @Test + public void givenFranceFrenchDefaultLocale_whenLocalizingMessage_thenMessageComesFromFrenchTranslationMessages() { + Locale.setDefault(Locale.FRANCE); + + LocalizedException localizedException = new LocalizedException("message.exception"); + String franceFrenchLocalizedExceptionMessage = localizedException.getLocalizedMessage(); + + assertThat(franceFrenchLocalizedExceptionMessage).isEqualTo("Je suis une exception."); + } + + @Test + public void givenUsEnglishProvidedLocale_whenLocalizingMessage_thenMessageComesFromDefaultMessage() { + LocalizedException localizedException = new LocalizedException("message.exception", Locale.US); + String usEnglishLocalizedExceptionMessage = localizedException.getLocalizedMessage(); + + assertThat(usEnglishLocalizedExceptionMessage).isEqualTo("I am an exception."); + } + + @Test + public void givenFranceFrenchProvidedLocale_whenLocalizingMessage_thenMessageComesFromFrenchTranslationMessages() { + LocalizedException localizedException = new LocalizedException("message.exception", Locale.FRANCE); + String franceFrenchLocalizedExceptionMessage = localizedException.getLocalizedMessage(); + + assertThat(franceFrenchLocalizedExceptionMessage).isEqualTo("Je suis une exception."); + } + +} diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java new file mode 100644 index 0000000000..7a6cb8ed32 --- /dev/null +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.exceptions.localization; + +import org.junit.Test; + +import java.util.Locale; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MessagesUnitTest { + + @Test + public void givenUsEnglishLocale_whenRetrievingMessage_thenEnglishTranslationIsReturned() { + String translatedMessage = Messages.getMessageForLocale("message.exception", Locale.US); + + assertThat(translatedMessage).isEqualTo("I am an exception."); + } + + @Test + public void givenFranceFrenchLocale_whenRetrievingMessage_thenFrenchTranslationIsReturned() { + String translatedMessage = Messages.getMessageForLocale("message.exception", Locale.FRANCE); + + assertThat(translatedMessage).isEqualTo("Je suis une exception."); + } + +} From 839870d8de7c265902022a3147ca559f8c563883 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 10 Nov 2020 12:04:40 -0300 Subject: [PATCH 149/590] removed test as it's not related to any article --- ...g5ReactiveServerClientIntegrationTest.java | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java deleted file mode 100644 index 14e9ed96c0..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.reactive; - -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; - -import java.time.Duration; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; - -import com.baeldung.web.reactive.Task; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.netty.DisposableServer; -import reactor.netty.http.server.HttpServer; - -public class Spring5ReactiveServerClientIntegrationTest { - private static DisposableServer disposableServer; - private static WebTestClient webTestClient; - - @BeforeAll - public static void setUp() throws Exception { - HttpServer server = HttpServer.create() - .host("localhost") - .port(8080); - RouterFunction route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok() - .body(request.bodyToFlux(Task.class) - .map(ll -> new Task("TaskName", 1)), Task.class)) - .and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok() - .body(Mono.just("server is alive"), String.class))); - HttpHandler httpHandler = RouterFunctions.toHttpHandler(route); - ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); - disposableServer = server.handle(adapter) - .bindNow(); - webTestClient = WebTestClient.bindToServer() - .baseUrl("http://localhost:8080") - .build(); - } - - @AfterAll - public static void shutDown() { - disposableServer.disposeNow(); - } - - @Test - public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception { - webTestClient.get() - .uri("/task") - .exchange() - .expectBody(String.class); - } - - @Test - public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception { - webTestClient.post() - .uri("/task/process") - .body(getLatLngs(), Task.class) - .exchange() - .expectBodyList(Task.class); - } - - private static Flux getLatLngs() { - return Flux.range(0, 3) - .zipWith(Flux.interval(Duration.ofSeconds(1))) - .map(x -> new Task("taskname", 1)) - .doOnNext(ll -> System.out.println("Produced: {}" + ll)); - } -} From b6ef67eec731de9a3bd9c7f102dc885694f732cd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 20:11:57 +0800 Subject: [PATCH 150/590] 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 0707d0de98..78491e5bfa 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -8,4 +8,5 @@ This module contains articles about core features in the Java language - [Checking if a Class Exists in Java](https://www.baeldung.com/java-check-class-exists) - [The Difference Between a.getClass() and A.class in Java](https://www.baeldung.com/java-getclass-vs-class) - [Constants in Java: Patterns and Anti-Patterns](https://www.baeldung.com/java-constants-good-practices) +- [The transient Keyword in Java](https://www.baeldung.com/java-transient-keyword) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From f651b0f7b1274f140c8f5f786c723c41dd9d4379 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 20:13:52 +0800 Subject: [PATCH 151/590] Update README.md --- core-java-modules/core-java-string-operations-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-operations-3/README.md b/core-java-modules/core-java-string-operations-3/README.md index 4e46849c11..7f391ee056 100644 --- a/core-java-modules/core-java-string-operations-3/README.md +++ b/core-java-modules/core-java-string-operations-3/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Version Comparison in Java](https://www.baeldung.com/java-comparing-versions) +- [Java (String) or .toString()?](https://www.baeldung.com/java-string-casting-vs-tostring) From c49c7f57a31a1885081762063e854e762b64f59a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:18:12 +0800 Subject: [PATCH 152/590] Update README.md --- core-java-modules/core-java-lang-oop-types/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-oop-types/README.md b/core-java-modules/core-java-lang-oop-types/README.md index 459352c490..6c649877b3 100644 --- a/core-java-modules/core-java-lang-oop-types/README.md +++ b/core-java-modules/core-java-lang-oop-types/README.md @@ -12,3 +12,4 @@ This module contains articles about types in Java - [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values) - [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums) - [Determine if an Object is of Primitive Type](https://www.baeldung.com/java-object-primitive-type) +- [Extending Enums in Java](https://www.baeldung.com/java-extending-enums) From 7e354390a3f9bbec7b382dd990c26ca08d52f821 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:19:54 +0800 Subject: [PATCH 153/590] Update README.md --- java-native/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-native/README.md b/java-native/README.md index 2e2047924b..4f85342a38 100644 --- a/java-native/README.md +++ b/java-native/README.md @@ -6,3 +6,4 @@ This module contains articles about the Java Native Interface (JNI). - [Guide to JNI (Java Native Interface)](https://www.baeldung.com/jni) - [Using JNA to Access Native Dynamic Libraries](https://www.baeldung.com/java-jna-dynamic-libraries) +- [Check if a Java Program Is Running in 64-Bit or 32-Bit JVM](https://www.baeldung.com/java-detect-jvm-64-or-32-bit) From 398eb841ae72fdada04d8b7c6118bcac026fa145 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:22:12 +0800 Subject: [PATCH 154/590] Update README.md --- core-java-modules/core-java-functional/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-functional/README.md b/core-java-modules/core-java-functional/README.md index ff12555376..5891b4a943 100644 --- a/core-java-modules/core-java-functional/README.md +++ b/core-java-modules/core-java-functional/README.md @@ -1 +1,3 @@ ## Relevant articles: + +- [Functional Programming in Java](https://www.baeldung.com/java-functional-programming) From 8ed8319d0bc70be49152cc09fdbd9fb62f716131 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:24:16 +0800 Subject: [PATCH 155/590] 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 f136a73daf..8922c159b9 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -4,3 +4,4 @@ - [IllegalArgumentException or NullPointerException for a Null Parameter?](https://www.baeldung.com/java-illegalargumentexception-or-nullpointerexception) - [IllegalMonitorStateException in Java](https://www.baeldung.com/java-illegalmonitorstateexception) - [AbstractMethodError in Java](https://www.baeldung.com/java-abstractmethoderror) +- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) From 5534daf2d7d429a313df8ed4b62b47fa8d61842c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:24:47 +0800 Subject: [PATCH 156/590] Update README.md --- core-java-modules/core-java-10/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-10/README.md b/core-java-modules/core-java-10/README.md index 23f598b902..38b1db1c05 100644 --- a/core-java-modules/core-java-10/README.md +++ b/core-java-modules/core-java-10/README.md @@ -10,3 +10,4 @@ This module contains articles about Java 10 core features - [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler) - [Copying Sets in Java](https://www.baeldung.com/java-copy-sets) - [Converting between a List and a Set in Java](https://www.baeldung.com/convert-list-to-set-and-set-to-list) +- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) From 8cb775a82b22b7a3d98151ff171783e16d0c5027 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:30:48 +0800 Subject: [PATCH 157/590] 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 8922c159b9..f93e1a9943 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -5,3 +5,4 @@ - [IllegalMonitorStateException in Java](https://www.baeldung.com/java-illegalmonitorstateexception) - [AbstractMethodError in Java](https://www.baeldung.com/java-abstractmethoderror) - [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) +- [Localizing Exception Messages in Java](https://www.baeldung.com/java-localize-exception-messages) From c485b9b8d1817fed6b344c01deedb6cadae15b29 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:32:16 +0800 Subject: [PATCH 158/590] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index dce9c4e711..504c7ccdd0 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -5,3 +5,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. ### Relevant Articles: - [JPA Entity Equality](https://www.baeldung.com/jpa-entity-equality) +- [Ignoring Fields With the JPA @Transient Annotation](https://www.baeldung.com/jpa-transient-ignore-field) From 2715bde82a18d5810a8c4100ea4ff9724a7b6604 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Wed, 11 Nov 2020 14:51:36 -0700 Subject: [PATCH 159/590] BAEL-4663: Whats new in Java 15 --- .../main/java/whatsnew/records/Person.java | 16 ++++++++++++ .../java/whatsnew/sealedclasses/Employee.java | 13 ++++++++++ .../java/whatsnew/sealedclasses/Manager.java | 4 +++ .../java/whatsnew/sealedclasses/Person.java | 25 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java create mode 100644 core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java create mode 100644 core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java create mode 100644 core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java b/core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java new file mode 100644 index 0000000000..9d668b1f85 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java @@ -0,0 +1,16 @@ +package whatsnew.records; + +/** + * Java record with a header indicating 2 fields. + */ +public record Person(String name, int age) { + + /** + * Public constructor that does some basic validation. + */ + public Person { + if (age < 0) { + throw new IllegalArgumentException("Age cannot be negative"); + } + } +} diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java new file mode 100644 index 0000000000..72c73a4312 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java @@ -0,0 +1,13 @@ +package whatsnew.sealedclasses; + +import java.util.Date; + +public non-sealed class Employee extends Person { + + public Date getHiredDate() + { + return new Date(); + } + + +} diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java new file mode 100644 index 0000000000..043a37182a --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java @@ -0,0 +1,4 @@ +package whatsnew.sealedclasses; + +public final class Manager extends Person { +} diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java new file mode 100644 index 0000000000..a5fca45772 --- /dev/null +++ b/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java @@ -0,0 +1,25 @@ +package whatsnew.sealedclasses; + +import java.util.Date; + +public sealed class Person permits Employee, Manager +{ + /** + * Demonstration of pattern matching for instanceof + * + * @param person A Person object + * @return + */ + public static void patternMatchingDemo(Person person) + { + if(person instanceof Employee employee) + { + Date hiredDate = employee.getHiredDate(); + } + + if(person instanceof Employee employee && employee.getHiredDate() != null) + { + Date hiredDate = employee.getHiredDate(); + } + } +} From d0678c77ab9b8f439fcae7a2145c0e304ac08174 Mon Sep 17 00:00:00 2001 From: sharifi Date: Thu, 12 Nov 2020 14:06:53 +0330 Subject: [PATCH 160/590] add equals method --- .../src/main/java/com/baeldung/aes/Student.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java index be87d4b06f..6daceb3377 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java @@ -1,6 +1,7 @@ package com.baeldung.crypto; import java.io.Serializable; +import java.util.Objects; public class Student implements Serializable { private String name; @@ -26,4 +27,14 @@ public class Student implements Serializable { public void setAge(int age) { this.age = age; } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Student student = (Student) o; + return age == student.age && Objects.equals(name, student.name); + } } From 1b22786001ac7269c66e1bf57dc302831f706d9d Mon Sep 17 00:00:00 2001 From: sharifi Date: Thu, 12 Nov 2020 14:08:02 +0330 Subject: [PATCH 161/590] add clean up files improve code quality --- .../java/com/baeldung/aes/AESUtilUnitTest.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java index fd51ce6a62..ed3b5bd650 100644 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -12,13 +12,8 @@ import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; -//@SpringBootTest class AESUtilUnitTest implements WithAssertions { - @Test - void contextLoads() { - } - @Test void givenString_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException { // given @@ -41,7 +36,8 @@ class AESUtilUnitTest implements WithAssertions { SecretKey key = AESUtil.generateKey(128); String algorithm = "AES/CBC/PKCS5Padding"; IvParameterSpec ivParameterSpec = AESUtil.generateIv(); - File inputFile = Paths.get("src/test/resources/baeldung.txt").toFile(); + File inputFile = Paths.get("src/test/resources/baeldung.txt") + .toFile(); File encryptedFile = new File("classpath:baeldung.encrypted"); File decryptedFile = new File("document.decrypted"); @@ -51,6 +47,8 @@ class AESUtilUnitTest implements WithAssertions { // then assertThat(inputFile).hasSameTextualContentAs(decryptedFile); + encryptedFile.delete(); + decryptedFile.delete(); } @Test @@ -66,7 +64,7 @@ class AESUtilUnitTest implements WithAssertions { Student object = (Student) AESUtil.decryptObject(algorithm, sealedObject, key, ivParameterSpec); // then - assertThat(student).isEqualToComparingFieldByField(object); + assertThat(student).isEqualTo(object); } @Test @@ -76,7 +74,7 @@ class AESUtilUnitTest implements WithAssertions { String password = "baeldung"; String salt = "12345678"; IvParameterSpec ivParameterSpec = AESUtil.generateIv(); - SecretKey key = AESUtil.getKeyFromPassword(password,salt); + SecretKey key = AESUtil.getKeyFromPassword(password, salt); // when String cipherText = AESUtil.encryptPasswordBased(plainText, key, ivParameterSpec); @@ -86,4 +84,3 @@ class AESUtilUnitTest implements WithAssertions { Assertions.assertEquals(plainText, decryptedCipherText); } } - From b0d7dd8359421468402776703be13a985c0c0b6f Mon Sep 17 00:00:00 2001 From: sharifi Date: Thu, 12 Nov 2020 14:08:44 +0330 Subject: [PATCH 162/590] edit logger code improve code quality --- .../main/java/com/baeldung/aes/AESUtil.java | 125 ++++++++++-------- 1 file changed, 73 insertions(+), 52 deletions(-) diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java index c4568623d0..e8b75ccc79 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java @@ -3,11 +3,22 @@ package com.baeldung.crypto; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.crypto.*; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.BadPaddingException; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKeyFactory; +import javax.crypto.SealedObject; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.Serializable; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -17,18 +28,19 @@ import java.security.spec.KeySpec; import java.util.Base64; public class AESUtil { - static Logger logger = LoggerFactory.getLogger(AESUtil.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AESUtil.class); public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) { try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key, iv); byte[] cipherText = cipher.doFinal(input.getBytes()); - return Base64.getEncoder().encodeToString(cipherText); - } catch (NoSuchAlgorithmException | NoSuchPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | IllegalBlockSizeException | BadPaddingException exp) { - logger.error(exp.getMessage()); + return Base64.getEncoder() + .encodeToString(cipherText); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + IllegalBlockSizeException | BadPaddingException exp) { + LOGGER.error(exp.getMessage()); } return null; } @@ -37,12 +49,13 @@ public class AESUtil { try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key, iv); - byte[] plainText = cipher.doFinal(Base64.getDecoder().decode(cipherText)); + byte[] plainText = cipher.doFinal(Base64.getDecoder() + .decode(cipherText)); return new String(plainText); - } catch (NoSuchAlgorithmException | NoSuchPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | IllegalBlockSizeException | BadPaddingException exp) { - logger.error(exp.getMessage()); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + IllegalBlockSizeException | BadPaddingException exp) { + LOGGER.error(exp.getMessage()); } return null; } @@ -55,10 +68,11 @@ public class AESUtil { } public static SecretKey getKeyFromPassword(String password, String salt) - throws NoSuchAlgorithmException, InvalidKeySpecException { + throws NoSuchAlgorithmException, InvalidKeySpecException { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 65536, 256); - SecretKey secret = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); + SecretKey secret = new SecretKeySpec(factory.generateSecret(spec) + .getEncoded(), "AES"); return secret; } @@ -68,13 +82,15 @@ public class AESUtil { return new IvParameterSpec(iv); } - public static void encryptFile(String algorithm, SecretKey key, IvParameterSpec iv - , File inputFile, File outputFile) throws IOException { + public static void encryptFile(String algorithm, SecretKey key, IvParameterSpec iv, + File inputFile, File outputFile) throws IOException { + FileInputStream inputStream = null; + FileOutputStream outputStream = null; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key, iv); - FileInputStream inputStream = new FileInputStream(inputFile); - FileOutputStream outputStream = new FileOutputStream(outputFile); + inputStream = new FileInputStream(inputFile); + outputStream = new FileOutputStream(outputFile); byte[] buffer = new byte[64]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { @@ -87,22 +103,25 @@ public class AESUtil { if (outputBytes != null) { outputStream.write(outputBytes); } + } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | + NoSuchPaddingException | BadPaddingException | + IllegalBlockSizeException | InvalidKeyException exp) { + LOGGER.error(exp.getMessage()); + } finally { inputStream.close(); outputStream.close(); - } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException - | NoSuchPaddingException | BadPaddingException - | IllegalBlockSizeException | InvalidKeyException exp) { - logger.error(exp.getMessage()); } } - public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv - , File encryptedFile, File decryptedFile) throws IOException { + public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv, + File encryptedFile, File decryptedFile) throws IOException { + FileInputStream inputStream = null; + FileOutputStream outputStream = null; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key, iv); - FileInputStream inputStream = new FileInputStream(encryptedFile); - FileOutputStream outputStream = new FileOutputStream(decryptedFile); + inputStream = new FileInputStream(encryptedFile); + outputStream = new FileOutputStream(decryptedFile); byte[] buffer = new byte[64]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { @@ -115,12 +134,13 @@ public class AESUtil { if (output != null) { outputStream.write(output); } + } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | + NoSuchPaddingException | BadPaddingException | + IllegalBlockSizeException | InvalidKeyException exp) { + LOGGER.error(exp.getMessage()); + } finally { inputStream.close(); outputStream.close(); - } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException - | NoSuchPaddingException | BadPaddingException - | IllegalBlockSizeException | InvalidKeyException exp) { - logger.error(exp.getMessage()); } } @@ -130,26 +150,25 @@ public class AESUtil { cipher.init(Cipher.ENCRYPT_MODE, key, iv); SealedObject sealedObject = new SealedObject(object, cipher); return sealedObject; - } catch (NoSuchAlgorithmException | NoSuchPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | IOException | IllegalBlockSizeException exp) { - logger.error(exp.getMessage()); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + IOException | IllegalBlockSizeException exp) { + LOGGER.error(exp.getMessage()); } return null; } - public static Serializable decryptObject(String algorithm, SealedObject sealedObject - , SecretKey key, IvParameterSpec iv) { + public static Serializable decryptObject(String algorithm, SealedObject sealedObject, + SecretKey key, IvParameterSpec iv) { try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key, iv); Serializable unsealObject = (Serializable) sealedObject.getObject(cipher); return unsealObject; - } catch (NoSuchAlgorithmException | NoSuchPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | IOException | ClassNotFoundException | IllegalBlockSizeException - | BadPaddingException exp) { - logger.error(exp.getMessage()); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + IOException | ClassNotFoundException | IllegalBlockSizeException | BadPaddingException exp) { + LOGGER.error(exp.getMessage()); } return null; } @@ -158,11 +177,12 @@ public class AESUtil { try { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, iv); - return Base64.getEncoder().encodeToString(cipher.doFinal(plainText.getBytes())); - } catch (NoSuchAlgorithmException | BadPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | NoSuchPaddingException | IllegalBlockSizeException exp) { - logger.error(exp.getMessage()); + return Base64.getEncoder() + .encodeToString(cipher.doFinal(plainText.getBytes())); + } catch (NoSuchAlgorithmException | BadPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + NoSuchPaddingException | IllegalBlockSizeException exp) { + LOGGER.error(exp.getMessage()); } return null; } @@ -171,11 +191,12 @@ public class AESUtil { try { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, key, iv); - return new String(cipher.doFinal(Base64.getDecoder().decode(cipherText))); - } catch (NoSuchAlgorithmException | BadPaddingException - | InvalidKeyException | InvalidAlgorithmParameterException - | NoSuchPaddingException | IllegalBlockSizeException exp) { - logger.error(exp.getMessage()); + return new String(cipher.doFinal(Base64.getDecoder() + .decode(cipherText))); + } catch (NoSuchAlgorithmException | BadPaddingException | + InvalidKeyException | InvalidAlgorithmParameterException | + NoSuchPaddingException | IllegalBlockSizeException exp) { + LOGGER.error(exp.getMessage()); } return null; } From 85db5610eadd98879acd49ad8c12fee21cfad037 Mon Sep 17 00:00:00 2001 From: Harihar Das Date: Thu, 12 Nov 2020 21:22:06 +0100 Subject: [PATCH 163/590] [KTLN-3] Fix package name (#10246) --- .../com/baeldung/{channles => channels}/BufferedChannel.kt | 2 +- .../com/baeldung/{channles => channels}/ConflatedChannel.kt | 2 +- .../com/baeldung/{channles => channels}/PizzaPipeline.kt | 4 ++-- .../com/baeldung/{channles => channels}/ProducerConsumer.kt | 2 +- .../com/baeldung/{channles => channels}/RendezvousChannel.kt | 2 +- .../{channles => channels}/SeveralProducersOneConsumer.kt | 2 +- .../{channles => channels}/SingleProducerSeveralConsumers.kt | 2 +- .../com/baeldung/{channles => channels}/TickerChannel.kt | 2 +- .../com/baeldung/{channles => channels}/UnlimitedChannel.kt | 2 +- .../main/kotlin/com/baeldung/{channles => channels}/logger.kt | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/BufferedChannel.kt (95%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/ConflatedChannel.kt (95%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/PizzaPipeline.kt (94%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/ProducerConsumer.kt (95%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/RendezvousChannel.kt (94%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/SeveralProducersOneConsumer.kt (96%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/SingleProducerSeveralConsumers.kt (95%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/TickerChannel.kt (94%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/UnlimitedChannel.kt (95%) rename core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/{channles => channels}/logger.kt (82%) diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt similarity index 95% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt index 6cfaf5b496..5fefc2f95e 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/BufferedChannel.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.channels.Channel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt similarity index 95% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt index 63b0b967c1..6225eeb107 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ConflatedChannel.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.channels.Channel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt similarity index 94% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt index ff4dcb2d32..abc8be4d18 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/PizzaPipeline.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt @@ -1,6 +1,6 @@ -package com.baeldung.channles +package com.baeldung.channels -import com.baeldung.channles.OrderStatus.* +import com.baeldung.channels.OrderStatus.* import kotlinx.coroutines.* import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.produce diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt similarity index 95% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt index 50687b909a..37f3c7d7bb 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/ProducerConsumer.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt similarity index 94% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt index e046e86e29..d4b554bced 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/RendezvousChannel.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt similarity index 96% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt index fd2c046f97..5ed95debe8 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SeveralProducersOneConsumer.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.channels.Channel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt similarity index 95% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt index bff1609b35..f8f7b4b23b 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/SingleProducerSeveralConsumers.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.* import kotlinx.coroutines.channels.ReceiveChannel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt similarity index 94% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt index febcbd1534..85c0dc8d04 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/TickerChannel.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.channels.ticker import kotlinx.coroutines.delay diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt similarity index 95% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt index 9b01bcee54..e4725ca903 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/UnlimitedChannel.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.channels.Channel diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt similarity index 82% rename from core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt rename to core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt index fdc4c295f8..036a6a4504 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channles/logger.kt +++ b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt @@ -1,4 +1,4 @@ -package com.baeldung.channles +package com.baeldung.channels import java.text.SimpleDateFormat import java.util.* From a51e034186bc8f730dbfbe9cc2230ccf7a47606a Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Fri, 13 Nov 2020 16:42:33 +0100 Subject: [PATCH 164/590] BAEL-4609 - Testing Kafka and Spring Boot --- spring-kafka/pom.xml | 7 +++++-- .../EmbeddedKafkaIntegrationTest.java | 21 ++++++++----------- .../KafkaTestContainersIntegrationTest.java | 12 ----------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index 3673fe8fa5..235dd75966 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -22,6 +22,7 @@ org.springframework.kafka spring-kafka + ${spring-kafka.version} com.fasterxml.jackson.core @@ -30,18 +31,20 @@ org.springframework.kafka spring-kafka-test + ${spring-kafka.version} test org.testcontainers kafka + ${testcontainers-kafka.version} test - 1.15.0-rc2 - 2.3.7.RELEASE + 2.5.8.RELEASE + 1.15.0
\ No newline at end of file diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java index 49ea080369..4c727795c4 100644 --- a/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java +++ b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java @@ -1,22 +1,19 @@ package com.baeldung.kafka.embedded; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.kafka.test.context.EmbeddedKafka; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import java.util.concurrent.TimeUnit; -@RunWith(SpringRunner.class) +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.test.annotation.DirtiesContext; + @SpringBootTest @DirtiesContext @EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" }) @@ -45,7 +42,7 @@ class EmbeddedKafkaIntegrationTest { @Test public void givenEmbeddedKafkaBroker_whenSendingtoSimpleProducer_thenMessageReceived() throws Exception { - producer.send(topic, "Sending with own controller"); + producer.send(topic, "Sending with our own simple KafkaProducer"); consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); assertThat(consumer.getLatch().getCount(), equalTo(0L)); diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java index cf941b770f..972b6cce4d 100644 --- a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java +++ b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java @@ -12,8 +12,6 @@ import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.common.serialization.StringSerializer; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; @@ -59,16 +57,6 @@ public class KafkaTestContainersIntegrationTest { @Value("${test.topic}") private String topic; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - kafka.start(); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - kafka.stop(); - } - @Test public void givenKafkaDockerContainer_whenSendingtoDefaultTemplate_thenMessageReceived() throws Exception { template.send(topic, "Sending with default template"); From 9bce552d6d369ab24a3acaf72889fd78f3d9b53a Mon Sep 17 00:00:00 2001 From: Mateusz Szablak Date: Fri, 13 Nov 2020 19:25:15 +0100 Subject: [PATCH 165/590] BAEL-4723 Defining Indexes in JPA (#10247) * BAEL-4723 Defining Indexes in JPA * unit -> integration test Co-authored-by: mateusz.szablak --- .../java/com/baeldung/jpa/index/Student.java | 70 +++++++++++++++++++ .../main/resources/META-INF/persistence.xml | 15 ++++ .../java-jpa-3/src/main/resources/logback.xml | 2 +- .../jpa/index/IndexIntegrationTest.java | 50 +++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/index/IndexIntegrationTest.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java new file mode 100644 index 0000000000..0a77cfbc9e --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java @@ -0,0 +1,70 @@ +package com.baeldung.jpa.index; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.Table; +import java.io.Serializable; +import java.util.Objects; + +@Entity +@Table(indexes = { + @Index(columnList = "firstName"), + @Index(name = "fn_index", columnList = "id"), + @Index(name = "multiIndex1", columnList = "firstName, lastName"), + @Index(name = "multiIndex2", columnList = "lastName, firstName"), + @Index(name = "multiSortIndex", columnList = "firstName, lastName DESC"), + @Index(name = "uniqueIndex", columnList = "firstName", unique = true), + @Index(name = "uniqueMultiIndex", columnList = "firstName, lastName", unique = true) +}) +public class Student implements Serializable { + @Id + @GeneratedValue + private Long id; + private String firstName; + private String lastName; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Student student = (Student) o; + return Objects.equals(id, student.id) && + Objects.equals(firstName, student.firstName) && + Objects.equals(lastName, student.lastName); + } + + @Override + public int hashCode() { + return Objects.hash(id, firstName, lastName); + } +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 88378bd8db..8fe3a8bbf1 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -40,4 +40,19 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.index.Student + true + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/main/resources/logback.xml b/persistence-modules/java-jpa-3/src/main/resources/logback.xml index 2527fea245..8000740dd1 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/logback.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/logback.xml @@ -8,7 +8,7 @@ - + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/index/IndexIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/index/IndexIntegrationTest.java new file mode 100644 index 0000000000..f59450567b --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/index/IndexIntegrationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.jpa.index; + +import org.hibernate.exception.ConstraintViolationException; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.util.Optional; + +public class IndexIntegrationTest { + private static EntityManagerFactory factory; + private static EntityManager entityManager; + + @BeforeClass + public static void setup() { + factory = Persistence.createEntityManagerFactory("jpa-index"); + entityManager = factory.createEntityManager(); + } + + @Test + public void givenStudent_whenPersistStudentWithSameFirstName_thenConstraintViolationException() { + Student student = new Student(); + student.setFirstName("FirstName"); + student.setLastName("LastName"); + + Student student2 = new Student(); + student2.setFirstName("FirstName"); + student2.setLastName("LastName2"); + + entityManager.getTransaction().begin(); + entityManager.persist(student); + entityManager.getTransaction().commit(); + + Assert.assertEquals(1L, (long) student.getId()); + + entityManager.getTransaction().begin(); + try { + entityManager.persist(student2); + entityManager.getTransaction().commit(); + Assert.fail("Should raise an exception - unique key violation"); + } catch (Exception ex) { + Assert.assertTrue(Optional.of(ex).map(Throwable::getCause).map(Throwable::getCause).filter(x -> x instanceof ConstraintViolationException).isPresent()); + } finally { + entityManager.getTransaction().rollback(); + } + } +} From cfb424f9d10b550856e1588def0d0e2c4af1b2d3 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Fri, 13 Nov 2020 19:31:59 +0100 Subject: [PATCH 166/590] BAEL-4609 - Testing Kafka and Spring Boot (#10249) * BAEL-4437 - System Rules * BAEL-4687 Testing Kafka and Spring Boot * BAEL-4609 - Testing Kafka and Spring Boot Co-authored-by: Jonathan Cook --- spring-kafka/pom.xml | 25 +++- .../kafka/embedded/KafkaConsumer.java | 39 ++++++ .../kafka/embedded/KafkaProducer.java | 22 ++++ .../KafkaProducerConsumerApplication.java | 15 +++ .../com/baeldung/SpringContextLiveTest.java | 17 --- .../com/baeldung/SpringContextManualTest.java | 17 --- .../EmbeddedKafkaIntegrationTest.java | 52 ++++++++ .../KafkaTestContainersIntegrationTest.java | 120 ++++++++++++++++++ .../src/test/resources/application.yml | 7 + spring-kafka/src/test/resources/logback.xml | 13 ++ 10 files changed, 286 insertions(+), 41 deletions(-) create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java create mode 100644 spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java delete mode 100644 spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java delete mode 100644 spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java create mode 100644 spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java create mode 100644 spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java create mode 100644 spring-kafka/src/test/resources/application.yml create mode 100644 spring-kafka/src/test/resources/logback.xml diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index 2b4a0914e6..235dd75966 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -1,9 +1,9 @@ - + 4.0.0 spring-kafka - 0.0.1-SNAPSHOT spring-kafka Intro to Kafka with Spring @@ -15,25 +15,36 @@ - org.springframework.boot spring-boot-starter - org.springframework.kafka spring-kafka + ${spring-kafka.version} - com.fasterxml.jackson.core jackson-databind + + org.springframework.kafka + spring-kafka-test + ${spring-kafka.version} + test + + + org.testcontainers + kafka + ${testcontainers-kafka.version} + test + - 2.3.7.RELEASE + 2.5.8.RELEASE + 1.15.0 \ No newline at end of file diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java new file mode 100644 index 0000000000..48a194b4e3 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaConsumer.java @@ -0,0 +1,39 @@ +package com.baeldung.kafka.embedded; + +import java.util.concurrent.CountDownLatch; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component +public class KafkaConsumer { + + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConsumer.class); + + private CountDownLatch latch = new CountDownLatch(1); + private String payload = null; + + @KafkaListener(topics = "${test.topic}") + public void receive(ConsumerRecord consumerRecord) { + LOGGER.info("received payload='{}'", consumerRecord.toString()); + setPayload(consumerRecord.toString()); + latch.countDown(); + } + + public CountDownLatch getLatch() { + return latch; + } + + public String getPayload() { + return payload; + } + + private void setPayload(String payload) { + this.payload = payload; + } + +} diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java new file mode 100644 index 0000000000..d7cbd35011 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducer.java @@ -0,0 +1,22 @@ +package com.baeldung.kafka.embedded; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class KafkaProducer { + + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaProducer.class); + + @Autowired + private KafkaTemplate kafkaTemplate; + + public void send(String topic, String payload) { + LOGGER.info("sending payload='{}' to topic='{}'", payload, topic); + kafkaTemplate.send(topic, payload); + } + +} diff --git a/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java new file mode 100644 index 0000000000..bf14251d75 --- /dev/null +++ b/spring-kafka/src/main/java/com/baeldung/kafka/embedded/KafkaProducerConsumerApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.kafka.embedded; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class KafkaProducerConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(KafkaProducerConsumerApplication.class, args); + } + +} diff --git a/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java deleted file mode 100644 index 60262df9d4..0000000000 --- a/spring-kafka/src/test/java/com/baeldung/SpringContextLiveTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.spring.kafka.KafkaApplication; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = KafkaApplication.class) -public class SpringContextLiveTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java b/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java deleted file mode 100644 index 0d2c19136f..0000000000 --- a/spring-kafka/src/test/java/com/baeldung/SpringContextManualTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.spring.kafka.KafkaApplication; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = KafkaApplication.class) -public class SpringContextManualTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java new file mode 100644 index 0000000000..4c727795c4 --- /dev/null +++ b/spring-kafka/src/test/java/com/baeldung/kafka/embedded/EmbeddedKafkaIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.kafka.embedded; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.test.annotation.DirtiesContext; + +@SpringBootTest +@DirtiesContext +@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" }) +class EmbeddedKafkaIntegrationTest { + + @Autowired + public KafkaTemplate template; + + @Autowired + private KafkaConsumer consumer; + + @Autowired + private KafkaProducer producer; + + @Value("${test.topic}") + private String topic; + + @Test + public void givenEmbeddedKafkaBroker_whenSendingtoDefaultTemplate_thenMessageReceived() throws Exception { + template.send(topic, "Sending with default template"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @Test + public void givenEmbeddedKafkaBroker_whenSendingtoSimpleProducer_thenMessageReceived() throws Exception { + producer.send(topic, "Sending with our own simple KafkaProducer"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + +} diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java new file mode 100644 index 0000000000..972b6cce4d --- /dev/null +++ b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java @@ -0,0 +1,120 @@ +package com.baeldung.kafka.testcontainers; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.core.ConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaProducerFactory; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.utility.DockerImageName; + +import com.baeldung.kafka.embedded.KafkaConsumer; +import com.baeldung.kafka.embedded.KafkaProducer; +import com.baeldung.kafka.embedded.KafkaProducerConsumerApplication; + +@RunWith(SpringRunner.class) +@Import(com.baeldung.kafka.testcontainers.KafkaTestContainersIntegrationTest.KafkaTestContainersConfiguration.class) +@SpringBootTest(classes = KafkaProducerConsumerApplication.class) +@DirtiesContext +public class KafkaTestContainersIntegrationTest { + + @ClassRule + public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")); + + @Autowired + public KafkaTemplate template; + + @Autowired + private KafkaConsumer consumer; + + @Autowired + private KafkaProducer producer; + + @Value("${test.topic}") + private String topic; + + @Test + public void givenKafkaDockerContainer_whenSendingtoDefaultTemplate_thenMessageReceived() throws Exception { + template.send(topic, "Sending with default template"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @Test + public void givenKafkaDockerContainer_whenSendingtoSimpleProducer_thenMessageReceived() throws Exception { + producer.send(topic, "Sending with own controller"); + consumer.getLatch().await(10000, TimeUnit.MILLISECONDS); + + assertThat(consumer.getLatch().getCount(), equalTo(0L)); + assertThat(consumer.getPayload(), containsString("embedded-test-topic")); + } + + @TestConfiguration + static class KafkaTestContainersConfiguration { + + @Bean + ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { + ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory()); + return factory; + } + + @Bean + public ConsumerFactory consumerFactory() { + return new DefaultKafkaConsumerFactory<>(consumerConfigs()); + } + + @Bean + public Map consumerConfigs() { + Map props = new HashMap<>(); + props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); + props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + props.put(ConsumerConfig.GROUP_ID_CONFIG, "baeldung"); + props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + return props; + } + + @Bean + public ProducerFactory producerFactory() { + Map configProps = new HashMap<>(); + configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); + configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + return new DefaultKafkaProducerFactory<>(configProps); + } + + @Bean + public KafkaTemplate kafkaTemplate() { + return new KafkaTemplate<>(producerFactory()); + } + + } + +} diff --git a/spring-kafka/src/test/resources/application.yml b/spring-kafka/src/test/resources/application.yml new file mode 100644 index 0000000000..7d7997c6fd --- /dev/null +++ b/spring-kafka/src/test/resources/application.yml @@ -0,0 +1,7 @@ +spring: + kafka: + consumer: + auto-offset-reset: earliest + group-id: baeldung +test: + topic: embedded-test-topic \ No newline at end of file diff --git a/spring-kafka/src/test/resources/logback.xml b/spring-kafka/src/test/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-kafka/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file From 810736bf23364c4983177b1fe9a33a7bc4ab7e6b Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sat, 14 Nov 2020 00:28:03 +0100 Subject: [PATCH 167/590] BAEL-3565: Using enums in JPQL examples (#10248) --- .../baeldung/jpa/enums/ArticleUnitTest.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/enums/ArticleUnitTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/enums/ArticleUnitTest.java index 82f3abc04d..9d98d6b86f 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/enums/ArticleUnitTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/enums/ArticleUnitTest.java @@ -7,7 +7,9 @@ import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; +import javax.persistence.TypedQuery; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -19,7 +21,7 @@ public class ArticleUnitTest { @BeforeClass public static void setup() { - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put("hibernate.show_sql", "true"); properties.put("hibernate.format_sql", "true"); emFactory = Persistence.createEntityManagerFactory("jpa-h2", properties); @@ -115,4 +117,53 @@ public class ArticleUnitTest { assertEquals(Category.MUSIC, persistedArticle.getCategory()); } + @Test + public void shouldFindArticleByCategory() { + // given + Article article = new Article(); + article.setId(5); + article.setTitle("static"); + article.setCategory(Category.SPORT); + + EntityTransaction tx = em.getTransaction(); + tx.begin(); + em.persist(article); + tx.commit(); + + String jpql = "select a from Article a where a.category = com.baeldung.jpa.enums.Category.SPORT"; + + // when + List
articles = em.createQuery(jpql, Article.class).getResultList(); + + // then + assertEquals(1, articles.size()); + assertEquals(Category.SPORT, articles.get(0).getCategory()); + assertEquals("static", articles.get(0).getTitle()); + } + + @Test + public void shouldFindArticleByCategoryParameter() { + // given + Article article = new Article(); + article.setId(6); + article.setTitle("dynamic"); + article.setCategory(Category.TECHNOLOGY); + + EntityTransaction tx = em.getTransaction(); + tx.begin(); + em.persist(article); + tx.commit(); + + String jpql = "select a from Article a where a.category = :category"; + + // when + TypedQuery
query = em.createQuery(jpql, Article.class); + query.setParameter("category", Category.TECHNOLOGY); + List
articles = query.getResultList(); + + // then + assertEquals(1, articles.size()); + assertEquals(Category.TECHNOLOGY, articles.get(0).getCategory()); + assertEquals("dynamic", articles.get(0).getTitle()); + } } \ No newline at end of file From 05dbe85de9d534ac00f76ce5c6efbed780061e54 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Nov 2020 11:21:32 +0200 Subject: [PATCH 168/590] Update pom.xml --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c96d8d77e..db16e6897d 100644 --- a/pom.xml +++ b/pom.xml @@ -1473,7 +1473,6 @@ 1.6.0 1.8 1.2.17 - 1.1 2.1.0.1 1.19 1.19 From b610c4d30444a6f2b211605076ea9b324091334f Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sat, 14 Nov 2020 12:03:06 -0700 Subject: [PATCH 169/590] BAEL-4663: Rename packages --- core-java-modules/core-java-15/pom.xml | 4 ++-- .../main/java/{ => com/baeldung}/whatsnew/records/Person.java | 2 +- .../{ => com/baeldung}/whatsnew/sealedclasses/Employee.java | 2 +- .../{ => com/baeldung}/whatsnew/sealedclasses/Manager.java | 2 +- .../{ => com/baeldung}/whatsnew/sealedclasses/Person.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename core-java-modules/core-java-15/src/main/java/{ => com/baeldung}/whatsnew/records/Person.java (88%) rename core-java-modules/core-java-15/src/main/java/{ => com/baeldung}/whatsnew/sealedclasses/Employee.java (76%) rename core-java-modules/core-java-15/src/main/java/{ => com/baeldung}/whatsnew/sealedclasses/Manager.java (51%) rename core-java-modules/core-java-15/src/main/java/{ => com/baeldung}/whatsnew/sealedclasses/Person.java (92%) diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index c6f1454078..df8aeafca9 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -51,8 +51,8 @@ ${maven.compiler.release} --enable-preview - 15 - 15 + 14 + 14 diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java similarity index 88% rename from core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java rename to core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java index 9d668b1f85..e59fa86ed6 100644 --- a/core-java-modules/core-java-15/src/main/java/whatsnew/records/Person.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java @@ -1,4 +1,4 @@ -package whatsnew.records; +package com.baeldung.whatsnew.records; /** * Java record with a header indicating 2 fields. diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java similarity index 76% rename from core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java rename to core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java index 72c73a4312..e9a2e25417 100644 --- a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Employee.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java @@ -1,4 +1,4 @@ -package whatsnew.sealedclasses; +package com.baeldung.whatsnew.sealedclasses; import java.util.Date; diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java similarity index 51% rename from core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java rename to core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java index 043a37182a..79c50b057e 100644 --- a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Manager.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java @@ -1,4 +1,4 @@ -package whatsnew.sealedclasses; +package com.baeldung.whatsnew.sealedclasses; public final class Manager extends Person { } diff --git a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java similarity index 92% rename from core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java rename to core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java index a5fca45772..d4beb64867 100644 --- a/core-java-modules/core-java-15/src/main/java/whatsnew/sealedclasses/Person.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java @@ -1,4 +1,4 @@ -package whatsnew.sealedclasses; +package com.baeldung.whatsnew.sealedclasses; import java.util.Date; From cc0e244ce4b2f67972ffced007cc0a04390ea2a0 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sun, 15 Nov 2020 15:00:16 +0530 Subject: [PATCH 170/590] JAVA-2423 Move/rename module spring-rest-compress - Removing spring-rest-compress module as its contents have been moved to spring-resttemplate-2 --- pom.xml | 2 - spring-rest-compress/README.md | 6 -- spring-rest-compress/pom.xml | 65 ------------------- ...mpressingClientHttpRequestInterceptor.java | 38 ----------- .../spring/rest/compress/GzipUtils.java | 52 --------------- .../compress/JettyWebServerConfiguration.java | 38 ----------- .../spring/rest/compress/Message.java | 29 --------- .../rest/compress/MessageController.java | 38 ----------- .../compress/RestTemplateConfiguration.java | 21 ------ .../SpringCompressRequestApplication.java | 15 ----- .../rest/compress/GzipUtilsUnitTest.java | 19 ------ .../compress/MessageControllerUnitTest.java | 56 ---------------- 12 files changed, 379 deletions(-) delete mode 100644 spring-rest-compress/README.md delete mode 100644 spring-rest-compress/pom.xml delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/CompressingClientHttpRequestInterceptor.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/GzipUtils.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/JettyWebServerConfiguration.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/Message.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/MessageController.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/RestTemplateConfiguration.java delete mode 100644 spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/SpringCompressRequestApplication.java delete mode 100644 spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/GzipUtilsUnitTest.java delete mode 100644 spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/MessageControllerUnitTest.java diff --git a/pom.xml b/pom.xml index 6c96d8d77e..82e242b9af 100644 --- a/pom.xml +++ b/pom.xml @@ -697,7 +697,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-compress spring-rest-http spring-rest-http-2 spring-rest-query-language @@ -1200,7 +1199,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-compress spring-rest-http spring-rest-query-language spring-rest-shell diff --git a/spring-rest-compress/README.md b/spring-rest-compress/README.md deleted file mode 100644 index ce627d8595..0000000000 --- a/spring-rest-compress/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Spring REST Compress - -This module contains articles about request compression with Spring - -### Relevant Articles: -- [How to compress requests using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) diff --git a/spring-rest-compress/pom.xml b/spring-rest-compress/pom.xml deleted file mode 100644 index 9ff0be9682..0000000000 --- a/spring-rest-compress/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - 4.0.0 - spring-rest-compress - 0.0.1-SNAPSHOT - spring-rest-compress - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - org.springframework.boot - spring-boot-starter-jetty - - - - org.apache.httpcomponents - httpclient - - - - commons-io - commons-io - ${commons-io.version} - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - 1.8 - 2.6 - - - diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/CompressingClientHttpRequestInterceptor.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/CompressingClientHttpRequestInterceptor.java deleted file mode 100644 index 78b77256af..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/CompressingClientHttpRequestInterceptor.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; - -import java.io.IOException; - -public class CompressingClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { - - private static final Logger LOG = LoggerFactory.getLogger(CompressingClientHttpRequestInterceptor.class); - - private static final String GZIP_ENCODING = "gzip"; - - /** - * Compress a request body using Gzip and add Http headers. - * - * @param req - * @param body - * @param exec - * @return - * @throws IOException - */ - @Override - public ClientHttpResponse intercept(HttpRequest req, byte[] body, ClientHttpRequestExecution exec) - throws IOException { - LOG.info("Compressing request..."); - HttpHeaders httpHeaders = req.getHeaders(); - httpHeaders.add(HttpHeaders.CONTENT_ENCODING, GZIP_ENCODING); - httpHeaders.add(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING); - return exec.execute(req, GzipUtils.compress(body)); - } - -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/GzipUtils.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/GzipUtils.java deleted file mode 100644 index b9731535b2..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/GzipUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.apache.commons.codec.Charsets; -import org.apache.commons.io.IOUtils; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -public class GzipUtils { - - /** - * Gzip a string. - * - * @param text - * @return - * @throws Exception - */ - public static byte[] compress(String text) throws Exception { - return GzipUtils.compress(text.getBytes(Charsets.UTF_8)); - } - - /** - * Gzip a byte array. - * - * @param body - * @return - * @throws IOException - */ - public static byte[] compress(byte[] body) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(baos)) { - gzipOutputStream.write(body); - } - return baos.toByteArray(); - } - - /** - * Decompress a Gzipped byte array to a String. - * - * @param body - * @return - * @throws IOException - */ - public static String decompress(byte[] body) throws IOException { - try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(body))) { - return IOUtils.toString(gzipInputStream, Charsets.UTF_8); - } - } -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/JettyWebServerConfiguration.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/JettyWebServerConfiguration.java deleted file mode 100644 index 8de8e5b523..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/JettyWebServerConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.server.handler.gzip.GzipHandler; -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Configure Jetty web server so it handles compressed requests. - */ -@Configuration -public class JettyWebServerConfiguration { - - private static final int MIN_BYTES = 1; - - /** - * Customise the Jetty web server to automatically decompress requests. - */ - @Bean - public JettyServletWebServerFactory jettyServletWebServerFactory() { - - JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); - factory.addServerCustomizers(server -> { - - GzipHandler gzipHandler = new GzipHandler(); - // Enable request decompression - gzipHandler.setInflateBufferSize(MIN_BYTES); - gzipHandler.setHandler(server.getHandler()); - - HandlerCollection handlerCollection = new HandlerCollection(gzipHandler); - server.setHandler(handlerCollection); - }); - - return factory; - } - -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/Message.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/Message.java deleted file mode 100644 index 24272a4fca..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/Message.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.spring.rest.compress; - -public class Message { - - private String text; - - public Message() { - } - - public Message(String text) { - this.text = text; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("Message {"); - sb.append("text='").append(text).append('\''); - sb.append('}'); - return sb.toString(); - } -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/MessageController.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/MessageController.java deleted file mode 100644 index 2fc2ca8272..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/MessageController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -public class MessageController { - - protected static final String PROCESSED = "Processed "; - - protected static final String REQUEST_MAPPING = "process"; - - private static final Logger LOG = LoggerFactory.getLogger(MessageController.class); - - /** - * A simple endpoint that responds with "Processed " + supplied Message content. - * - * @param headers - * @param message - * @return - */ - @PostMapping(value = REQUEST_MAPPING) - public ResponseEntity processMessage(@RequestHeader Map headers, - @RequestBody Message message) { - - // Print headers - headers.forEach((k, v) -> LOG.info(k + "=" + v)); - - return ResponseEntity.ok(PROCESSED + message.getText()); - } -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/RestTemplateConfiguration.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/RestTemplateConfiguration.java deleted file mode 100644 index c1e3c89ae9..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/RestTemplateConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; - -@Configuration -public class RestTemplateConfiguration { - - /** - * A RestTemplate that compresses requests. - * - * @return RestTemplate - */ - @Bean - public RestTemplate getRestTemplate() { - RestTemplate restTemplate = new RestTemplate(); - restTemplate.getInterceptors().add(new CompressingClientHttpRequestInterceptor()); - return restTemplate; - } -} diff --git a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/SpringCompressRequestApplication.java b/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/SpringCompressRequestApplication.java deleted file mode 100644 index 9b1b71979d..0000000000 --- a/spring-rest-compress/src/main/java/com/baeldung/spring/rest/compress/SpringCompressRequestApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -@EnableAutoConfiguration -public class SpringCompressRequestApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringCompressRequestApplication.class, args); - } - -} diff --git a/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/GzipUtilsUnitTest.java b/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/GzipUtilsUnitTest.java deleted file mode 100644 index 431758d358..0000000000 --- a/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/GzipUtilsUnitTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class GzipUtilsUnitTest { - - @Test - public void givenCompressedText_whenDecompressed_thenSuccessful() throws Exception { - final String expectedText = "Hello Baeldung!"; - byte[] compressedText = GzipUtils.compress(expectedText); - String decompressedText = GzipUtils.decompress(compressedText); - assertNotNull(compressedText); - assertEquals(expectedText, decompressedText); - } - -} \ No newline at end of file diff --git a/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/MessageControllerUnitTest.java b/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/MessageControllerUnitTest.java deleted file mode 100644 index 50b2b7ccd7..0000000000 --- a/spring-rest-compress/src/test/java/com/baeldung/spring/rest/compress/MessageControllerUnitTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.spring.rest.compress; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class MessageControllerUnitTest { - - private static final Logger LOG = LoggerFactory.getLogger(MessageControllerUnitTest.class); - - @Autowired - private RestTemplate restTemplate; - - @LocalServerPort - private int randomServerPort; - - /** - * As a further test you can intercept the request body, using a tool like - * Wireshark, to see the request body is actually gzipped. - * - * @throws Exception - */ - @Test - public void givenRestTemplate_whenPostCompressedRequest_thenRespondsSuccessfully() throws Exception { - - final String text = "Hello Baeldung!"; - Message message = new Message(text); - - HttpEntity request = new HttpEntity<>(message); - String uri = String.format("http://localhost:%s/%s", randomServerPort, MessageController.REQUEST_MAPPING); - - ResponseEntity responseEntity = restTemplate.postForEntity(uri, request, String.class); - - String response = responseEntity.getBody(); - LOG.info("Got response [{}]", response); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(response); - assertEquals(MessageController.PROCESSED + text, response); - } - -} From 796aefa9962896f00ede30cb94b7f4deb5a0b4cb Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 15 Nov 2020 11:47:08 +0100 Subject: [PATCH 171/590] BAEL-4717: Added ArrayList examples --- .../comparation/ArrayListUnitTest.java | 29 ++++++++++++++++++ .../comparation/ListVsMapUnitTest.java | 30 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java create mode 100644 core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java new file mode 100644 index 0000000000..935be19e74 --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.collections.comparation; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ArrayListUnitTest { + + @Test + void givenList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { + List list = new ArrayList<>(); + list.add("Daniel"); + list.add(1, "Marko"); + assertThat(list).hasSize(2); + assertThat(list.get(1)).isEqualTo("Marko"); + } + + @Test + void givenList_whenItemRemovedViaIndex_thenListSizeIsReduced() { + List list = new ArrayList<>(Arrays.asList("Daniel", "Marko")); + list.remove(1); + assertThat(list).hasSize(1); + } + +} diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java new file mode 100644 index 0000000000..6507013fbf --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.collections.comparation; + +import static org.assertj.core.api.Assertions.*; +import org.junit.jupiter.api.Test; + +import java.util.*; + +class ListVsMapUnitTest { + + @Test + void givenList_whenIteratingTroughValues_thenEachValueIsPresent() { + List list = new ArrayList<>(); + list.add("Daniel"); + list.add("Marko"); + for (String name : list) { + assertThat(name).isIn(list); + } + } + + @Test + void givenMap_whenIteratingTroughValues_thenEachValueIsPresent() { + Map map = new HashMap<>(); + map.put(1, "Daniel"); + map.put(2, "Marko"); + for (String name : map.values()) { + assertThat(name).isIn(map.values()); + } + } + +} From 7d5b9275aa790e881f8a9c0c1076dc61e4464783 Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Fri, 13 Nov 2020 16:50:14 +0000 Subject: [PATCH 172/590] BAEL-4728 Change the connection handling to close the connections in the pool and reuse the session factory --- .../java/com/baeldung/lambda/shipping/App.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java index 719725598c..95fd058667 100644 --- a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java +++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java @@ -6,10 +6,12 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.zaxxer.hikari.HikariDataSource; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import java.util.HashMap; import java.util.Map; @@ -22,11 +24,14 @@ import static org.hibernate.cfg.AvailableSettings.PASS; */ public class App implements RequestHandler { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private SessionFactory sessionFactory = createSessionFactory(); public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { - try (SessionFactory sessionFactory = createSessionFactory()) { + try { ShippingService service = new ShippingService(sessionFactory, new ShippingDao()); return routeRequest(input, service); + } finally { + flushConnectionPool(); } } @@ -105,4 +110,12 @@ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); .buildMetadata() .buildSessionFactory(); } + + private void flushConnectionPool() { + ConnectionProvider connectionProvider = sessionFactory.getSessionFactoryOptions() + .getServiceRegistry() + .getService(ConnectionProvider.class); + HikariDataSource hikariDataSource = connectionProvider.unwrap(HikariDataSource.class); + hikariDataSource.getHikariPoolMXBean().softEvictConnections(); + } } From f440cf900c3837a661dcb513a73eeaa95421afec Mon Sep 17 00:00:00 2001 From: Jordan Simpson Date: Sun, 15 Nov 2020 23:24:07 -0600 Subject: [PATCH 173/590] BAEL-4731 (article improvement) (#10251) * Instead of using .onDisconnect().block() to keep the app alive, make the app a web server. * Add article reference to README --- discord4j/.gitignore | 1 - discord4j/README.md | 7 +++++++ discord4j/pom.xml | 8 ++++++++ .../java/com/baeldung/discordbot/BotConfiguration.java | 2 -- 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 discord4j/README.md diff --git a/discord4j/.gitignore b/discord4j/.gitignore index b56f1dd0d0..7ed0d6b679 100644 --- a/discord4j/.gitignore +++ b/discord4j/.gitignore @@ -1,4 +1,3 @@ -README.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ diff --git a/discord4j/README.md b/discord4j/README.md new file mode 100644 index 0000000000..58a9924666 --- /dev/null +++ b/discord4j/README.md @@ -0,0 +1,7 @@ +## DISCORD4J + +This module contains articles about Discord4J + +### Relevant Articles: + +- [Creating a Discord Bot with Discord4J + Spring Boot](https://www.baeldung.com/spring-discord4j-bot) \ No newline at end of file diff --git a/discord4j/pom.xml b/discord4j/pom.xml index 7687f63ad5..664692f60a 100644 --- a/discord4j/pom.xml +++ b/discord4j/pom.xml @@ -23,6 +23,14 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot diff --git a/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java b/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java index a60005e9b5..901308605b 100644 --- a/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java +++ b/discord4j/src/main/java/com/baeldung/discordbot/BotConfiguration.java @@ -36,8 +36,6 @@ public class BotConfiguration { .onErrorResume(listener::handleError) .subscribe(); } - - client.onDisconnect().block(); } catch ( Exception exception ) { log.error( "Be sure to use a valid bot token!", exception ); From ad30d29ed6d48d29f020164687135876c1193f8f Mon Sep 17 00:00:00 2001 From: Mateusz Szablak Date: Mon, 16 Nov 2020 06:26:38 +0100 Subject: [PATCH 174/590] BAEL-4723 Defining Indexes in JPA #2 (#10254) * BAEL-4723 Defining Indexes in JPA * unit -> integration test * whitespaces fix * tab to space Co-authored-by: mateusz.szablak --- .../java/com/baeldung/jpa/index/Student.java | 14 +++++----- .../main/resources/META-INF/persistence.xml | 28 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java index 0a77cfbc9e..45de3f3fc4 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/index/Student.java @@ -10,13 +10,13 @@ import java.util.Objects; @Entity @Table(indexes = { - @Index(columnList = "firstName"), - @Index(name = "fn_index", columnList = "id"), - @Index(name = "multiIndex1", columnList = "firstName, lastName"), - @Index(name = "multiIndex2", columnList = "lastName, firstName"), - @Index(name = "multiSortIndex", columnList = "firstName, lastName DESC"), - @Index(name = "uniqueIndex", columnList = "firstName", unique = true), - @Index(name = "uniqueMultiIndex", columnList = "firstName, lastName", unique = true) + @Index(columnList = "firstName"), + @Index(name = "fn_index", columnList = "id"), + @Index(name = "multiIndex1", columnList = "firstName, lastName"), + @Index(name = "multiIndex2", columnList = "lastName, firstName"), + @Index(name = "multiSortIndex", columnList = "firstName, lastName DESC"), + @Index(name = "uniqueIndex", columnList = "firstName", unique = true), + @Index(name = "uniqueMultiIndex", columnList = "firstName, lastName", unique = true) }) public class Student implements Serializable { @Id diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 8fe3a8bbf1..1a53fb8e82 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -41,18 +41,18 @@ - org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.index.Student - true - - - - - - - - - - - + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.index.Student + true + + + + + + + + + + + From 644939da0755d266186dc15e0ee4934b9c2387a3 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Mon, 16 Nov 2020 14:27:29 +0200 Subject: [PATCH 175/590] BAEL-4687: added test for each configuration --- .../boot/jackson/{ => app}/Application.java | 5 +- .../jackson/config/CoffeeConfiguration.java | 60 ------------------- .../boot/jackson/config/CoffeeConstants.java | 11 ++++ .../config/CoffeeCustomizerConfig.java | 18 ++++++ .../CoffeeHttpConverterConfiguration.java | 21 +++++++ .../config/CoffeeJacksonBuilderConfig.java | 21 +++++++ .../config/CoffeeObjectMapperConfig.java | 24 ++++++++ .../config/CoffeeRegisterModuleConfig.java | 21 +++++++ .../src/main/resources/application.properties | 2 - .../src/main/resources/coffee.properties | 1 + .../AbstractCoffeeIntegrationTest.java} | 12 ++-- .../app/CoffeeCustomizerIntegrationTest.java | 8 +++ .../CoffeeHttpConverterIntegrationTest.java | 8 +++ .../CoffeeJacksonBuilderIntegrationTest.java | 8 +++ .../CoffeeObjectMapperIntegrationTest.java | 8 +++ .../CoffeeRegisterModuleIntegrationTest.java | 8 +++ 16 files changed, 166 insertions(+), 70 deletions(-) rename spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/{ => app}/Application.java (62%) delete mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java delete mode 100644 spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties rename spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/{CoffeeIntegrationTest.java => app/AbstractCoffeeIntegrationTest.java} (81%) create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/app/Application.java similarity index 62% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java rename to spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/app/Application.java index c4de34879f..6f57a534a8 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/Application.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/app/Application.java @@ -1,11 +1,12 @@ -package com.baeldung.boot.jackson; +package com.baeldung.boot.jackson.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan(basePackages = "com.baeldung.boot.jackson.controller") public class Application { - public static void main(String[] args) { SpringApplication.run(Application.class, args); } diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java deleted file mode 100644 index d13ce51e9b..0000000000 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.boot.jackson.config; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; - -import java.time.format.DateTimeFormatter; - -@Configuration -public class CoffeeConfiguration { - public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; - private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); - - @Bean - public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { - Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) - .serializationInclusion(JsonInclude.Include.NON_NULL); - return new MappingJackson2HttpMessageConverter(builder.build()); - } - - @Bean - public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { - return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL) - .serializers(localDateTimeSerializer); - } - - @Bean - @Primary - public ObjectMapper objectMapper() { - JavaTimeModule module = new JavaTimeModule(); - module.addSerializer(localDateTimeSerializer); - return new ObjectMapper() - .setSerializationInclusion(JsonInclude.Include.NON_NULL) - .registerModule(module); - } - - @Bean - @Primary - public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { - return new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) - .serializationInclusion(JsonInclude.Include.NON_NULL); - } - - @Bean - public Module javaTimeModule() { - JavaTimeModule module = new JavaTimeModule(); - module.addSerializer(localDateTimeSerializer); - return module; - } -} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java new file mode 100644 index 0000000000..7e7d7b8bc2 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java @@ -0,0 +1,11 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; + +import java.time.format.DateTimeFormatter; + +public class CoffeeConstants { + + public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; + public static LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java new file mode 100644 index 0000000000..c13615e702 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + +@Configuration +public class CoffeeCustomizerConfig { + + @Bean + public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { + return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL) + .serializers(localDateTimeSerializer); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java new file mode 100644 index 0000000000..83474a5c1f --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + +@Configuration +public class CoffeeHttpConverterConfiguration { + + @Bean + public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { + Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() + .serializers(localDateTimeSerializer) + .serializationInclusion(JsonInclude.Include.NON_NULL); + return new MappingJackson2HttpMessageConverter(builder.build()); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java new file mode 100644 index 0000000000..7a7b3e48bf --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java @@ -0,0 +1,21 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + +@Configuration +public class CoffeeJacksonBuilderConfig { + + @Bean + @Primary + public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { + return new Jackson2ObjectMapperBuilder() + .serializers(localDateTimeSerializer) + .serializationInclusion(JsonInclude.Include.NON_NULL); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java new file mode 100644 index 0000000000..5697928cc5 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java @@ -0,0 +1,24 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + +@Configuration +public class CoffeeObjectMapperConfig { + + @Bean + @Primary + public ObjectMapper objectMapper() { + JavaTimeModule module = new JavaTimeModule(); + module.addSerializer(localDateTimeSerializer); + return new ObjectMapper() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .registerModule(module); + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java new file mode 100644 index 0000000000..855bc84966 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java @@ -0,0 +1,21 @@ +package com.baeldung.boot.jackson.config; + +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + +@Configuration +@PropertySource("classpath:coffee.properties") +public class CoffeeRegisterModuleConfig { + + @Bean + public Module javaTimeModule() { + JavaTimeModule module = new JavaTimeModule(); + module.addSerializer(localDateTimeSerializer); + return module; + } +} diff --git a/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties b/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties deleted file mode 100644 index 352add464b..0000000000 --- a/spring-boot-modules/spring-boot-jackson/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.jackson.default-property-inclusion=non_null -spring.jackson.serialization.write-dates-as-timestamps=false \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties b/spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties new file mode 100644 index 0000000000..269845cbf1 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties @@ -0,0 +1 @@ +spring.jackson.default-property-inclusion=non_null \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java similarity index 81% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java rename to spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java index 1fda173d37..13e1f05f97 100644 --- a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/CoffeeIntegrationTest.java +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java @@ -1,6 +1,6 @@ -package com.baeldung.boot.jackson; +package com.baeldung.boot.jackson.app; -import com.baeldung.boot.jackson.config.CoffeeConfiguration; +import com.baeldung.boot.jackson.config.CoffeeConstants; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -12,20 +12,20 @@ import java.time.format.DateTimeFormatter; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class CoffeeIntegrationTest { +public abstract class AbstractCoffeeIntegrationTest { @Autowired - TestRestTemplate restTemplate; + protected TestRestTemplate restTemplate; @Test public void whenGetCoffee_thenSerializedWithDateAndNonNull() { - String formattedDate = DateTimeFormatter.ofPattern(CoffeeConfiguration.dateTimeFormat) + String formattedDate = DateTimeFormatter.ofPattern(CoffeeConstants.dateTimeFormat) .format(LocalDateTime.now()); + String brand = "Lavazza"; String url = "/coffee?brand=" + brand; String response = restTemplate.getForObject(url, String.class); - assertThat(response).isEqualTo( "{\"brand\":\"" + brand + "\",\"date\":\"" + formattedDate + "\"}"); } diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java new file mode 100644 index 0000000000..d690de1b9c --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.jackson.app; + +import com.baeldung.boot.jackson.config.CoffeeCustomizerConfig; +import org.springframework.context.annotation.Import; + +@Import(CoffeeCustomizerConfig.class) +public class CoffeeCustomizerIntegrationTest extends AbstractCoffeeIntegrationTest { +} diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java new file mode 100644 index 0000000000..62b1d42152 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.jackson.app; + +import com.baeldung.boot.jackson.config.CoffeeHttpConverterConfiguration; +import org.springframework.context.annotation.Import; + +@Import(CoffeeHttpConverterConfiguration.class) +public class CoffeeHttpConverterIntegrationTest extends AbstractCoffeeIntegrationTest { +} diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java new file mode 100644 index 0000000000..52a55394c0 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.jackson.app; + +import com.baeldung.boot.jackson.config.CoffeeJacksonBuilderConfig; +import org.springframework.context.annotation.Import; + +@Import(CoffeeJacksonBuilderConfig.class) +public class CoffeeJacksonBuilderIntegrationTest extends AbstractCoffeeIntegrationTest { +} diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java new file mode 100644 index 0000000000..34743ceba5 --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.jackson.app; + +import com.baeldung.boot.jackson.config.CoffeeObjectMapperConfig; +import org.springframework.context.annotation.Import; + +@Import(CoffeeObjectMapperConfig.class) +public class CoffeeObjectMapperIntegrationTest extends AbstractCoffeeIntegrationTest { +} diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java new file mode 100644 index 0000000000..69bbd5be2a --- /dev/null +++ b/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.jackson.app; + +import com.baeldung.boot.jackson.config.CoffeeRegisterModuleConfig; +import org.springframework.context.annotation.Import; + +@Import(CoffeeRegisterModuleConfig.class) +public class CoffeeRegisterModuleIntegrationTest extends AbstractCoffeeIntegrationTest { +} From 003a5f203419f19c3a4a0f023ada288ea982d2e6 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Mon, 16 Nov 2020 14:29:46 +0200 Subject: [PATCH 176/590] BAEL-4687: updated parent --- spring-boot-modules/spring-boot-jackson/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-jackson/pom.xml b/spring-boot-modules/spring-boot-jackson/pom.xml index b502bca908..1b2e55839a 100644 --- a/spring-boot-modules/spring-boot-jackson/pom.xml +++ b/spring-boot-modules/spring-boot-jackson/pom.xml @@ -3,10 +3,10 @@ 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"> - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ 4.0.0 From 69c4d136f5d51f1d7a24860bebdafcacd86d4b9b Mon Sep 17 00:00:00 2001 From: Carlos Cavero Date: Mon, 16 Nov 2020 14:45:31 +0100 Subject: [PATCH 177/590] Update pom.xml Use the correct indentation --- docker/docker-internal-dto/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/docker-internal-dto/pom.xml b/docker/docker-internal-dto/pom.xml index 01b92f81dc..55cef257fe 100644 --- a/docker/docker-internal-dto/pom.xml +++ b/docker/docker-internal-dto/pom.xml @@ -10,6 +10,6 @@ docker-internal-dto - docker-internal-dto + docker-internal-dto - \ No newline at end of file + From cc1a2e9b15892f181240e867481335527dee8a00 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Mon, 16 Nov 2020 16:02:18 +0100 Subject: [PATCH 178/590] BAEL-4717: Added HashMap and LinkedList examples --- .../comparation/ArrayListUnitTest.java | 5 ++- .../comparation/HashMapUnitTest.java | 31 ++++++++++++++ .../comparation/LinkedListUnitTest.java | 41 +++++++++++++++++++ .../comparation/ListVsMapUnitTest.java | 2 + 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java create mode 100644 core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java index 935be19e74..4041ff1637 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ArrayListUnitTest { @Test - void givenList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { + void givenArrayList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { List list = new ArrayList<>(); list.add("Daniel"); list.add(1, "Marko"); @@ -20,10 +20,11 @@ public class ArrayListUnitTest { } @Test - void givenList_whenItemRemovedViaIndex_thenListSizeIsReduced() { + void givenArrayList_whenItemRemovedViaIndex_thenListSizeIsReduced() { List list = new ArrayList<>(Arrays.asList("Daniel", "Marko")); list.remove(1); assertThat(list).hasSize(1); + assertThat(list).doesNotContain("Marko"); } } diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java new file mode 100644 index 0000000000..3b595472e0 --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.collections.comparation; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HashMapUnitTest { + + @Test + void givenHashMap_whenItemAddedByKey_thenItCanBeRetrieved() { + Map map = new HashMap<>(); + map.put("123456", "Daniel"); + map.put("654321", "Marko"); + assertThat(map.get("654321")).isEqualTo("Marko"); + } + + @Test + void givenHashMap_whenItemRemovedByKey_thenMapSizeIsReduced() { + Map map = new HashMap<>(); + map.put("123456", "Daniel"); + map.put("654321", "Marko"); + map.remove("654321"); + assertThat(map).hasSize(1); + } + +} diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java new file mode 100644 index 0000000000..c2ab554c91 --- /dev/null +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.collections.comparation; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class LinkedListUnitTest { + + @Test + void givenLinkedList_whenItemIsAppended_thenItCanBeRetrieved() { + LinkedList list = new LinkedList<>(); + list.addLast("Daniel"); + list.addFirst( "Marko"); + assertThat(list).hasSize(2); + assertThat(list.getLast()).isEqualTo("Daniel"); + } + + @Test + void givenLinkedList_whenItemIsRemoved_thenListSizeIsReduced() { + LinkedList list = new LinkedList<>(Arrays.asList("Daniel", "Marko", "David")); + list.removeFirst(); + list.removeLast(); + assertThat(list).hasSize(1); + assertThat(list).containsExactly("Marko"); + } + + @Test + void givenLinkedList_whenItemInserted_thenItCanBeRetrievedAndDeleted() { + LinkedList list = new LinkedList<>(); + list.push("Daniel"); + list.push("Marko"); + assertThat(list.poll()).isEqualTo("Marko"); + assertThat(list).hasSize(1); + } + +} diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java index 6507013fbf..dd6bf760fd 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java @@ -15,6 +15,7 @@ class ListVsMapUnitTest { for (String name : list) { assertThat(name).isIn(list); } + assertThat(list).containsExactly("Daniel", "Marko"); } @Test @@ -25,6 +26,7 @@ class ListVsMapUnitTest { for (String name : map.values()) { assertThat(name).isIn(map.values()); } + assertThat(map.values()).containsExactlyInAnyOrder("Daniel", "Marko"); } } From 600896e8423a423e6067b3065faf10bfc6ac1c65 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Mon, 16 Nov 2020 19:03:15 +0100 Subject: [PATCH 179/590] [BAEL-4617] extending enums (#10130) --- .../core-java-lang-oop-types/pom.xml | 10 ++++- .../enums/extendenum/Application.java | 35 +++++++++++++++ .../enums/extendenum/ApplicationWithEx.java | 26 +++++++++++ .../extendenum/BasicStringOperation.java | 33 ++++++++++++++ .../extendenum/ExtendedStringOperation.java | 31 +++++++++++++ .../enums/extendenum/ImmutableOperation.java | 6 +++ .../baeldung/enums/extendenum/Operator.java | 5 +++ .../enums/extendenum/StringOperation.java | 7 +++ .../enums/extendenum/ExtendEnumUnitTest.java | 43 +++++++++++++++++++ 9 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Application.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ApplicationWithEx.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/BasicStringOperation.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ExtendedStringOperation.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ImmutableOperation.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Operator.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/StringOperation.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/extendenum/ExtendEnumUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-types/pom.xml b/core-java-modules/core-java-lang-oop-types/pom.xml index ee167bbae2..c4efd9b8d2 100644 --- a/core-java-modules/core-java-lang-oop-types/pom.xml +++ b/core-java-modules/core-java-lang-oop-types/pom.xml @@ -12,12 +12,20 @@ core-java-lang-oop-types core-java-lang-oop-types jar - + org.apache.commons commons-lang3 ${commons-lang3.version} + + commons-codec + commons-codec + ${commons-codec.version} + + + 1.15 + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Application.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Application.java new file mode 100644 index 0000000000..ad3d861d6a --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Application.java @@ -0,0 +1,35 @@ +package com.baeldung.enums.extendenum; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.EnumMap; +import java.util.Map; + +public class Application { + private static final Map OPERATION_MAP; + + static { + OPERATION_MAP = new EnumMap<>(ImmutableOperation.class); + OPERATION_MAP.put(ImmutableOperation.TO_LOWER, String::toLowerCase); + OPERATION_MAP.put(ImmutableOperation.INVERT_CASE, StringUtils::swapCase); + OPERATION_MAP.put(ImmutableOperation.REMOVE_WHITESPACES, input -> input.replaceAll("\\s", "")); + + if (Arrays.stream(ImmutableOperation.values()).anyMatch(it -> !OPERATION_MAP.containsKey(it))) { + throw new IllegalStateException("Unmapped enum constant found!"); + } + } + + public String applyImmutableOperation(ImmutableOperation operation, String input) { + return OPERATION_MAP.get(operation).apply(input); + } + + public String getDescription(StringOperation stringOperation) { + return stringOperation.getDescription(); + } + + public String applyOperation(StringOperation operation, String input) { + return operation.apply(input); + } + +} diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ApplicationWithEx.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ApplicationWithEx.java new file mode 100644 index 0000000000..e9cbad6b7c --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ApplicationWithEx.java @@ -0,0 +1,26 @@ +package com.baeldung.enums.extendenum; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.EnumMap; +import java.util.Map; + +public class ApplicationWithEx { + private static final Map OPERATION_MAP; + + static { + OPERATION_MAP = new EnumMap<>(ImmutableOperation.class); + OPERATION_MAP.put(ImmutableOperation.TO_LOWER, String::toLowerCase); + OPERATION_MAP.put(ImmutableOperation.INVERT_CASE, StringUtils::swapCase); + // ImmutableOperation.REMOVE_WHITESPACES is not mapped + + if (Arrays.stream(ImmutableOperation.values()).anyMatch(it -> !OPERATION_MAP.containsKey(it))) { + throw new IllegalStateException("Unmapped enum constant found!"); + } + } + + public String applyImmutableOperation(ImmutableOperation operation, String input) { + return OPERATION_MAP.get(operation).apply(input); + } +} diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/BasicStringOperation.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/BasicStringOperation.java new file mode 100644 index 0000000000..267b02daf4 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/BasicStringOperation.java @@ -0,0 +1,33 @@ +package com.baeldung.enums.extendenum; + +public enum BasicStringOperation implements StringOperation { + TRIM("Removing leading and trailing spaces.") { + @Override + public String apply(String input) { + return input.trim(); + } + }, + TO_UPPER("Changing all characters into upper case.") { + @Override + public String apply(String input) { + return input.toUpperCase(); + } + }, + REVERSE("Reversing the given string.") { + @Override + public String apply(String input) { + return new StringBuilder(input).reverse().toString(); + } + }; + + private String description; + + public String getDescription() { + return description; + } + + BasicStringOperation(String description) { + this.description = description; + } +} + diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ExtendedStringOperation.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ExtendedStringOperation.java new file mode 100644 index 0000000000..6184837b26 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ExtendedStringOperation.java @@ -0,0 +1,31 @@ +package com.baeldung.enums.extendenum; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.digest.DigestUtils; + +public enum ExtendedStringOperation implements StringOperation { + MD5_ENCODE("Encoding the given string using the MD5 algorithm.") { + @Override + public String apply(String input) { + return DigestUtils.md5Hex(input); + } + }, + BASE64_ENCODE("Encoding the given string using the BASE64 algorithm.") { + @Override + public String apply(String input) { + return new String(new Base64().encode(input.getBytes())); + } + }; + + private String description; + + ExtendedStringOperation(String description) { + this.description = description; + } + + + @Override + public String getDescription() { + return description; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ImmutableOperation.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ImmutableOperation.java new file mode 100644 index 0000000000..66f26a4806 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/ImmutableOperation.java @@ -0,0 +1,6 @@ +package com.baeldung.enums.extendenum; + +public enum ImmutableOperation { + REMOVE_WHITESPACES, TO_LOWER, INVERT_CASE +} + diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Operator.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Operator.java new file mode 100644 index 0000000000..a65fea4f92 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/Operator.java @@ -0,0 +1,5 @@ +package com.baeldung.enums.extendenum; + +public interface Operator { + String apply(String input); +} diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/StringOperation.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/StringOperation.java new file mode 100644 index 0000000000..faf4f38274 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/extendenum/StringOperation.java @@ -0,0 +1,7 @@ +package com.baeldung.enums.extendenum; + +public interface StringOperation { + String getDescription(); + + String apply(String input); +} diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/extendenum/ExtendEnumUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/extendenum/ExtendEnumUnitTest.java new file mode 100644 index 0000000000..0b5ed1e826 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/extendenum/ExtendEnumUnitTest.java @@ -0,0 +1,43 @@ +package com.baeldung.enums.extendenum; + +import org.junit.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class ExtendEnumUnitTest { + private Application app = new Application(); + + @Test + public void givenAStringAndOperation_whenApplyOperation_thenGetExpectedResult() { + String input = " hello"; + String expectedToUpper = " HELLO"; + String expectedReverse = "olleh "; + String expectedTrim = "hello"; + String expectedBase64 = "IGhlbGxv"; + String expectedMd5 = "292a5af68d31c10e31ad449bd8f51263"; + assertEquals(expectedTrim, app.applyOperation(BasicStringOperation.TRIM, input)); + assertEquals(expectedToUpper, app.applyOperation(BasicStringOperation.TO_UPPER, input)); + assertEquals(expectedReverse, app.applyOperation(BasicStringOperation.REVERSE, input)); + assertEquals(expectedBase64, app.applyOperation(ExtendedStringOperation.BASE64_ENCODE, input)); + assertEquals(expectedMd5, app.applyOperation(ExtendedStringOperation.MD5_ENCODE, input)); + } + + @Test + public void givenAStringAndImmutableOperation_whenApplyOperation_thenGetExpectedResult() { + String input = " He ll O "; + String expectedToLower = " he ll o "; + String expectedRmWhitespace = "HellO"; + String expectedInvertCase = " hE LL o "; + assertEquals(expectedToLower, app.applyImmutableOperation(ImmutableOperation.TO_LOWER, input)); + assertEquals(expectedRmWhitespace, app.applyImmutableOperation(ImmutableOperation.REMOVE_WHITESPACES, input)); + assertEquals(expectedInvertCase, app.applyImmutableOperation(ImmutableOperation.INVERT_CASE, input)); + } + + @Test + public void givenUnmappedImmutableOperationValue_whenAppStarts_thenGetException() { + Throwable throwable = assertThrows(ExceptionInInitializerError.class, () -> { + ApplicationWithEx appEx = new ApplicationWithEx(); + }); + assertTrue(throwable.getCause() instanceof IllegalStateException); + } +} \ No newline at end of file From c6f8c565722415f191bee2a6b31d2a09e93f066e Mon Sep 17 00:00:00 2001 From: vatsalgosar Date: Mon, 16 Nov 2020 23:33:49 +0530 Subject: [PATCH 180/590] IsLetter / isAlphabetic method unit tests (#10097) --- .../character/IsLetterOrAlphabetUnitTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java new file mode 100644 index 0000000000..44c712a17f --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.java14.character; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +public class IsLetterOrAlphabetUnitTest { + + @Test + public void givenACharacter_whenLetter_thenAssertIsLetterTrue() { + assertTrue(Character.isLetter(65)); + } + + @Test + public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic(65)); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() { + assertFalse(Character.isLetter(837)); + } + + @Test + public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic(837)); + } + +} \ No newline at end of file From 43fad6ba9570481a560f8c1e62e1e2f76552e863 Mon Sep 17 00:00:00 2001 From: developerDiv <34768329+developerDiv@users.noreply.github.com> Date: Mon, 16 Nov 2020 18:08:49 +0000 Subject: [PATCH 181/590] Bael 4215 creating generic array (#10178) * Initial commit for generic arrays, using T[] and Object[] * Add CollectionsList * Create generic arrays example with a Stack * Remove custom exception classes + throw RuntimeException instead. --- .../com/baeldung/genericarrays/MyStack.java | 30 +++++++++++++ .../genericarrays/ListToArrayUnitTest.java | 24 ++++++++++ .../genericarrays/MyStackUnitTest.java | 44 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java create mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java create mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java new file mode 100644 index 0000000000..02659f13bc --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java @@ -0,0 +1,30 @@ +package com.baeldung.genericarrays; + +import java.lang.reflect.Array; + +public class MyStack { + private E[] elements; + private int size = 0; + + public MyStack(Class clazz, int capacity) { + elements = (E[]) Array.newInstance(clazz, capacity); + } + + public void push(E item) { + if (size == elements.length) { + throw new RuntimeException(); + } + elements[size++] = item; + } + + public E pop() { + if (size == 0) { + throw new RuntimeException(); + } + return elements[--size]; + } + + public E[] getAllElements() { + return elements; + } +} diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java new file mode 100644 index 0000000000..5fd0385181 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.genericarrays; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class ListToArrayUnitTest { + + @Test + public void givenListOfItems_whenToArray_thenReturnArrayOfItems() { + List items = new LinkedList<>(); + items.add("first item"); + items.add("second item"); + + String[] itemsAsArray = items.toArray(new String[0]); + + assertEquals("first item", itemsAsArray[0]); + assertEquals("second item", itemsAsArray[1]); + } +} diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java new file mode 100644 index 0000000000..e36c5169a5 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.genericarrays; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class MyStackUnitTest { + + @Test + public void givenStackWithTwoItems_whenPop_thenReturnLastAdded() { + MyStack myStack = new MyStack<>(String.class, 2); + myStack.push("hello"); + myStack.push("example"); + + assertEquals("example", myStack.pop()); + } + + @Test (expected = RuntimeException.class) + public void givenStackWithFixedCapacity_whenExceedCapacity_thenThrowException() { + MyStack myStack = new MyStack<>(Integer.class, 2); + myStack.push(100); + myStack.push(200); + myStack.push(300); + } + + @Test(expected = RuntimeException.class) + public void givenStack_whenPopOnEmptyStack_thenThrowException() { + MyStack myStack = new MyStack<>(Integer.class, 1); + myStack.push(100); + myStack.pop(); + myStack.pop(); + } + + @Test + public void givenStackWithItems_whenGetAllElements_thenSizeShouldEqualTotal() { + MyStack myStack = new MyStack<>(String.class, 2); + myStack.push("hello"); + myStack.push("example"); + + String[] items = myStack.getAllElements(); + + assertEquals(2, items.length); + } +} From 4164ff6a03ad8b97622e08467d638bc3e849ea79 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 16 Nov 2020 21:48:14 -0700 Subject: [PATCH 182/590] Updates from PR comments --- core-java-modules/core-java-15/pom.xml | 4 ++-- .../java/com/baeldung/whatsnew/records/Person.java | 10 ++++++---- .../com/baeldung/whatsnew/sealedclasses/Employee.java | 6 ++---- .../com/baeldung/whatsnew/sealedclasses/Manager.java | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index df8aeafca9..c6f1454078 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -51,8 +51,8 @@ ${maven.compiler.release} --enable-preview - 14 - 14 + 15 + 15 diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java index e59fa86ed6..67d3151440 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java @@ -3,13 +3,15 @@ package com.baeldung.whatsnew.records; /** * Java record with a header indicating 2 fields. */ -public record Person(String name, int age) { - +public record Person(String name, int age) +{ /** * Public constructor that does some basic validation. */ - public Person { - if (age < 0) { + public Person + { + if (age < 0) + { throw new IllegalArgumentException("Age cannot be negative"); } } diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java index e9a2e25417..72ef75cb7c 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java @@ -2,12 +2,10 @@ package com.baeldung.whatsnew.sealedclasses; import java.util.Date; -public non-sealed class Employee extends Person { - +public non-sealed class Employee extends Person +{ public Date getHiredDate() { return new Date(); } - - } diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java index 79c50b057e..87cbcf2673 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java @@ -1,4 +1,5 @@ package com.baeldung.whatsnew.sealedclasses; -public final class Manager extends Person { +public final class Manager extends Person +{ } From bba378a141822b9bf4b0c847f149a800f6efac57 Mon Sep 17 00:00:00 2001 From: sharifi Date: Tue, 17 Nov 2020 09:14:33 +0330 Subject: [PATCH 183/590] correct the package name --- .../src/main/java/com/baeldung/aes/AESUtil.java | 2 +- .../src/main/java/com/baeldung/aes/Student.java | 2 +- .../src/test/java/com/baeldung/aes/AESUtilUnitTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java index e8b75ccc79..361f09f1cb 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java @@ -1,4 +1,4 @@ -package com.baeldung.crypto; +package com.baeldung.aes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java index 6daceb3377..13cd1c5e9d 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java @@ -1,4 +1,4 @@ -package com.baeldung.crypto; +package com.baeldung.aes; import java.io.Serializable; import java.util.Objects; diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java index ed3b5bd650..3b583ef0c4 100644 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.crypto; +package com.baeldung.aes; import org.assertj.core.api.WithAssertions; import org.junit.jupiter.api.Assertions; From c57644617da2faeb6a0855e26f50306dbc9bca96 Mon Sep 17 00:00:00 2001 From: sharifi Date: Tue, 17 Nov 2020 09:30:20 +0330 Subject: [PATCH 184/590] improve import package names --- .../src/test/java/com/baeldung/aes/AESUtilUnitTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java index 3b583ef0c4..78543d0abc 100644 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -4,7 +4,8 @@ import org.assertj.core.api.WithAssertions; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import javax.crypto.*; +import javax.crypto.SealedObject; +import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import java.io.File; import java.io.IOException; From 9c1e232982e2158bf0944b59ba730f0335d16289 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Nov 2020 15:40:24 +0800 Subject: [PATCH 185/590] Update README.md --- spring-security-modules/spring-security-oidc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-modules/spring-security-oidc/README.md b/spring-security-modules/spring-security-oidc/README.md index 5e8f391b96..6a45824fcb 100644 --- a/spring-security-modules/spring-security-oidc/README.md +++ b/spring-security-modules/spring-security-oidc/README.md @@ -5,6 +5,7 @@ This module contains articles about OpenID with Spring Security ### Relevant articles - [Spring Security and OpenID Connect (Legacy)](https://www.baeldung.com/spring-security-openid-connect-legacy) +- [Spring Security and OpenID Connect](https://www.baeldung.com/spring-security-openid-connect) ### OpenID Connect with Spring Security From 79fc666e0709f947a2b0eaa33ffe49f95a05ffe3 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Tue, 17 Nov 2020 11:00:56 +0100 Subject: [PATCH 186/590] BAEL-4717: Refactor examples --- .../baeldung/collections/comparation/ArrayListUnitTest.java | 4 ++-- .../baeldung/collections/comparation/LinkedListUnitTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java index 4041ff1637..bc6a07d274 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java @@ -14,9 +14,9 @@ public class ArrayListUnitTest { void givenArrayList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() { List list = new ArrayList<>(); list.add("Daniel"); - list.add(1, "Marko"); + list.add(0, "Marko"); assertThat(list).hasSize(2); - assertThat(list.get(1)).isEqualTo("Marko"); + assertThat(list.get(0)).isEqualTo("Marko"); } @Test diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java index c2ab554c91..aa6b7fa923 100644 --- a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java +++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java @@ -15,7 +15,7 @@ public class LinkedListUnitTest { void givenLinkedList_whenItemIsAppended_thenItCanBeRetrieved() { LinkedList list = new LinkedList<>(); list.addLast("Daniel"); - list.addFirst( "Marko"); + list.addFirst("Marko"); assertThat(list).hasSize(2); assertThat(list.getLast()).isEqualTo("Daniel"); } From 7bb2282d2435c148b73eaacf2533dc598c73632e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Nov 2020 16:32:30 +0530 Subject: [PATCH 187/590] BAEL-4301 - Created a new module core-java-char in core-java-modules modules - Added Unit Tests for Character#isAlphabetic and Character#isLetter methods --- core-java-modules/core-java-char/README.md | 6 +++ core-java-modules/core-java-char/pom.xml | 42 +++++++++++++++++++ .../CharacterGeneralCategoryTypeUnitTest.java | 37 ++++++++++++++++ .../character/IsLetterOrAlphabetUnitTest.java | 14 +++---- core-java-modules/pom.xml | 3 +- 5 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 core-java-modules/core-java-char/README.md create mode 100644 core-java-modules/core-java-char/pom.xml create mode 100644 core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java rename core-java-modules/{core-java-14/src/test/java/com/baeldung/java14 => core-java-char/src/test/java/com/baeldung}/character/IsLetterOrAlphabetUnitTest.java (69%) diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md new file mode 100644 index 0000000000..71f8e943aa --- /dev/null +++ b/core-java-modules/core-java-char/README.md @@ -0,0 +1,6 @@ +## Core Java Character + +This module contains articles about Java Character Class + +### Relevant Articles: +- Character#isAlphabetic vs Character#isLetter diff --git a/core-java-modules/core-java-char/pom.xml b/core-java-modules/core-java-char/pom.xml new file mode 100644 index 0000000000..3691079482 --- /dev/null +++ b/core-java-modules/core-java-char/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + core-java-char + 0.1.0-SNAPSHOT + core-java-char + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.openjdk.jmh + jmh-core + ${openjdk.jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${openjdk.jmh.version} + + + + + 1.19 + 3.11.1 + + + diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java new file mode 100644 index 0000000000..4bb41211a9 --- /dev/null +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.character; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class CharacterGeneralCategoryTypeUnitTest { + @Test + public void givenACharacter_whenUpperCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('U') == Character.UPPERCASE_LETTER); + } + + @Test + public void givenACharacter_whenLowerCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('u') == Character.LOWERCASE_LETTER); + } + + @Test + public void givenACharacter_whenTitleCaseLetter_thenAssertTrue() { + assertTrue(Character.getType('\u01f2') == Character.TITLECASE_LETTER); + } + + @Test + public void givenACharacter_whenModifierLetter_thenAssertTrue() { + assertTrue(Character.getType('\u02b0') == Character.MODIFIER_LETTER); + } + + @Test + public void givenACharacter_whenOtherLetter_thenAssertTrue() { + assertTrue(Character.getType('\u05d0') == Character.OTHER_LETTER); + } + + @Test + public void givenACharacter_whenLetterNumber_thenAssertTrue() { + assertTrue(Character.getType('\u2164') == Character.LETTER_NUMBER); + } +} diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java similarity index 69% rename from core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java rename to core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java index 44c712a17f..734762ec7b 100644 --- a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java14.character; +package com.baeldung.character; import org.junit.Test; @@ -6,25 +6,23 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; public class IsLetterOrAlphabetUnitTest { - @Test public void givenACharacter_whenLetter_thenAssertIsLetterTrue() { - assertTrue(Character.isLetter(65)); + assertTrue(Character.isLetter('a')); } @Test public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() { - assertTrue(Character.isAlphabetic(65)); + assertTrue(Character.isAlphabetic('a')); } @Test public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() { - assertFalse(Character.isLetter(837)); + assertFalse(Character.isLetter('\u2164')); } @Test public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() { - assertTrue(Character.isAlphabetic(837)); + assertTrue(Character.isAlphabetic('\u2164')); } - -} \ No newline at end of file +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index a6aecef741..370c8c9eb7 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -29,7 +29,8 @@ core-java-arrays-convert core-java-arrays-operations-basic core-java-arrays-operations-advanced - + + core-java-char core-java-collections core-java-collections-2 core-java-collections-3 From a34be087d9e2c7ec2789624d6910e2dcea3f8eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horacio=20L=C3=B3pez?= Date: Tue, 17 Nov 2020 20:06:51 -0300 Subject: [PATCH 188/590] Update UserController.java --- .../baeldung/crud/controllers/UserController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java index 8a7ef96f1e..4fac1ba0ca 100644 --- a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java @@ -23,6 +23,12 @@ public class UserController { this.userRepository = userRepository; } + @GetMapping("/index") + public String userList(User user) { + model.addAttribute("users", userRepository.findAll()); + return "index"; + } + @GetMapping("/signup") public String showSignUpForm(User user) { return "add-user"; @@ -35,7 +41,6 @@ public class UserController { } userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); return "redirect:/index"; } @@ -43,6 +48,7 @@ public class UserController { public String showUpdateForm(@PathVariable("id") long id, Model model) { User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); model.addAttribute("user", user); + return "update-user"; } @@ -54,7 +60,7 @@ public class UserController { } userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); + return "redirect:/index"; } @@ -62,7 +68,7 @@ public class UserController { public String deleteUser(@PathVariable("id") long id, Model model) { User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); userRepository.delete(user); - model.addAttribute("users", userRepository.findAll()); - return "index"; + + return "redirect:/index"; } } From 34243ccef424815e1d28f346cc00f8695d9e557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horacio=20L=C3=B3pez?= Date: Tue, 17 Nov 2020 20:16:10 -0300 Subject: [PATCH 189/590] Removed user param on userList method --- .../main/java/com/baeldung/crud/controllers/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java index 4fac1ba0ca..9c27c1764c 100644 --- a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java @@ -24,7 +24,7 @@ public class UserController { } @GetMapping("/index") - public String userList(User user) { + public String userList() { model.addAttribute("users", userRepository.findAll()); return "index"; } From 01ecd328687ff1465e5e3688422011b24273086f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horacio=20L=C3=B3pez?= Date: Tue, 17 Nov 2020 21:50:02 -0300 Subject: [PATCH 190/590] Fixed test --- .../src/test/java/com/baeldung/crud/UserControllerUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java index f1455f7a73..651f17b57a 100644 --- a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java @@ -78,6 +78,6 @@ public class UserControllerUnitTest { @Test(expected = IllegalArgumentException.class) public void whenCalleddeleteUser_thenIllegalArgumentException() { - assertThat(userController.deleteUser(1l, mockedModel)).isEqualTo("index"); + assertThat(userController.deleteUser(1l, mockedModel)).isEqualTo("redirect:/index"); } } From d2f2bb6ab0b009c8e3e1939ffa3d215c9e98416b Mon Sep 17 00:00:00 2001 From: Horacio Lopez Date: Tue, 17 Nov 2020 21:57:15 -0300 Subject: [PATCH 191/590] Added test and some fixes --- .../java/com/baeldung/crud/controllers/UserController.java | 2 +- .../test/java/com/baeldung/crud/UserControllerUnitTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java index 9c27c1764c..fb86683d6b 100644 --- a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java @@ -24,7 +24,7 @@ public class UserController { } @GetMapping("/index") - public String userList() { + public String showUserList(Model model) { model.addAttribute("users", userRepository.findAll()); return "index"; } diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java index 651f17b57a..77d83698de 100644 --- a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java @@ -28,6 +28,11 @@ public class UserControllerUnitTest { userController = new UserController(mockedUserRepository); } + @Test + public void whenCalledIndex_thenCorrect() { + assertThat(userController.showUserList(mockedModel)).isEqualTo("index"); + } + @Test public void whenCalledshowSignUpForm_thenCorrect() { User user = new User("John", "john@domain.com"); From a26085b2660202ba8ff20f2c31b600da6a4d05eb Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Wed, 18 Nov 2020 08:30:49 +0100 Subject: [PATCH 192/590] BAEL-4706 - Spring Boot with Spring Batch - Rename testcontainers test to LiveTest --- ...inersIntegrationTest.java => KafkaTestContainersLiveTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/{KafkaTestContainersIntegrationTest.java => KafkaTestContainersLiveTest.java} (100%) diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java similarity index 100% rename from spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersIntegrationTest.java rename to spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java From dfc2aa22dccf64a4f76b841920f6de8d24c09912 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 16:53:18 +0800 Subject: [PATCH 193/590] 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 934833b31b..7338ff9523 100644 --- a/core-java-modules/core-java-arrays-guides/README.md +++ b/core-java-modules/core-java-arrays-guides/README.md @@ -7,3 +7,4 @@ This module contains complete guides about arrays in Java - [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) +- [Creating a Generic Array in Java](https://www.baeldung.com/java-generic-array) From 7e76b6ed8fbeee32893598c52ffc03d9239f820f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 16:55:25 +0800 Subject: [PATCH 194/590] Update README.md --- docker/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/README.md b/docker/README.md index 7948b3d663..fcace3978f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,3 +1,4 @@ ## Relevant Articles: - [Introduction to Docker Compose](https://www.baeldung.com/docker-compose) +- [Reusing Docker Layers with Spring Boot](https://www.baeldung.com/docker-layers-spring-boot) From afc3b4e82d052ce614ccb6bd5bdbd5795af527cf Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 16:57:40 +0800 Subject: [PATCH 195/590] Update README.md --- spring-kafka/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-kafka/README.md b/spring-kafka/README.md index f2fecde894..ddb086c3bd 100644 --- a/spring-kafka/README.md +++ b/spring-kafka/README.md @@ -5,6 +5,7 @@ This module contains articles about Spring with Kafka ### Relevant articles - [Intro to Apache Kafka with Spring](https://www.baeldung.com/spring-kafka) +- [Testing Kafka and Spring Boot](https://www.baeldung.com/spring-boot-kafka-testing) ### Intro From dac7bca3bf37cdeab0afc37efd88e95479245d65 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:00:13 +0800 Subject: [PATCH 196/590] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index 504c7ccdd0..1c8bf88c12 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -6,3 +6,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [JPA Entity Equality](https://www.baeldung.com/jpa-entity-equality) - [Ignoring Fields With the JPA @Transient Annotation](https://www.baeldung.com/jpa-transient-ignore-field) +- [Defining Indexes in JPA](https://www.baeldung.com/jpa-indexes) From 8e477f4d9c8aa91102c3e47bc493c78243c08580 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Wed, 18 Nov 2020 10:00:24 +0100 Subject: [PATCH 197/590] BAEL-4706 - Spring Boot with Spring Batch - Rename testcontainers test to LiveTest --- .../testcontainers/KafkaTestContainersLiveTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java index 972b6cce4d..74d6f824b1 100644 --- a/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java +++ b/spring-kafka/src/test/java/com/baeldung/kafka/testcontainers/KafkaTestContainersLiveTest.java @@ -36,11 +36,18 @@ import com.baeldung.kafka.embedded.KafkaConsumer; import com.baeldung.kafka.embedded.KafkaProducer; import com.baeldung.kafka.embedded.KafkaProducerConsumerApplication; +/** + * This test class uses Testcontainers to instantiate and manage an external Apache + * Kafka broker hosted inside a Docker container. + * + * Therefore, one of the prerequisites for using Testcontainers is that Docker is installed on the host running this test + * + */ @RunWith(SpringRunner.class) -@Import(com.baeldung.kafka.testcontainers.KafkaTestContainersIntegrationTest.KafkaTestContainersConfiguration.class) +@Import(com.baeldung.kafka.testcontainers.KafkaTestContainersLiveTest.KafkaTestContainersConfiguration.class) @SpringBootTest(classes = KafkaProducerConsumerApplication.class) @DirtiesContext -public class KafkaTestContainersIntegrationTest { +public class KafkaTestContainersLiveTest { @ClassRule public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3")); From d5f9419cab3923676a1b0e6e08c5bc150ba52f3f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:03:03 +0800 Subject: [PATCH 198/590] Update README.md --- maven-modules/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-modules/README.md b/maven-modules/README.md index 1ef664f879..19f0473a58 100644 --- a/maven-modules/README.md +++ b/maven-modules/README.md @@ -7,3 +7,4 @@ This module contains articles about Apache Maven. Please refer to its submodules - [Apache Maven Tutorial](https://www.baeldung.com/maven) - [Apache Maven Standard Directory Layout](https://www.baeldung.com/maven-directory-structure) - [Multi-Module Project with Maven](https://www.baeldung.com/maven-multi-module) +- [Maven Packaging Types](https://www.baeldung.com/maven-packaging-types) From 492a1643e66ee06d7587045895b957d732165971 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:04:40 +0800 Subject: [PATCH 199/590] Update README.md --- spring-boot-modules/spring-boot-basic-customization-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-basic-customization-2/README.md b/spring-boot-modules/spring-boot-basic-customization-2/README.md index faaee0962e..bf7e4abb76 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/README.md +++ b/spring-boot-modules/spring-boot-basic-customization-2/README.md @@ -4,4 +4,4 @@ This module contains articles about Spring Boot customization 2 ### Relevant Articles: - - [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/) + - [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/spring-boot-dispatcherservlet-web-xml) From 34e339767fe578966355c51c3b80245b7b7880a9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:09:46 +0800 Subject: [PATCH 200/590] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index 1c8bf88c12..50ea75d995 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -7,3 +7,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [JPA Entity Equality](https://www.baeldung.com/jpa-entity-equality) - [Ignoring Fields With the JPA @Transient Annotation](https://www.baeldung.com/jpa-transient-ignore-field) - [Defining Indexes in JPA](https://www.baeldung.com/jpa-indexes) +- [JPA CascadeType.REMOVE vs orphanRemoval](https://www.baeldung.com/jpa-cascade-remove-vs-orphanremoval) From d0cb67f305dfad2eb1644b827761277782f2a0e0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:14:44 +0800 Subject: [PATCH 201/590] Update README.md --- core-java-modules/core-java-15/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-15/README.md b/core-java-modules/core-java-15/README.md index 53989f5cbb..de503fbb31 100644 --- a/core-java-modules/core-java-15/README.md +++ b/core-java-modules/core-java-15/README.md @@ -4,4 +4,4 @@ This module contains articles about Java 15. ### Relevant articles -- TODO: add article links here +- [Sealed Classes and Interfaces in Java 15](https://www.baeldung.com/java-sealed-classes-interfaces) From 967e685937dda8bfb7deb364d830c35a7be41273 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Nov 2020 17:24:16 +0800 Subject: [PATCH 202/590] Update README.md --- core-kotlin-modules/core-kotlin-concurrency/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin-modules/core-kotlin-concurrency/README.md b/core-kotlin-modules/core-kotlin-concurrency/README.md index 09d9055a2b..22619b156f 100644 --- a/core-kotlin-modules/core-kotlin-concurrency/README.md +++ b/core-kotlin-modules/core-kotlin-concurrency/README.md @@ -5,3 +5,4 @@ This module contains articles about concurrency in Kotlin. ### Relevant articles: - [Threads vs Coroutines in Kotlin](https://www.baeldung.com/kotlin-threads-coroutines) - [Introduction to Kotlin Coroutines](https://www.baeldung.com/kotlin-coroutines) +- [Introduction to Channels in Kotlin](https://www.baeldung.com/kotlin/channels) From c0b7dc928a460ecf17b10a431f42d097cdad3d9a Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Wed, 18 Nov 2020 13:18:52 +0100 Subject: [PATCH 203/590] BAEL-4225 Thymeleaf Variables --- .../baeldung/thymeleaf/articles/Article.java | 28 +++++++++++++ .../articles/ArticlesController.java | 37 ++++++++++++++++++ .../templates/articles/articles-list.html | 39 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java create mode 100644 spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java create mode 100644 spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java new file mode 100644 index 0000000000..9b01328e45 --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java @@ -0,0 +1,28 @@ +package main.java.com.baeldung.thymeleaf.articles; + +public class Article { + + private String name; + private String url; + + public Article(String name, String url) { + this.name = name; + this.url = url; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java new file mode 100644 index 0000000000..401ef30156 --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -0,0 +1,37 @@ +package main.java.com.baeldung.thymeleaf.articles; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.Arrays; +import java.util.List; + +@Controller +@RequestMapping("/api/articles") +public class ArticlesController { + + @GetMapping + public String allArticles(Model model) { + model.addAttribute("articles", fetchArticles()); + return "articles/articles-list"; + } + + private List
fetchArticles() { + return Arrays.asList( + new Article( + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" + ), + new Article( + "Spring MVC Data and Thymeleaf", + "https://www.baeldung.com/spring-mvc-thymeleaf-data" + ) + ); + } +} diff --git a/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html b/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html new file mode 100644 index 0000000000..de03a86731 --- /dev/null +++ b/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html @@ -0,0 +1,39 @@ + + + + Thymeleaf Variables + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+

+
+ +
+
+ +
+
+
+ + \ No newline at end of file From 6a6ec8d9c232d5cd76adb4dda51f026ee8afb15a Mon Sep 17 00:00:00 2001 From: Karsten Silz <1061209+ksilz@users.noreply.github.com> Date: Wed, 18 Nov 2020 21:08:14 +0000 Subject: [PATCH 204/590] BAEL-4652: Running Spring Boot with PostgreSQL in Docker Compose (#10255) * Initial commit after Spring Starter Wizard. * Shortened class names. * Added Docker files, probably not working, yet. * Ignoring JAR files. * Docker files work now. * Fixed application start-up. * Creating & querying customer. * Simplified by removing "files" sub-folder for applicaton JAR file. * Removed more unnecessary settings. * Removed last "application.properties" setting since this is part of the Docker Compose file. * Final tweaking. --- docker/docker-spring-boot-postgres/.gitignore | 38 +++ .../.mvn/wrapper/MavenWrapperDownloader.java | 117 +++++++ .../.mvn/wrapper/maven-wrapper.jar | Bin 0 -> 50710 bytes .../.mvn/wrapper/maven-wrapper.properties | 2 + docker/docker-spring-boot-postgres/mvnw | 310 ++++++++++++++++++ docker/docker-spring-boot-postgres/mvnw.cmd | 182 ++++++++++ docker/docker-spring-boot-postgres/pom.xml | 48 +++ .../src/main/docker/Dockerfile | 7 + .../src/main/docker/docker-compose.yml | 22 ++ .../java/com/baeldung/docker/Customer.java | 57 ++++ .../baeldung/docker/CustomerRepository.java | 7 + .../com/baeldung/docker/DemoApplication.java | 43 +++ .../src/main/resources/application.properties | 0 .../baeldung/docker/DemoApplicationTests.java | 13 + 14 files changed, 846 insertions(+) create mode 100644 docker/docker-spring-boot-postgres/.gitignore create mode 100644 docker/docker-spring-boot-postgres/.mvn/wrapper/MavenWrapperDownloader.java create mode 100644 docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.jar create mode 100644 docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.properties create mode 100755 docker/docker-spring-boot-postgres/mvnw create mode 100644 docker/docker-spring-boot-postgres/mvnw.cmd create mode 100644 docker/docker-spring-boot-postgres/pom.xml create mode 100644 docker/docker-spring-boot-postgres/src/main/docker/Dockerfile create mode 100644 docker/docker-spring-boot-postgres/src/main/docker/docker-compose.yml create mode 100644 docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/Customer.java create mode 100644 docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/CustomerRepository.java create mode 100644 docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/DemoApplication.java create mode 100644 docker/docker-spring-boot-postgres/src/main/resources/application.properties create mode 100644 docker/docker-spring-boot-postgres/src/test/java/com/baeldung/docker/DemoApplicationTests.java diff --git a/docker/docker-spring-boot-postgres/.gitignore b/docker/docker-spring-boot-postgres/.gitignore new file mode 100644 index 0000000000..802324853e --- /dev/null +++ b/docker/docker-spring-boot-postgres/.gitignore @@ -0,0 +1,38 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + + +### Custom exclusions ### + +*.jar diff --git a/docker/docker-spring-boot-postgres/.mvn/wrapper/MavenWrapperDownloader.java b/docker/docker-spring-boot-postgres/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000..e76d1f3241 --- /dev/null +++ b/docker/docker-spring-boot-postgres/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.jar b/docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054 GIT binary patch literal 50710 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 EfAhh=DF6Tf literal 0 HcmV?d00001 diff --git a/docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.properties b/docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..642d572ce9 --- /dev/null +++ b/docker/docker-spring-boot-postgres/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/docker/docker-spring-boot-postgres/mvnw b/docker/docker-spring-boot-postgres/mvnw new file mode 100755 index 0000000000..a16b5431b4 --- /dev/null +++ b/docker/docker-spring-boot-postgres/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/docker/docker-spring-boot-postgres/mvnw.cmd b/docker/docker-spring-boot-postgres/mvnw.cmd new file mode 100644 index 0000000000..c8d43372c9 --- /dev/null +++ b/docker/docker-spring-boot-postgres/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/docker/docker-spring-boot-postgres/pom.xml b/docker/docker-spring-boot-postgres/pom.xml new file mode 100644 index 0000000000..f409ca7d92 --- /dev/null +++ b/docker/docker-spring-boot-postgres/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.4.0 + + + com.baeldung.docker + spring-boot-postgres-docker + 0.0.1-SNAPSHOT + spring-boot-postgres-docker + Demo project showing Spring Boot, PostgreSQL, and Docker + + + 11 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/docker/docker-spring-boot-postgres/src/main/docker/Dockerfile b/docker/docker-spring-boot-postgres/src/main/docker/Dockerfile new file mode 100644 index 0000000000..a642876cbe --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/main/docker/Dockerfile @@ -0,0 +1,7 @@ +FROM adoptopenjdk:11-jre-hotspot +MAINTAINER baeldung.com + +ARG JAR_FILE=*.jar +COPY ${JAR_FILE} application.jar + +ENTRYPOINT ["java", "-jar", "application.jar"] \ No newline at end of file diff --git a/docker/docker-spring-boot-postgres/src/main/docker/docker-compose.yml b/docker/docker-spring-boot-postgres/src/main/docker/docker-compose.yml new file mode 100644 index 0000000000..93aa634205 --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/main/docker/docker-compose.yml @@ -0,0 +1,22 @@ +version: '2' + +services: + app: + image: 'docker-spring-boot-postgres:latest' + build: + context: . + container_name: app + depends_on: + - db + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres + - SPRING_DATASOURCE_USERNAME=compose-postgres + - SPRING_DATASOURCE_PASSWORD=compose-postgres + - SPRING_JPA_HIBERNATE_DDL_AUTO=update + + db: + image: 'postgres:13.1-alpine' + container_name: db + environment: + - POSTGRES_USER=compose-postgres + - POSTGRES_PASSWORD=compose-postgres \ No newline at end of file diff --git a/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/Customer.java b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/Customer.java new file mode 100644 index 0000000000..9369a84287 --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/Customer.java @@ -0,0 +1,57 @@ +package com.baeldung.docker; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "customer") +public class Customer { + + @Id + @GeneratedValue + private long id; + + + @Column(name = "first_name", nullable = false) + private String firstName; + + @Column(name = "last_name", nullable = false) + private String lastName; + + public Customer() { + super(); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]"; + } + +} diff --git a/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/CustomerRepository.java b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/CustomerRepository.java new file mode 100644 index 0000000000..c959e00c89 --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/CustomerRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.docker; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CustomerRepository extends JpaRepository { + +} diff --git a/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/DemoApplication.java b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/DemoApplication.java new file mode 100644 index 0000000000..05377c6893 --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/main/java/com/baeldung/docker/DemoApplication.java @@ -0,0 +1,43 @@ +package com.baeldung.docker; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; + +@SpringBootApplication +public class DemoApplication { + private final Logger logger = LoggerFactory.getLogger(DemoApplication.class); + + @Autowired private CustomerRepository repository; + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + + @EventListener(ApplicationReadyEvent.class) + public void runAfterStartup() { + queryAllCustomers(); + createCustomer(); + queryAllCustomers(); + } + + private void createCustomer() { + Customer newCustomer = new Customer(); + newCustomer.setFirstName("John"); + newCustomer.setLastName("Doe"); + logger.info("Saving new customer..."); + this.repository.save(newCustomer); + } + + private void queryAllCustomers() { + List allCustomers = this.repository.findAll(); + logger.info("Number of customers: " + allCustomers.size()); + } + +} diff --git a/docker/docker-spring-boot-postgres/src/main/resources/application.properties b/docker/docker-spring-boot-postgres/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docker/docker-spring-boot-postgres/src/test/java/com/baeldung/docker/DemoApplicationTests.java b/docker/docker-spring-boot-postgres/src/test/java/com/baeldung/docker/DemoApplicationTests.java new file mode 100644 index 0000000000..87bd1dd6ba --- /dev/null +++ b/docker/docker-spring-boot-postgres/src/test/java/com/baeldung/docker/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.baeldung.docker; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +} From a198814d315766da0eef0bd5dd61e8e3e93cff50 Mon Sep 17 00:00:00 2001 From: Cicio Flaviu Date: Thu, 19 Nov 2020 16:48:03 +0200 Subject: [PATCH 205/590] [BAEL-4637] Performance difference between save() and saveAll() in Spring Data (#10177) * [BAEL-4637] Performance difference between save() and saveAll() in Spring Data * Apply suggestions from code review * Rename IBookRepository.java to BookRepository.java --- .../persistence/saveperformance/Book.java | 25 ++++++++++ .../saveperformance/BookApplication.java | 48 +++++++++++++++++++ .../saveperformance/BookRepository.java | 7 +++ 3 files changed, 80 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/Book.java create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookApplication.java create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookRepository.java diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/Book.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/Book.java new file mode 100644 index 0000000000..b6abdd2ed5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/Book.java @@ -0,0 +1,25 @@ +package com.baeldung.spring.data.persistence.saveperformance; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Book { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String title; + private String author; + + public Book(final String title, final String author) { + this.title = title; + this.author = author; + } + + public Book() { + } +} diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookApplication.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookApplication.java new file mode 100644 index 0000000000..56ad918be3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookApplication.java @@ -0,0 +1,48 @@ +package com.baeldung.spring.data.persistence.saveperformance; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; + +import java.util.ArrayList; +import java.util.List; + +@SpringBootApplication +public class BookApplication { + + @Autowired + private BookRepository bookRepository; + + public static void main(String[] args) { + SpringApplication.run(BookApplication.class, args); + } + + @EventListener(ApplicationReadyEvent.class) + public void executePerformanceBenchmark() { + + int bookCount = 10000; + + long start = System.currentTimeMillis(); + for(int i = 0; i < bookCount; i++) { + bookRepository.save(new Book("Book " + i, "Author " + i)); + } + long end = System.currentTimeMillis(); + bookRepository.deleteAll(); + + System.out.println("It took " + (end - start) + "ms to execute save() for " + bookCount + " books"); + + List bookList = new ArrayList<>(); + for (int i = 0; i < bookCount; i++) { + bookList.add(new Book("Book " + i, "Author " + i)); + } + + start = System.currentTimeMillis(); + bookRepository.saveAll(bookList); + end = System.currentTimeMillis(); + + System.out.println("It took " + (end - start) + "ms to execute saveAll() with " + bookCount + " books\n"); + + } +} diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookRepository.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookRepository.java new file mode 100644 index 0000000000..9db4a18796 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/BookRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.spring.data.persistence.saveperformance; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BookRepository extends JpaRepository { + +} From 6743c4de492c5937f4b2807b6630fe4a1f4ab1cb Mon Sep 17 00:00:00 2001 From: Maciej Glowka Date: Fri, 20 Nov 2020 00:42:56 +0100 Subject: [PATCH 206/590] BAEL-4725: examples of double comparison in Java --- core-java-modules/core-java-lang-3/pom.xml | 12 ++++ .../comparedouble/CompareDoubleUnitTest.java | 71 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java diff --git a/core-java-modules/core-java-lang-3/pom.xml b/core-java-modules/core-java-lang-3/pom.xml index de290717b1..f98074ad1b 100644 --- a/core-java-modules/core-java-lang-3/pom.xml +++ b/core-java-modules/core-java-lang-3/pom.xml @@ -23,6 +23,18 @@ ${assertj.version} test + + com.google.guava + guava + ${guava.version} + test + + + org.apache.commons + commons-math3 + 3.6.1 + test + diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java new file mode 100644 index 0000000000..c70dabd014 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java @@ -0,0 +1,71 @@ +package com.baeldung.comparedouble; + +import com.google.common.math.DoubleMath; +import org.apache.commons.math3.util.Precision; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; + +public class CompareDoubleUnitTest { + + @Test + public void givenDoubleValuesThatShouldHaveSameValue_whenUsingSimpleComparison_thenFails() { + double d1 = getFirstDouble(0); + + double d2 = .1 * 8; + + assertThat(d1 == d2).isFalse(); + } + + @Test + public void givenDoubleValuesThatShouldHaveSameValue_whenUsingThresholdComparison_thenSuccess() { + double d1 = getFirstDouble(0); + + double d2 = .1 * 8; + + double epsilon = 0.000001d; + + assertThat(Math.abs(d1 - d2) < epsilon).isTrue(); + } + + @Test + public void givenDoubleValuesThatShouldHaveSameValue_whenUsingGuavaFuzzyComparison_thenSuccess() { + double d1 = getFirstDouble(0); + double d2 = .1 * 8; + + double epsilon = 0.000001d; + + + assertThat(DoubleMath.fuzzyEquals(d1, d2, epsilon)).isTrue(); + } + + @Test + public void givenDoubleValuesThatShouldHaveSameValue_whenUsingCommonsMathComparison_thenSuccess() { + double d1 = getFirstDouble(0); + double d2 = .1 * 8; + + double epsilon = 0.000001d; + + + assertThat(Precision.equals(d1, d2, epsilon)).isTrue(); + assertThat(Precision.equals(d1, d2)).isTrue(); + } + + @Test + public void givenDoubleValuesThatShouldHaveSameValue_whenUsingJunitComparison_thenSuccess() { + double d1 = getFirstDouble(0); + double d2 = .1 * 8; + + double epsilon = 0.000001d; + + assertEquals(d1, d2, epsilon); + } + + private double getFirstDouble(double d1) { + for (int i = 1; i <= 8; i++) { + d1 += .1; + } + return d1; + } +} \ No newline at end of file From 683215b2fe3d1dcc29f0ea782fde9d7bced39bbd Mon Sep 17 00:00:00 2001 From: Vishal Akkalkote <10594502+vishal1023@users.noreply.github.com> Date: Fri, 20 Nov 2020 05:56:15 +0530 Subject: [PATCH 207/590] =?UTF-8?q?BAEL-4600=20|=20Add=20examples=20to=20d?= =?UTF-8?q?emonstrate=20the=20difference=20between=20Array=20=E2=80=A6=20(?= =?UTF-8?q?#10211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-4600 | Add examples to demonstrate the difference between Array Size vs ArrayList Capacity * BAEL-4600 | Refactor | Remove ArrayCreator and ArrayListCreator --- .../ArrayCreatorUnitTest.java | 20 ++++++++++++++ .../ArrayListCreatorUnitTest.java | 27 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java create mode 100644 core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java diff --git a/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java new file mode 100644 index 0000000000..74c8b93872 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.listcapacityvsarraysize; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class ArrayCreatorUnitTest { + + @Test + void whenSizeOfAnArrayIsNonZero_thenReturnNewArrayOfGivenSize() { + Integer[] array = new Integer[10]; + assertEquals(10, array.length); + } + + @Test + void whenSizeOfAnArrayIsLessThanZero_thenThrowException() { + assertThrows(NegativeArraySizeException.class, () -> { Integer[] array = new Integer[-1]; }); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java new file mode 100644 index 0000000000..62efe43af4 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.listcapacityvsarraysize; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class ArrayListCreatorUnitTest { + + @Test + void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithGivenCapacity() { + ArrayList list = new ArrayList<>(100); + + assertNotNull(list); + } + + @Test + void givenInvalidCapacityOfList_whenCreateListInvoked_thenThrowException() { + assertThrows(IllegalArgumentException.class, () -> new ArrayList<>(-1)); + } + + @Test + void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithSizeZero() { + assertEquals(0, new ArrayList(100).size()); + } +} \ No newline at end of file From 5b591b27b9057b6f194b65adc02be7ad6ec3b39e Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:39:42 +0100 Subject: [PATCH 208/590] BAEL-4225 Thymeleaf Variables --- .../articles/ArticlesController.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 401ef30156..e7c7e9b18d 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -20,18 +20,18 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( - new Article( - "Introduction to Using Thymeleaf in Spring", - "https://www.baeldung.com/thymeleaf-in-spring-mvc" - ), - new Article( - "Spring Boot CRUD Application with Thymeleaf", - "https://www.baeldung.com/spring-boot-crud-thymeleaf" - ), - new Article( - "Spring MVC Data and Thymeleaf", - "https://www.baeldung.com/spring-mvc-thymeleaf-data" - ) + new Article( + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" + ), + new Article( + "Spring MVC Data and Thymeleaf", + "https://www.baeldung.com/spring-mvc-thymeleaf-data" + ) ); } } From 6c88ec6a6c6a2c3830b08964e59ffb7849dbbcec Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:40:43 +0100 Subject: [PATCH 209/590] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index e7c7e9b18d..9db994bbf2 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -21,7 +21,7 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( new Article( - "Introduction to Using Thymeleaf in Spring", + "Introduction to Using Thymeleaf in Spring", "https://www.baeldung.com/thymeleaf-in-spring-mvc" ), new Article( From a329743e7bf2e2b8b7a7aed754a9815244c7fba3 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:41:01 +0100 Subject: [PATCH 210/590] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 9db994bbf2..3274c79222 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -24,9 +24,9 @@ public class ArticlesController { "Introduction to Using Thymeleaf in Spring", "https://www.baeldung.com/thymeleaf-in-spring-mvc" ), - new Article( - "Spring Boot CRUD Application with Thymeleaf", - "https://www.baeldung.com/spring-boot-crud-thymeleaf" + new Article( + "Spring Boot CRUD Application with Thymeleaf", + "https://www.baeldung.com/spring-boot-crud-thymeleaf" ), new Article( "Spring MVC Data and Thymeleaf", From e2239b4c6dba3d71a540ceb8241964338d937c32 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 20 Nov 2020 07:41:50 +0100 Subject: [PATCH 211/590] BAEL-4225 Thymeleaf Variables --- .../com/baeldung/thymeleaf/articles/ArticlesController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java index 3274c79222..cfbf0fcaa6 100644 --- a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java @@ -21,9 +21,9 @@ public class ArticlesController { private List
fetchArticles() { return Arrays.asList( new Article( - "Introduction to Using Thymeleaf in Spring", - "https://www.baeldung.com/thymeleaf-in-spring-mvc" - ), + "Introduction to Using Thymeleaf in Spring", + "https://www.baeldung.com/thymeleaf-in-spring-mvc" + ), new Article( "Spring Boot CRUD Application with Thymeleaf", "https://www.baeldung.com/spring-boot-crud-thymeleaf" From 95fbc41ce326e2d75cd93a640ed6d8dd1b563b1a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 20 Nov 2020 13:48:38 +0200 Subject: [PATCH 212/590] simplify random string generation --- .../kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt b/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt index 5b84d1f67d..20e635a579 100644 --- a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt +++ b/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt @@ -54,7 +54,7 @@ class RandomStringUnitTest { random.nextBytes(bytes) var randomString = (0..bytes.size - 1).map { i -> - charPool.get((bytes[i] and 0xFF.toByte() and (charPool.size-1).toByte()).toInt()) + charPool[random.nextInt(charPool.size)] }.joinToString("") assert(randomString.matches(Regex(ALPHANUMERIC_REGEX))) From ebf99bfd4fe39ef5e0873839d3ca75c48b493d93 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 20 Nov 2020 14:41:36 +0200 Subject: [PATCH 213/590] BAEL-3641 fix for creating directories inside a zip and handling missing entry for root folder in windows-created archives --- .../java/com/baeldung/unzip/UnzipFile.java | 81 +++++++++++-------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java index 140d809d44..b81b343042 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java +++ b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java @@ -8,39 +8,50 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class UnzipFile { - public static void main(final String[] args) throws IOException { - final String fileZip = "src/main/resources/unzipTest/compressed.zip"; - final File destDir = new File("src/main/resources/unzipTest"); - final byte[] buffer = new byte[1024]; - final ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip)); - ZipEntry zipEntry = zis.getNextEntry(); - while (zipEntry != null) { - final File newFile = newFile(destDir, zipEntry); - final FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - fos.close(); - zipEntry = zis.getNextEntry(); - } - zis.closeEntry(); - zis.close(); - } - - /** - * @see https://snyk.io/research/zip-slip-vulnerability - */ - public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { - File destFile = new File(destinationDir, zipEntry.getName()); - - String destDirPath = destinationDir.getCanonicalPath(); - String destFilePath = destFile.getCanonicalPath(); - - if (!destFilePath.startsWith(destDirPath + File.separator)) { - throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); - } - - return destFile; - } + public static void main(final String[] args) throws IOException { + final String fileZip = "src/main/resources/unzipTest/compressed.zip"; + final File destDir = new File("src/main/resources/unzipTest"); + final byte[] buffer = new byte[1024]; + final ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip)); + ZipEntry zipEntry = zis.getNextEntry(); + while (zipEntry != null) { + final File newFile = newFile(destDir, zipEntry); + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory " + newFile); + } + } else { + File parent = newFile.getParentFile(); + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory " + parent); + } + + final FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + } + zipEntry = zis.getNextEntry(); + } + zis.closeEntry(); + zis.close(); + } + + /** + * @see https://snyk.io/research/zip-slip-vulnerability + */ + public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); + + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); + + if (!destFilePath.startsWith(destDirPath + File.separator)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } + + return destFile; + } } \ No newline at end of file From f6ee5efc3f910377d54c6464be133b48bf978170 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 20 Nov 2020 14:42:56 +0200 Subject: [PATCH 214/590] formatting --- .../java/com/baeldung/unzip/UnzipFile.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java index b81b343042..a18663f544 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java +++ b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java @@ -8,50 +8,50 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class UnzipFile { - public static void main(final String[] args) throws IOException { - final String fileZip = "src/main/resources/unzipTest/compressed.zip"; - final File destDir = new File("src/main/resources/unzipTest"); - final byte[] buffer = new byte[1024]; - final ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip)); - ZipEntry zipEntry = zis.getNextEntry(); - while (zipEntry != null) { - final File newFile = newFile(destDir, zipEntry); - if (zipEntry.isDirectory()) { - if (!newFile.isDirectory() && !newFile.mkdirs()) { - throw new IOException("Failed to create directory " + newFile); - } - } else { - File parent = newFile.getParentFile(); - if (!parent.isDirectory() && !parent.mkdirs()) { - throw new IOException("Failed to create directory " + parent); - } + public static void main(final String[] args) throws IOException { + final String fileZip = "src/main/resources/unzipTest/compressed.zip"; + final File destDir = new File("src/main/resources/unzipTest"); + final byte[] buffer = new byte[1024]; + final ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip)); + ZipEntry zipEntry = zis.getNextEntry(); + while (zipEntry != null) { + final File newFile = newFile(destDir, zipEntry); + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory " + newFile); + } + } else { + File parent = newFile.getParentFile(); + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory " + parent); + } - final FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - fos.close(); - } - zipEntry = zis.getNextEntry(); - } - zis.closeEntry(); - zis.close(); - } + final FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + } + zipEntry = zis.getNextEntry(); + } + zis.closeEntry(); + zis.close(); + } - /** - * @see https://snyk.io/research/zip-slip-vulnerability - */ - public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { - File destFile = new File(destinationDir, zipEntry.getName()); + /** + * @see https://snyk.io/research/zip-slip-vulnerability + */ + public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); - String destDirPath = destinationDir.getCanonicalPath(); - String destFilePath = destFile.getCanonicalPath(); + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); - if (!destFilePath.startsWith(destDirPath + File.separator)) { - throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); - } + if (!destFilePath.startsWith(destDirPath + File.separator)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } - return destFile; - } + return destFile; + } } \ No newline at end of file From 567a63cb7da115bfa85690dc1c94dcbb67b8e3f5 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 20 Nov 2020 07:49:50 -0700 Subject: [PATCH 215/590] Update formatting --- core-java-modules/core-java-15/pom.xml | 4 ++-- .../java/com/baeldung/whatsnew/records/Person.java | 9 +++------ .../baeldung/whatsnew/sealedclasses/Employee.java | 6 ++---- .../com/baeldung/whatsnew/sealedclasses/Manager.java | 3 +-- .../com/baeldung/whatsnew/sealedclasses/Person.java | 12 ++++-------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index c6f1454078..df8aeafca9 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -51,8 +51,8 @@ ${maven.compiler.release} --enable-preview - 15 - 15 + 14 + 14 diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java index 67d3151440..74cf5edf9c 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java @@ -3,15 +3,12 @@ package com.baeldung.whatsnew.records; /** * Java record with a header indicating 2 fields. */ -public record Person(String name, int age) -{ +public record Person(String name, int age) { /** * Public constructor that does some basic validation. */ - public Person - { - if (age < 0) - { + public Person { + if (age < 0) { throw new IllegalArgumentException("Age cannot be negative"); } } diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java index 72ef75cb7c..ec85c371b7 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java @@ -2,10 +2,8 @@ package com.baeldung.whatsnew.sealedclasses; import java.util.Date; -public non-sealed class Employee extends Person -{ - public Date getHiredDate() - { +public non-sealed class Employee extends Person { + public Date getHiredDate() { return new Date(); } } diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java index 87cbcf2673..79c50b057e 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java @@ -1,5 +1,4 @@ package com.baeldung.whatsnew.sealedclasses; -public final class Manager extends Person -{ +public final class Manager extends Person { } diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java index d4beb64867..2a52bc1a73 100644 --- a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java +++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java @@ -2,23 +2,19 @@ package com.baeldung.whatsnew.sealedclasses; import java.util.Date; -public sealed class Person permits Employee, Manager -{ +public sealed class Person permits Employee, Manager { /** * Demonstration of pattern matching for instanceof * * @param person A Person object * @return */ - public static void patternMatchingDemo(Person person) - { - if(person instanceof Employee employee) - { + public static void patternMatchingDemo(Person person) { + if(person instanceof Employee employee) { Date hiredDate = employee.getHiredDate(); } - if(person instanceof Employee employee && employee.getHiredDate() != null) - { + if(person instanceof Employee employee && employee.getHiredDate() != null) { Date hiredDate = employee.getHiredDate(); } } From 58750bce50d2f28267bce5350666c4a82053474a Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 20 Nov 2020 16:31:01 +0100 Subject: [PATCH 216/590] JAVA-3580: Migrate spring-testing to the parent-boot-2 --- testing-modules/spring-testing/pom.xml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index c5e94f3afc..f26b0f27ec 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -3,16 +3,15 @@ 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 - com.baeldung spring-testing 0.1-SNAPSHOT spring-testing com.baeldung - parent-java + parent-boot-2 0.0.1-SNAPSHOT - ../../parent-java + ../../parent-boot-2 @@ -32,25 +31,23 @@ org.springframework.boot spring-boot-starter - LATEST org.springframework.boot spring-boot-starter-test - LATEST test org.springframework spring-core - LATEST + ${spring.version} org.springframework spring-context - LATEST + ${spring.version} org.springframework @@ -65,7 +62,6 @@ org.springframework.data spring-data-jpa - LATEST org.junit.jupiter @@ -116,9 +112,9 @@ 2.0.0.0 3.1.6 - 5.5.0 - 1.5.2 - 5.1.4.RELEASE + 5.7.0 + 1.7.0 + 5.2.8.RELEASE 4.0.1 2.1.1 From 390b864ff385b25483e80806098bc1ad27b44441 Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Fri, 20 Nov 2020 17:44:42 +0000 Subject: [PATCH 217/590] BAEL-4742-Guide-To-System-Stubs --- testing-modules/testing-libraries-2/pom.xml | 41 ++++++++++++++++ .../SystemLambdaComparisonUnitTest.java | 49 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemLambdaComparisonUnitTest.java diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index 282583c882..dd863af6ee 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -9,6 +9,7 @@ com.baeldung testing-modules 1.0.0-SNAPSHOT + ../ @@ -24,6 +25,44 @@ ${system-lambda.version} test + + uk.org.webcompere + system-stubs-jupiter + ${system-stubs.version} + test + + + uk.org.webcompere + system-stubs-junit4 + ${system-stubs.version} + test + + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + @@ -39,5 +78,7 @@ 1.19.0 1.0.0 + 1.0.0 + 5.6.2 diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemLambdaComparisonUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemLambdaComparisonUnitTest.java new file mode 100644 index 0000000000..23e65767a8 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemLambdaComparisonUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.properties.SystemProperties; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties; +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; +import static org.junit.Assert.assertEquals; + +@ExtendWith(SystemStubsExtension.class) +class SystemLambdaComparisonUnitTest { + @SystemStub + private EnvironmentVariables environmentVariables = + new EnvironmentVariables("ADDRESS", "https://www.baeldung.com"); + + @SystemStub + private SystemProperties systemProperties = new SystemProperties(); + + @Test + void aSingleSystemLambda() throws Exception { + restoreSystemProperties(() -> { + System.setProperty("log_dir", "test/resources"); + assertEquals("test/resources", System.getProperty("log_dir")); + }); + } + + @Test + void multipleSystemLambdas() throws Exception { + restoreSystemProperties(() -> { + withEnvironmentVariable("URL", "https://www.baeldung.com") + .execute(() -> { + System.setProperty("log_dir", "test/resources"); + assertEquals("test/resources", System.getProperty("log_dir")); + assertEquals("https://www.baeldung.com", System.getenv("URL")); + }); + }); + } + + @Test + void multipleSystemStubs() { + System.setProperty("log_dir", "test/resources"); + assertEquals("test/resources", System.getProperty("log_dir")); + assertEquals("https://www.baeldung.com", System.getenv("ADDRESS")); + } +} From 94aa14c43a5b41935bf1f1c025f9b917388c4c9c Mon Sep 17 00:00:00 2001 From: Tomas Skalicky Date: Sat, 21 Nov 2020 09:51:59 +0100 Subject: [PATCH 218/590] GraphQL schema file added, fix of PostResolver - graphqls was missing - author in Post is mandatory --- .../com/baeldung/graphql/PostResolver.java | 6 ++--- .../src/main/resources/graphql/post.graphqls | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java index dbfde330ea..329d1f469a 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java @@ -1,7 +1,5 @@ package com.baeldung.graphql; -import java.util.Optional; - import com.coxautodev.graphql.tools.GraphQLResolver; public class PostResolver implements GraphQLResolver { @@ -11,7 +9,7 @@ public class PostResolver implements GraphQLResolver { this.authorDao = authorDao; } - public Optional getAuthor(Post post) { - return authorDao.getAuthor(post.getAuthorId()); + public Author getAuthor(Post post) { + return authorDao.getAuthor(post.getAuthorId()).orElseThrow(RuntimeException::new); } } diff --git a/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls b/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls new file mode 100644 index 0000000000..0e42f7255c --- /dev/null +++ b/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls @@ -0,0 +1,24 @@ +type Post { + id: ID! + title: String! + text: String! + category: String + author: Author! +} + +type Author { + id: ID! + name: String! + thumbnail: String + posts: [Post]! +} + +# The Root Query for the application +type Query { + recentPosts(count: Int, offset: Int): [Post]! +} + +# The Root Mutation for the application +type Mutation { + writePost(title: String!, text: String!, category: String, author: String!) : Post! +} From 83d16d3ade028b9c3d16d90af74b9bb145d2ce21 Mon Sep 17 00:00:00 2001 From: Tomas Skalicky Date: Sat, 21 Nov 2020 09:52:46 +0100 Subject: [PATCH 219/590] security disabled for easier experimenting --- .../src/main/java/com/baeldung/demo/DemoApplication.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java index eb091b4695..e30ee6104d 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java @@ -2,12 +2,14 @@ package com.baeldung.demo; import com.baeldung.graphql.GraphqlConfiguration; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; - +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.context.annotation.Import; @SpringBootApplication @Import(GraphqlConfiguration.class) +@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class}) public class DemoApplication { public static void main(String[] args) { From 1332044479a7ea83984368a2741ebb2190073339 Mon Sep 17 00:00:00 2001 From: Tomas Skalicky Date: Sat, 21 Nov 2020 09:53:18 +0100 Subject: [PATCH 220/590] server port changed to 8081 for avoiding conflicts --- .../spring-boot-libraries/src/main/resources/demo.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 spring-boot-modules/spring-boot-libraries/src/main/resources/demo.yml diff --git a/spring-boot-modules/spring-boot-libraries/src/main/resources/demo.yml b/spring-boot-modules/spring-boot-libraries/src/main/resources/demo.yml new file mode 100644 index 0000000000..11e54c5449 --- /dev/null +++ b/spring-boot-modules/spring-boot-libraries/src/main/resources/demo.yml @@ -0,0 +1,2 @@ +server: + port: 8081 From e3c28ba8a5545d71d1f98313c49356cb50d43f62 Mon Sep 17 00:00:00 2001 From: Tomas Skalicky Date: Sat, 21 Nov 2020 09:53:42 +0100 Subject: [PATCH 221/590] sample queries, both Query and Mutation, added --- .../spring-boot-libraries/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spring-boot-modules/spring-boot-libraries/README.md b/spring-boot-modules/spring-boot-libraries/README.md index 10c56ca576..6976435866 100644 --- a/spring-boot-modules/spring-boot-libraries/README.md +++ b/spring-boot-modules/spring-boot-libraries/README.md @@ -15,3 +15,21 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Boot and Togglz Aspect](https://www.baeldung.com/spring-togglz) - [Getting Started with GraphQL and Spring Boot](https://www.baeldung.com/spring-graphql) - [An Introduction to Kong](https://www.baeldung.com/kong) + +### GraphQL sample queries + +Query +```shell script +curl \ +--request POST 'localhost:8081/graphql' \ +--header 'Content-Type: application/json' \ +--data-raw '{"query":"query {\n recentPosts(count: 2, offset: 0) {\n id\n title\n author {\n id\n posts {\n id\n }\n }\n }\n}"}' +``` + +Mutation +```shell script +curl \ +--request POST 'localhost:8081/graphql' \ +--header 'Content-Type: application/json' \ +--data-raw '{"query":"mutation {\n writePost(title: \"New Title\", author: \"Author2\", text: \"New Text\") {\n id\n category\n author {\n id\n name\n }\n }\n}"}' +``` From 761e38f0a1965dcc5752bd8e622b91fcaaf3e683 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Sat, 21 Nov 2020 15:35:14 +0530 Subject: [PATCH 222/590] Corrected the changes based on review comment --- .../nosuchfielderror/{Dependent.java => Dependency.java} | 2 +- .../baeldung/exceptions/nosuchfielderror/FieldErrorExample.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/{Dependent.java => Dependency.java} (88%) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java similarity index 88% rename from core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java rename to core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java index 9e222c5a87..31ac54ac6b 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependent.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java @@ -1,6 +1,6 @@ package com.baeldung.exceptions.nosuchfielderror; -public class Dependent { +public class Dependency { // This needed to be commented post compilation of NoSuchFielDError and Compile public static String message = "Hello Baeldung!!"; diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java index a55bacab75..021ed57d87 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java @@ -9,7 +9,7 @@ public class FieldErrorExample { public static String getDependentMessage() { - return Dependent.message; + return Dependency.message; } public static void fetchAndPrint() { From 6e54323282acaecd3f8fbca9a93bb2545e4de1ce Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Sun, 22 Nov 2020 13:20:43 +0200 Subject: [PATCH 223/590] Determine if an Integer's Square Root Is an Integer in Java Article by Abdallah Sawan --- .../perfectsquare/PerfectSquareUtil.java | 49 +++++++++++++++++++ .../perfectsquare/PerfectSquareUnitTest.java | 27 ++++++++++ 2 files changed, 76 insertions(+) create mode 100644 java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java create mode 100644 java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java diff --git a/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java b/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java new file mode 100644 index 0000000000..bd08fbe60b --- /dev/null +++ b/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java @@ -0,0 +1,49 @@ +package com.baeldung.perfectsquare; + +public class PerfectSquareUtil { + + public static boolean isPerfectSquareByUsingSqrt(long n) { + if (n <= 0) + return false; + double perfectSquare = Math.sqrt(n); + long tst = (long)(perfectSquare + 0.5); + return tst*tst == n; + } + + public static boolean isPerfectSquareByUsingBinarySearch(long low, long high, long number) { + long check = (low + high) / 2L; + if (high < low) + return false; + if (number == check * check) { + return true; + } else if (number < check * check) { + high = check - 1L; + return isPerfectSquareByUsingBinarySearch(low, high, number); + } else { + low = check + 1L; + return isPerfectSquareByUsingBinarySearch(low, high, number); + } + } + + public static boolean isPerfectSquareByUsingNewtonMethod(long n) { + long x1 = n; + long x2 = 1L; + while (x1 > x2) { + x1 = (x1 + x2) / 2L; + x2 = n / x1; + } + return x1 == x2 && n % x1 == 0L; + } + + public static boolean isSquareNumberWithOptimization(long n) { + if (n < 0) + return false; + switch ((int) (n & 0xF)) { + case 0: case 1: case 4: case 9: + long tst = (long) Math.sqrt(n); + return tst * tst == n; + default: + return false; + } + } +} diff --git a/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java new file mode 100644 index 0000000000..30ab95f963 --- /dev/null +++ b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.perfectsquare; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class PerfectSquareUnitTest { + + @Test + public void test0xFFAssignedToInteger() { + long n = 18676209273604L; //‬ 18676209273604 = 43621598 * 43621598 + boolean expectedValue = true; + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); + assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n)); + } + + @Test + public void test0xFFAssignedToByte() { + long n = 549790047707L; // prime number + boolean expectedValue = false; + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); + assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n)); + } +} From 6526ccbf35dc6fd3b053d6ce3fb1d7c55c6220e2 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Sun, 22 Nov 2020 13:22:45 +0200 Subject: [PATCH 224/590] Determine if an Integer's Square Root Is an Integer in Java Article by Abdallah Sawan --- .../java/com/baeldung/perfectsquare/PerfectSquareUtil.java | 2 +- .../com/baeldung/perfectsquare/PerfectSquareUnitTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java b/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java index bd08fbe60b..61093ba816 100644 --- a/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java +++ b/java-numbers-4/src/main/java/com/baeldung/perfectsquare/PerfectSquareUtil.java @@ -35,7 +35,7 @@ public class PerfectSquareUtil { return x1 == x2 && n % x1 == 0L; } - public static boolean isSquareNumberWithOptimization(long n) { + public static boolean isPerfectSquareWithOptimization(long n) { if (n < 0) return false; switch ((int) (n & 0xF)) { diff --git a/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java index 30ab95f963..334b95ea9d 100644 --- a/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java @@ -12,7 +12,7 @@ public class PerfectSquareUnitTest { assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); - assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n)); } @Test @@ -22,6 +22,6 @@ public class PerfectSquareUnitTest { assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); - assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n)); + assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n)); } } From 48a5af66e9b63760b70ed5167331abb68d2c235d Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sun, 22 Nov 2020 19:28:07 +0100 Subject: [PATCH 225/590] BAEL-3720: Add missing code examples (#10264) --- .../SpringResourceIntegrationTest.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/spring-core/src/test/java/com/baeldung/classpathfileaccess/SpringResourceIntegrationTest.java b/spring-core/src/test/java/com/baeldung/classpathfileaccess/SpringResourceIntegrationTest.java index b57a64a8c6..38f857b42e 100644 --- a/spring-core/src/test/java/com/baeldung/classpathfileaccess/SpringResourceIntegrationTest.java +++ b/spring-core/src/test/java/com/baeldung/classpathfileaccess/SpringResourceIntegrationTest.java @@ -1,16 +1,5 @@ package com.baeldung.classpathfileaccess; -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.util.stream.Collectors; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +13,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.util.ResourceUtils; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; + /** * Test class illustrating various methods of accessing a file from the classpath using Resource. * @author tritty @@ -55,7 +55,7 @@ public class SpringResourceIntegrationTest { @Test public void whenResourceLoader_thenReadSuccessful() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:data/employees.dat"); + final Resource resource = loadEmployeesWithResourceLoader(); final String employees = new String(Files.readAllBytes(resource.getFile() .toPath())); assertEquals(EMPLOYEES_EXPECTED, employees); @@ -63,7 +63,7 @@ public class SpringResourceIntegrationTest { @Test public void whenApplicationContext_thenReadSuccessful() throws IOException { - final Resource resource = appContext.getResource("classpath:data/employees.dat"); + final Resource resource = loadEmployeesWithApplicationContext(); final String employees = new String(Files.readAllBytes(resource.getFile() .toPath())); assertEquals(EMPLOYEES_EXPECTED, employees); @@ -85,7 +85,7 @@ public class SpringResourceIntegrationTest { @Test public void whenResourceAsStream_thenReadSuccessful() throws IOException { - final InputStream resource = new ClassPathResource("data/employees.dat").getInputStream(); + final InputStream resource = loadEmployeesWithClassPathResource().getInputStream(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) { final String employees = reader.lines() .collect(Collectors.joining("\n")); @@ -95,7 +95,7 @@ public class SpringResourceIntegrationTest { @Test public void whenResourceAsFile_thenReadSuccessful() throws IOException { - final File resource = new ClassPathResource("data/employees.dat").getFile(); + final File resource = loadEmployeesWithClassPathResource().getFile(); final String employees = new String(Files.readAllBytes(resource.toPath())); assertEquals(EMPLOYEES_EXPECTED, employees); } @@ -114,7 +114,19 @@ public class SpringResourceIntegrationTest { assertEquals(EMPLOYEES_EXPECTED, employees); } - public File loadEmployeesWithSpringInternalClass() throws FileNotFoundException { + private File loadEmployeesWithSpringInternalClass() throws FileNotFoundException { return ResourceUtils.getFile("classpath:data/employees.dat"); } + + private Resource loadEmployeesWithClassPathResource(){ + return new ClassPathResource("data/employees.dat"); + } + + private Resource loadEmployeesWithResourceLoader(){ + return resourceLoader.getResource("classpath:data/employees.dat"); + } + + private Resource loadEmployeesWithApplicationContext(){ + return appContext.getResource("classpath:data/employees.dat"); + } } From aaac4e6a95e5e274c60418034e74ca1a2679a6ea Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 23 Nov 2020 09:56:16 +0530 Subject: [PATCH 226/590] Added changes to fix the details --- ...oncurrentHashMapVsSynchronizedMapTest.java | 159 ++++++++++++++++++ .../ConcurrentModificationErrorTest.java | 41 +++++ .../cuncurrenthashmap/PerformanceTest.java | 54 ++++++ .../map/cuncurrenthashmap/UserId.java | 17 ++ 4 files changed, 271 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java new file mode 100644 index 0000000000..6a7716d38a --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java @@ -0,0 +1,159 @@ +package com.baeldung.map.cuncurrenthashmap; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Test; + +public class ConcurrentHashMapVsSynchronizedMapTest { + + public final static int THREAD_POOL_SIZE = 5; + public final static int TEST_ITERATIONS = 5; + public final static int TEST_NO_ITEMS = 500000; + + @Test + public void randomReadAndWritePerformaceTest_cuncurrentHashMap_faster() + throws InterruptedException { + // For synchronizedMap + Long totalTimeForSynchronizedMap = 0l; + Map slowerMap = Collections + .synchronizedMap(new HashMap()); + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForSynchronizedMap += performReadAndWriteTest(slowerMap); + } + Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; + + // For ConcurrentHashMap Object + Long totalTimeForCuncurrentHashMap = 0l; + Map fasterMap = new ConcurrentHashMap<>(); + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForCuncurrentHashMap += performReadAndWriteTest(fasterMap); + } + Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + } + + @Test + public void randomWritePerformaceTest_cuncurrentHashMap_faster() throws InterruptedException { + // For synchronizedMap + Long totalTimeForSynchronizedMap = 0l; + Map slowerMap = Collections + .synchronizedMap(new HashMap()); + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForSynchronizedMap += performWriteTest(slowerMap); + } + Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; + + // For ConcurrentHashMap Object + Long totalTimeForCuncurrentHashMap = 0l; + Map fasterMap = new ConcurrentHashMap<>(); + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForCuncurrentHashMap += performWriteTest(fasterMap); + } + Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + } + + @Test + public void randomReadPerformaceTest_cuncurrentHashMap_faster() throws InterruptedException { + + Map slowerMap = Collections + .synchronizedMap(addItems(new HashMap())); + // For synchronizedMap + Long totalTimeForSynchronizedMap = 0l; + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForSynchronizedMap += performReadTest(slowerMap); + } + Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; + + Map fasterMap = Collections + .synchronizedMap(addItems(new ConcurrentHashMap())); + // For ConcurrentHashMap Object + Long totalTimeForCuncurrentHashMap = 0l; + new ConcurrentHashMap<>(); + for (int i = 0; i < TEST_ITERATIONS; i++) { + totalTimeForCuncurrentHashMap += performReadTest(fasterMap); + } + Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + } + + private Map addItems(Map map) { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.put(String.valueOf(randNumber), randNumber); + } + return map; + } + + private long performWriteTest(final Map map) throws InterruptedException { + long startTime = System.nanoTime(); + ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + for (int j = 0; j < THREAD_POOL_SIZE; j++) { + exectures.execute(new Runnable() { + @Override + public void run() { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.put(String.valueOf(randNumber), randNumber); + } + } + }); + } + exectures.shutdown(); + exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); + long entTime = System.nanoTime(); + return (entTime - startTime) / 1000000L; + } + + private long performReadAndWriteTest(final Map map) + throws InterruptedException { + long startTime = System.nanoTime(); + ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + for (int j = 0; j < THREAD_POOL_SIZE; j++) { + exectures.execute(new Runnable() { + @Override + public void run() { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + Integer value = map.get(String.valueOf(randNumber)); + map.put(String.valueOf(randNumber), randNumber); + } + } + }); + } + exectures.shutdown(); + exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); + long entTime = System.nanoTime(); + return (entTime - startTime) / 1000000L; + } + + private long performReadTest(final Map map) throws InterruptedException { + long startTime = System.nanoTime(); + ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + for (int j = 0; j < THREAD_POOL_SIZE; j++) { + exectures.execute(new Runnable() { + @Override + public void run() { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + Integer value = map.get(String.valueOf(randNumber)); + } + } + }); + } + exectures.shutdown(); + exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); + long entTime = System.nanoTime(); + return (entTime - startTime) / 1000000L; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java new file mode 100644 index 0000000000..993354d6d0 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java @@ -0,0 +1,41 @@ +package com.baeldung.map.cuncurrenthashmap; + +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.Assert; +import org.junit.Test; + +public class ConcurrentModificationErrorTest { + + @Test(expected = ConcurrentModificationException.class) + public void whenRemoveAndAddOnHashMap_thenCuncurrentModificationError() { + Map map = new HashMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Map synchronizedMap = Collections.synchronizedMap(map); + Iterator> iterator = synchronizedMap.entrySet().iterator(); + while (iterator.hasNext()) { + synchronizedMap.put(4, "Modification"); + iterator.next(); + } + } + + public void whenRemoveAndAddOnCuncurrentHashMap_thenNoError() { + Map map = new ConcurrentHashMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Iterator> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + map.put(4, "Modification"); + iterator.next(); + } + + Assert.assertEquals(4, map.size()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java new file mode 100644 index 0000000000..9751decf53 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java @@ -0,0 +1,54 @@ +package com.baeldung.map.cuncurrenthashmap; + +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.Test; + +public class PerformanceTest { + + @Test(expected = ConcurrentModificationException.class) + public void whenRemoveAndAddOnHashMap_thenCuncurrentModificationError() { + Map map = new HashMap<>(); + Map synchronizedMap = Collections.synchronizedMap(map); + long startTime = System.currentTimeMillis(); + for(int i=0; i<100000; i++) { + UserId userId = new UserId(1); + synchronizedMap.put(userId, userId.toString()); + } + long endTime = System.currentTimeMillis(); + long addTimeForSynchronized = endTime-startTime; + + startTime = System.currentTimeMillis(); + for(int i=0; i<100000; i++) { + UserId userId = new UserId(1); + synchronizedMap.get(userId); + } + endTime = System.currentTimeMillis(); + long fetchTimeForSynchronized = endTime-startTime; + + Map map1 = new ConcurrentHashMap<>(); + startTime = System.currentTimeMillis(); + for(int i=0; i<100000; i++) { + UserId userId = new UserId(1); + map1.put(userId, userId.toString()); + } + endTime = System.currentTimeMillis(); + long addTimeForConcurrent = endTime-startTime; + + startTime = System.currentTimeMillis(); + for(int i=0; i<100000; i++) { + UserId userId = new UserId(1); + map1.get(userId); + } + endTime = System.currentTimeMillis(); + long fetchTimeForConcurrent = endTime-startTime; + + System.out.println("ABC"); + + } + +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java new file mode 100644 index 0000000000..a69976180d --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java @@ -0,0 +1,17 @@ +package com.baeldung.map.cuncurrenthashmap; + +public class UserId { + + private int id; + + public UserId(int id) { + super(); + this.id = id; + } + + @Override + public int hashCode() { + return this.id%10; + } + +} From 61f4eb62a77c2a70679a96a81d5370388424832c Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 23 Nov 2020 14:54:44 +0530 Subject: [PATCH 227/590] BAEL-4686: Performance test --- ...hMapVsSynchronizedMapPerformanceTest.java} | 41 +++++++------- .../ConcurrentModificationErrorTest.java | 6 +-- .../cuncurrenthashmap/PerformanceTest.java | 54 ------------------- .../map/cuncurrenthashmap/UserId.java | 17 ------ 4 files changed, 23 insertions(+), 95 deletions(-) rename core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/{cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java => concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java} (82%) rename core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/{cuncurrenthashmap => concurrenthashmap}/ConcurrentModificationErrorTest.java (87%) delete mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java delete mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java similarity index 82% rename from core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java rename to core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java index 6a7716d38a..eb0c58a8b0 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentHashMapVsSynchronizedMapTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java @@ -1,4 +1,4 @@ -package com.baeldung.map.cuncurrenthashmap; +package com.baeldung.map.concurrenthashmap; import java.util.Collections; import java.util.HashMap; @@ -11,14 +11,14 @@ import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; -public class ConcurrentHashMapVsSynchronizedMapTest { +public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { public final static int THREAD_POOL_SIZE = 5; public final static int TEST_ITERATIONS = 5; public final static int TEST_NO_ITEMS = 500000; @Test - public void randomReadAndWritePerformaceTest_cuncurrentHashMap_faster() + public void randomReadAndWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { // For synchronizedMap Long totalTimeForSynchronizedMap = 0l; @@ -30,18 +30,18 @@ public class ConcurrentHashMapVsSynchronizedMapTest { Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; // For ConcurrentHashMap Object - Long totalTimeForCuncurrentHashMap = 0l; + Long totalTimeForConcurrentHashMap = 0l; Map fasterMap = new ConcurrentHashMap<>(); for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForCuncurrentHashMap += performReadAndWriteTest(fasterMap); + totalTimeForConcurrentHashMap += performReadAndWriteTest(fasterMap); } - Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); } @Test - public void randomWritePerformaceTest_cuncurrentHashMap_faster() throws InterruptedException { + public void randomWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { // For synchronizedMap Long totalTimeForSynchronizedMap = 0l; Map slowerMap = Collections @@ -52,18 +52,18 @@ public class ConcurrentHashMapVsSynchronizedMapTest { Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; // For ConcurrentHashMap Object - Long totalTimeForCuncurrentHashMap = 0l; + Long totalTimeForConcurrentHashMap = 0l; Map fasterMap = new ConcurrentHashMap<>(); for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForCuncurrentHashMap += performWriteTest(fasterMap); + totalTimeForConcurrentHashMap += performWriteTest(fasterMap); } - Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); } @Test - public void randomReadPerformaceTest_cuncurrentHashMap_faster() throws InterruptedException { + public void randomReadPerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { Map slowerMap = Collections .synchronizedMap(addItems(new HashMap())); @@ -74,17 +74,16 @@ public class ConcurrentHashMapVsSynchronizedMapTest { } Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; - Map fasterMap = Collections - .synchronizedMap(addItems(new ConcurrentHashMap())); + Map fasterMap = addItems(new ConcurrentHashMap()); // For ConcurrentHashMap Object - Long totalTimeForCuncurrentHashMap = 0l; + Long totalTimeForConcurrentHashMap = 0l; new ConcurrentHashMap<>(); for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForCuncurrentHashMap += performReadTest(fasterMap); + totalTimeForConcurrentHashMap += performReadTest(fasterMap); } - Long avgTimeForCuncurrentHashMap = totalTimeForCuncurrentHashMap / TEST_ITERATIONS; + Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForCuncurrentHashMap); + Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); } private Map addItems(Map map) { @@ -125,7 +124,7 @@ public class ConcurrentHashMapVsSynchronizedMapTest { public void run() { for (int i = 0; i < TEST_NO_ITEMS; i++) { Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - Integer value = map.get(String.valueOf(randNumber)); + map.get(String.valueOf(randNumber)); map.put(String.valueOf(randNumber), randNumber); } } @@ -146,7 +145,7 @@ public class ConcurrentHashMapVsSynchronizedMapTest { public void run() { for (int i = 0; i < TEST_NO_ITEMS; i++) { Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - Integer value = map.get(String.valueOf(randNumber)); + map.get(String.valueOf(randNumber)); } } }); diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java similarity index 87% rename from core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java rename to core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java index 993354d6d0..998496720e 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/ConcurrentModificationErrorTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java @@ -1,4 +1,4 @@ -package com.baeldung.map.cuncurrenthashmap; +package com.baeldung.map.concurrenthashmap; import java.util.Collections; import java.util.ConcurrentModificationException; @@ -14,7 +14,7 @@ import org.junit.Test; public class ConcurrentModificationErrorTest { @Test(expected = ConcurrentModificationException.class) - public void whenRemoveAndAddOnHashMap_thenCuncurrentModificationError() { + public void whenRemoveAndAddOnHashMap_thenConcurrentModificationError() { Map map = new HashMap<>(); map.put(1, "baeldung"); map.put(2, "HashMap"); @@ -26,7 +26,7 @@ public class ConcurrentModificationErrorTest { } } - public void whenRemoveAndAddOnCuncurrentHashMap_thenNoError() { + public void whenRemoveAndAddOnConcurrentHashMap_thenNoError() { Map map = new ConcurrentHashMap<>(); map.put(1, "baeldung"); map.put(2, "HashMap"); diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java deleted file mode 100644 index 9751decf53..0000000000 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/PerformanceTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.map.cuncurrenthashmap; - -import java.util.Collections; -import java.util.ConcurrentModificationException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Test; - -public class PerformanceTest { - - @Test(expected = ConcurrentModificationException.class) - public void whenRemoveAndAddOnHashMap_thenCuncurrentModificationError() { - Map map = new HashMap<>(); - Map synchronizedMap = Collections.synchronizedMap(map); - long startTime = System.currentTimeMillis(); - for(int i=0; i<100000; i++) { - UserId userId = new UserId(1); - synchronizedMap.put(userId, userId.toString()); - } - long endTime = System.currentTimeMillis(); - long addTimeForSynchronized = endTime-startTime; - - startTime = System.currentTimeMillis(); - for(int i=0; i<100000; i++) { - UserId userId = new UserId(1); - synchronizedMap.get(userId); - } - endTime = System.currentTimeMillis(); - long fetchTimeForSynchronized = endTime-startTime; - - Map map1 = new ConcurrentHashMap<>(); - startTime = System.currentTimeMillis(); - for(int i=0; i<100000; i++) { - UserId userId = new UserId(1); - map1.put(userId, userId.toString()); - } - endTime = System.currentTimeMillis(); - long addTimeForConcurrent = endTime-startTime; - - startTime = System.currentTimeMillis(); - for(int i=0; i<100000; i++) { - UserId userId = new UserId(1); - map1.get(userId); - } - endTime = System.currentTimeMillis(); - long fetchTimeForConcurrent = endTime-startTime; - - System.out.println("ABC"); - - } - -} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java deleted file mode 100644 index a69976180d..0000000000 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/cuncurrenthashmap/UserId.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.map.cuncurrenthashmap; - -public class UserId { - - private int id; - - public UserId(int id) { - super(); - this.id = id; - } - - @Override - public int hashCode() { - return this.id%10; - } - -} From bd6bc03c93a926c357ee22006a75082d606c4731 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 23 Nov 2020 17:32:18 +0530 Subject: [PATCH 228/590] BAEL-4686: Corrected the test --- ...shMapVsSynchronizedMapPerformanceTest.java | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java index eb0c58a8b0..573087d5a5 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java @@ -15,7 +15,7 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { public final static int THREAD_POOL_SIZE = 5; public final static int TEST_ITERATIONS = 5; - public final static int TEST_NO_ITEMS = 500000; + public final static int TEST_NO_ITEMS = 10000; @Test public void randomReadAndWritePerformaceTest_ConcurrentHashMap_faster() @@ -40,6 +40,28 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); } + private long performReadAndWriteTest(final Map map) + throws InterruptedException { + long startTime = System.nanoTime(); + ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + for (int j = 0; j < THREAD_POOL_SIZE; j++) { + exectures.execute(new Runnable() { + @Override + public void run() { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.get(String.valueOf(randNumber)); + map.put(String.valueOf(randNumber), randNumber); + } + } + }); + } + exectures.shutdown(); + exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); + long entTime = System.nanoTime(); + return (entTime - startTime) / 1000000L; + } + @Test public void randomWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { // For synchronizedMap @@ -62,6 +84,26 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); } + private long performWriteTest(final Map map) throws InterruptedException { + long startTime = System.nanoTime(); + ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + for (int j = 0; j < THREAD_POOL_SIZE; j++) { + exectures.execute(new Runnable() { + @Override + public void run() { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.put(String.valueOf(randNumber), randNumber); + } + } + }); + } + exectures.shutdown(); + exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); + long entTime = System.nanoTime(); + return (entTime - startTime) / 1000000L; + } + @Test public void randomReadPerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { @@ -94,48 +136,6 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { return map; } - private long performWriteTest(final Map map) throws InterruptedException { - long startTime = System.nanoTime(); - ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); - for (int j = 0; j < THREAD_POOL_SIZE; j++) { - exectures.execute(new Runnable() { - @Override - public void run() { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.put(String.valueOf(randNumber), randNumber); - } - } - }); - } - exectures.shutdown(); - exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - long entTime = System.nanoTime(); - return (entTime - startTime) / 1000000L; - } - - private long performReadAndWriteTest(final Map map) - throws InterruptedException { - long startTime = System.nanoTime(); - ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); - for (int j = 0; j < THREAD_POOL_SIZE; j++) { - exectures.execute(new Runnable() { - @Override - public void run() { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.get(String.valueOf(randNumber)); - map.put(String.valueOf(randNumber), randNumber); - } - } - }); - } - exectures.shutdown(); - exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - long entTime = System.nanoTime(); - return (entTime - startTime) / 1000000L; - } - private long performReadTest(final Map map) throws InterruptedException { long startTime = System.nanoTime(); ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); From c4a3db7acc638010b37459703d7a21b1ac4c3f6d Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 23 Nov 2020 16:11:44 +0200 Subject: [PATCH 229/590] remove kotlin code from repo --- .../core-kotlin-advanced/README.md | 11 - .../core-kotlin-advanced/pom.xml | 41 --- .../baeldung/contract/CallsInPlaceEffect.kt | 23 -- .../com/baeldung/contract/ReturnsEffect.kt | 43 --- .../kotlin/com/baeldung/datamapping/User.kt | 10 - .../baeldung/datamapping/UserExtensions.kt | 22 -- .../com/baeldung/datamapping/UserView.kt | 8 - .../main/kotlin/com/baeldung/dsl/SqlDsl.kt | 114 ------ .../logging/LoggerAsExtensionOnAny.kt | 30 -- .../LoggerAsExtensionOnMarkerInterface.kt | 30 -- .../com/baeldung/logging/LoggerAsProperty.kt | 17 - .../logging/LoggerAsPropertyDelegate.kt | 47 --- .../logging/LoggerInCompanionObject.kt | 44 --- .../main/kotlin/com/baeldung/logging/Util.kt | 13 - .../com/baeldung/datamapping/UserTest.kt | 43 --- .../kotlin/com/baeldung/dsl/SqlDslTest.kt | 73 ---- .../baeldung/reflection/JavaReflectionTest.kt | 32 -- .../com/baeldung/reflection/KClassTest.kt | 69 ---- .../com/baeldung/reflection/KMethodTest.kt | 88 ----- .../kotlin/com/baeldung/regex/RegexTest.kt | 123 ------- .../core-kotlin-annotations/README.md | 8 - .../core-kotlin-annotations/pom.xml | 41 --- .../com/baeldung/annotations/Annotations.kt | 7 - .../kotlin/com/baeldung/annotations/Item.kt | 3 - .../kotlin/com/baeldung/annotations/Main.kt | 7 - .../com/baeldung/annotations/Validator.kt | 38 -- .../com/baeldung/jvmannotations/Document.kt | 11 - .../baeldung/jvmannotations/HtmlDocument.java | 9 - .../com/baeldung/jvmannotations/Message.kt | 66 ---- .../jvmannotations/MessageConverter.kt | 6 - .../baeldung/jvmannotations/TextDocument.kt | 16 - .../baeldung/jvmannotations/XmlDocument.kt | 5 - .../kotlin/com/baeldung/jvmfield/JvmSample.kt | 12 - .../baeldung/annotations/ValidationTest.kt | 41 --- .../baeldung/jvmannotations/DocumentTest.kt | 20 -- .../com/baeldung/jvmfield/JvmSampleTest.kt | 26 -- .../core-kotlin-collections-2/README.md | 7 - .../core-kotlin-collections-2/pom.xml | 47 --- .../baeldung/aggregate/AggregateOperations.kt | 107 ------ .../aggregate/AggregateOperationsUnitTest.kt | 104 ------ .../core-kotlin-collections/README.md | 16 - .../core-kotlin-collections/pom.xml | 47 --- .../com/baeldung/index/IndexedIteration.kt | 33 -- .../kotlin/collections/ListExample.kt | 204 ----------- .../com/baeldung/sorting/SortingExample.kt | 42 --- .../baeldung/collections/CollectionsTest.kt | 212 ----------- .../transformations/AssociateUnitTest.kt | 48 --- .../transformations/FilterUnitTest.kt | 43 --- .../transformations/FlattenUnitTest.kt | 21 -- .../transformations/JoinToUnitTest.kt | 46 --- .../transformations/MapUnitTest.kt | 53 --- .../transformations/ReduceUnitTest.kt | 22 -- .../transformations/ZipUnitTest.kt | 34 -- .../kotlin/com/baeldung/filter/ChunkedTest.kt | 39 -- .../com/baeldung/filter/DistinctTest.kt | 71 ---- .../kotlin/com/baeldung/filter/DropTest.kt | 53 --- .../kotlin/com/baeldung/filter/FilterTest.kt | 39 -- .../kotlin/com/baeldung/filter/SliceTest.kt | 45 --- .../kotlin/com/baeldung/filter/TakeTest.kt | 38 -- .../FindAnElementInAListUnitTest.kt | 34 -- .../foldvsreduce/FoldAndReduceTest.kt | 59 ---- .../kotlin/collections/ListExampleUnitTest.kt | 126 ------- .../com/baeldung/listtomap/ListToMapTest.kt | 74 ---- .../kotlin/com/baeldung/listtomap/User.kt | 3 - .../baeldung/sorting/SortingExampleKtTest.kt | 13 - .../splitlist/SplitListIntoPartsTest.kt | 99 ------ .../core-kotlin-concurrency/README.md | 8 - .../core-kotlin-concurrency/pom.xml | 41 --- .../com/baeldung/channels/BufferedChannel.kt | 29 -- .../com/baeldung/channels/ConflatedChannel.kt | 27 -- .../com/baeldung/channels/PizzaPipeline.kt | 52 --- .../com/baeldung/channels/ProducerConsumer.kt | 22 -- .../baeldung/channels/RendezvousChannel.kt | 26 -- .../channels/SeveralProducersOneConsumer.kt | 36 -- .../SingleProducerSeveralConsumers.kt | 31 -- .../com/baeldung/channels/TickerChannel.kt | 24 -- .../com/baeldung/channels/UnlimitedChannel.kt | 28 -- .../kotlin/com/baeldung/channels/logger.kt | 8 - .../threadsvscoroutines/SimpleRunnable.kt | 8 - .../threadsvscoroutines/SimpleThread.kt | 8 - .../com/baeldung/channels/ChannelsTest.kt | 29 -- .../baeldung/coroutines/CoroutinesUnitTest.kt | 178 ---------- .../threadsvscoroutines/CoroutineUnitTest.kt | 52 --- .../threadsvscoroutines/ThreadUnitTest.kt | 38 -- .../core-kotlin-datastructures/README.md | 6 - .../core-kotlin-datastructures/pom.xml | 29 -- .../kotlin/com/baeldung/binarytree/Main.kt | 19 - .../kotlin/com/baeldung/binarytree/Node.kt | 167 --------- .../test/kotlin/com/binarytree/NodeTest.kt | 320 ----------------- .../core-kotlin-date-time/README.md | 6 - .../core-kotlin-date-time/pom.xml | 36 -- .../baeldung/dates/datetime/UseDuration.kt | 15 - .../baeldung/dates/datetime/UseLocalDate.kt | 42 --- .../dates/datetime/UseLocalDateTime.kt | 10 - .../baeldung/dates/datetime/UseLocalTime.kt | 31 -- .../com/baeldung/dates/datetime/UsePeriod.kt | 15 - .../dates/datetime/UseZonedDateTime.kt | 12 - .../com/baeldung/dates/CreateDateUnitTest.kt | 34 -- .../com/baeldung/dates/ExtractDateUnitTest.kt | 29 -- .../com/baeldung/dates/FormatDateUnitTest.kt | 29 -- .../com/baeldung/dates/PeriodDateUnitTest.kt | 48 --- .../datetime/UseLocalDateTimeUnitTest.kt | 21 -- .../dates/datetime/UseLocalDateUnitTest.kt | 59 ---- .../dates/datetime/UseLocalTimeUnitTest.kt | 36 -- .../dates/datetime/UsePeriodUnitTest.kt | 27 -- .../datetime/UseZonedDateTimeUnitTest.kt | 19 - .../core-kotlin-design-patterns/README.md | 6 - .../core-kotlin-design-patterns/pom.xml | 29 -- .../kotlin/com/baeldung/builder/FoodOrder.kt | 22 -- .../com/baeldung/builder/FoodOrderApply.kt | 8 - .../com/baeldung/builder/FoodOrderNamed.kt | 7 - .../main/kotlin/com/baeldung/builder/Main.kt | 9 - .../builder/BuilderPatternUnitTest.kt | 140 -------- core-kotlin-modules/core-kotlin-io/README.md | 9 - core-kotlin-modules/core-kotlin-io/pom.xml | 54 --- .../com/baeldung/filesystem/FileReader.kt | 24 -- .../com/baeldung/filesystem/FileWriter.kt | 19 - .../inputstream/InputStreamExtension.kt | 18 - .../com/baeldung/console/ConsoleIOUnitTest.kt | 79 ----- .../com/baeldung/filesystem/FileReaderTest.kt | 67 ---- .../com/baeldung/filesystem/FileWriterTest.kt | 43 --- .../inputstream/InputStreamToStringTest.kt | 74 ---- .../src/test/resources/Kotlin.in | 5 - .../src/test/resources/Kotlin.out | 2 - .../src/test/resources/inputstream2string.txt | 2 - .../org.mockito.plugins.MockMaker | 1 - .../core-kotlin-lang-2/README.md | 16 - .../core-kotlin-lang-2/pom.xml | 16 - .../lazy/ClassWithHeavyInitialization.java | 14 - .../IfElseExpressionExample.kt | 86 ----- .../main/kotlin/com/baeldung/lambda/Lambda.kt | 84 ----- .../com/baeldung/scope/ScopeFunctions.kt | 25 -- .../com/baeldung/lazy/LazyJavaUnitTest.java | 18 - .../com/baeldung/constant/ConstantUnitTest.kt | 17 - .../constant/TestKotlinConstantClass.kt | 8 - .../constant/TestKotlinConstantObject.kt | 15 - .../IfElseExpressionExampleTest.kt | 43 --- .../infixfunctions/InfixFunctionsTest.kt | 51 --- .../baeldung/lambda/LambdaKotlinUnitTest.java | 36 -- .../kotlin/com/baeldung/lambda/LambdaTest.kt | 96 ----- .../com/baeldung/late/LateInitUnitTest.kt | 22 -- .../kotlin/com/baeldung/lazy/LazyUnitTest.kt | 68 ---- .../com/baeldung/nullsafety/NullSafetyTest.kt | 161 --------- .../baeldung/scope/ScopeFunctionsUnitTest.kt | 143 -------- .../structuraljump/StructuralJumpUnitTest.kt | 121 ------- .../core-kotlin-lang-oop-2/README.md | 11 - .../core-kotlin-lang-oop-2/pom.xml | 78 ---- .../com/baeldung/anonymous/Anonymous.kt | 41 --- .../kotlin/com/baeldung/generic/Reified.kt | 6 - .../com/baeldung/kotlin/delegates/Database.kt | 35 -- .../kotlin/delegates/DatabaseDelegate.kt | 13 - .../kotlin/delegates/InterfaceDelegation.kt | 64 ---- .../com/baeldung/kotlin/delegates/User.kt | 6 - .../test/kotlin/com/baeldung/GenericsTest.kt | 143 -------- .../kotlin/delegates/DatabaseDelegatesTest.kt | 26 -- .../kotlin/delegates/DelegateProviderTest.kt | 42 --- .../delegates/InterfaceDelegationTest.kt | 28 -- .../core-kotlin-lang-oop/README.md | 17 - .../core-kotlin-lang-oop/pom.xml | 25 -- .../main/java/com/baeldung/constructor/Car.kt | 17 - .../java/com/baeldung/constructor/Employee.kt | 3 - .../java/com/baeldung/constructor/Person.java | 19 - .../java/com/baeldung/dataclass/Movie.java | 88 ----- .../kotlin/com/baeldung/constructor/Person.kt | 26 -- .../kotlin/com/baeldung/dataclass/Movie.kt | 3 - .../kotlin/com/baeldung/dataclass/Sandbox.kt | 26 -- .../kotlin/com/baeldung/enums/CardType.kt | 23 -- .../kotlin/com/baeldung/enums/ICardLimit.kt | 5 - .../baeldung/inline/classes/CircleRadius.kt | 14 - .../inline/classes/InlineDoubleWrapper.kt | 3 - .../interfaces/ConflictingInterfaces.kt | 23 -- .../interfaces/InterfaceDelegation.kt | 13 - .../baeldung/interfaces/MultipleInterfaces.kt | 29 -- .../baeldung/interfaces/SimpleInterface.kt | 24 -- .../main/kotlin/com/baeldung/kotlin/Sealed.kt | 19 - .../kotlin/com/baeldung/kotlin/StringUtil.kt | 9 - .../kotlin/com/baeldung/nested/Computer.kt | 75 ---- .../com/baeldung/static/ConsoleUtils.kt | 10 - .../com/baeldung/static/LoggingUtils.kt | 5 - .../baeldung/kotlin/StringUtilUnitTest.java | 30 -- .../com/baeldung/enums/CardTypeUnitTest.kt | 84 ----- .../inline/classes/CircleRadiusTest.kt | 19 - .../inline/classes/InlineDoubleWrapperTest.kt | 13 - .../interfaces/InterfaceExamplesUnitTest.kt | 32 -- .../com/baeldung/kotlin/ExtensionMethods.kt | 44 --- .../kotlin/com/baeldung/kotlin/SealedTest.kt | 84 ----- .../com/baeldung/kotlin/objects/Counter.kt | 15 - .../baeldung/kotlin/objects/ObjectsTest.kt | 36 -- .../com/baeldung/kotlin/objects/OuterClass.kt | 10 - .../kotlin/objects/ReverseStringComparator.kt | 5 - .../kotlin/objects/SimpleSingleton.kt | 7 - .../baeldung/kotlin/objects/StaticClass.kt | 8 - .../com/baeldung/nested/ComputerUnitTest.kt | 28 -- .../baeldung/static/ConsoleUtilsUnitTest.kt | 10 - .../baeldung/static/LoggingUtilsUnitTest.kt | 10 - .../core-kotlin-lang/README.md | 16 - core-kotlin-modules/core-kotlin-lang/pom.xml | 16 - .../destructuringdeclarations/Person.kt | 3 - .../destructuringdeclarations/Result.kt | 3 - .../destructuringdeclarations/Sandbox.kt | 42 --- .../com/baeldung/equalityoperators/User.kt | 3 - .../kotlin/com/baeldung/forEach/forEach.kt | 87 ----- .../main/kotlin/com/baeldung/inline/Inline.kt | 28 -- .../kotlin/com/baeldung/operators/Money.kt | 31 -- .../kotlin/com/baeldung/operators/Page.kt | 17 - .../kotlin/com/baeldung/operators/Point.kt | 31 -- .../kotlin/com/baeldung/operators/Utils.kt | 8 - .../kotlin/com/baeldung/range/CharRange.kt | 13 - .../main/kotlin/com/baeldung/range/Color.kt | 21 -- .../main/kotlin/com/baeldung/range/Filter.kt | 18 - .../kotlin/com/baeldung/range/FirstLast.kt | 8 - .../com/baeldung/range/OtherRangeFunctions.kt | 14 - .../main/kotlin/com/baeldung/range/Range.kt | 28 -- .../kotlin/com/baeldung/range/ReverseRange.kt | 14 - .../main/kotlin/com/baeldung/range/Step.kt | 15 - .../kotlin/com/baeldung/range/UntilRange.kt | 8 - .../com/baeldung/rangeiterator/CustomColor.kt | 56 --- .../com/baeldung/whenblock/WhenBlockTypes.kt | 28 -- .../equalityoperators/EqualityTest.kt | 58 --- .../kotlin/com/baeldung/operators/PageTest.kt | 33 -- .../com/baeldung/operators/PointTest.kt | 48 --- .../com/baeldung/operators/UtilsTest.kt | 13 - .../com/baeldung/range/CharRangeTest.kt | 17 - .../kotlin/com/baeldung/range/ColorTest.kt | 20 -- .../kotlin/com/baeldung/range/FilterTest.kt | 24 -- .../com/baeldung/range/FirstLastTest.kt | 22 -- .../baeldung/range/OtherRangeFunctionsTest.kt | 40 --- .../kotlin/com/baeldung/range/RangeTest.kt | 22 -- .../com/baeldung/range/ReverseRangeTest.kt | 12 - .../kotlin/com/baeldung/range/StepTest.kt | 17 - .../com/baeldung/range/UntilRangeTest.kt | 12 - .../baeldung/rangeiterator/CustomColorTest.kt | 41 --- .../com/baeldung/trywithresource/UseTest.kt | 67 ---- .../baeldung/voidtypes/VoidTypesUnitTest.kt | 63 ---- .../baeldung/whenblock/WhenBlockUnitTest.kt | 136 ------- .../core-kotlin-strings/README.md | 9 - .../core-kotlin-strings/pom.xml | 24 -- .../com/baeldung/stringtemplates/Templates.kt | 115 ------ .../randomstring/RandomStringUnitTest.kt | 64 ---- .../stringcomparison/StringComparisonTest.kt | 47 --- .../StringConcatenationTest.kt | 48 --- .../core-kotlin-testing/README.md | 6 - .../core-kotlin-testing/pom.xml | 29 -- .../kotlin/com/baeldung/junit5/Calculator.kt | 17 - .../com/baeldung/junit5/CalculatorUnitTest.kt | 82 ----- .../baeldung/junit5/DivideByZeroException.kt | 3 - .../com/baeldung/junit5/SimpleUnitTest.kt | 22 -- core-kotlin-modules/core-kotlin/README.md | 15 - core-kotlin-modules/core-kotlin/pom.xml | 29 -- .../interoperability/ArrayExample.java | 24 -- .../baeldung/interoperability/Customer.java | 24 -- .../baeldung/introduction/StringUtils.java | 7 - .../baeldung/mavenjavakotlin/Application.java | 25 -- .../mavenjavakotlin/services/JavaService.java | 9 - .../baeldung/arguments/DefaultArguments.kt | 37 -- .../com/baeldung/arguments/NamedArguments.kt | 28 -- .../exceptionhandling/ExceptionHandling.kt | 88 ----- .../com/baeldung/introduction/Example1.kt | 5 - .../kotlin/com/baeldung/introduction/Item.kt | 14 - .../com/baeldung/introduction/ItemService.kt | 83 ----- .../baeldung/introduction/ListExtension.kt | 14 - .../introduction/MathematicsOperations.kt | 7 - .../baeldung/mavenjavakotlin/KotlinService.kt | 9 - .../JavaCallToKotlinUnitTest.java | 17 - .../ExceptionHandlingUnitTest.kt | 51 --- .../baeldung/interoperability/ArrayTest.kt | 37 -- .../baeldung/interoperability/CustomerTest.kt | 22 -- .../baeldung/introduction/ItemServiceTest.kt | 21 -- .../KotlinJavaInteroperabilityTest.kt | 20 -- .../com/baeldung/introduction/LambdaTest.kt | 20 -- .../introduction/ListExtensionTest.kt | 19 - .../nullassertion/NotNullAssertionUnitTest.kt | 20 -- .../com/baeldung/random/RandomNumberTest.kt | 55 --- .../com/baeldung/sequences/SequencesTest.kt | 54 --- .../baeldung/ternary/TernaryOperatorTest.kt | 32 -- core-kotlin-modules/pom.xml | 70 ---- jee-kotlin/README.md | 6 - jee-kotlin/pom.xml | 288 --------------- .../com/baeldung/jeekotlin/entity/Student.kt | 22 -- .../jeekotlin/rest/ApplicationConfig.kt | 9 - .../jeekotlin/rest/StudentResource.kt | 42 --- .../jeekotlin/service/StudentService.kt | 21 -- .../main/resources/META-INF/persistence.xml | 18 - jee-kotlin/src/main/webapp/WEB-INF/beans.xml | 8 - .../StudentResourceIntegrationTest.java | 108 ------ jee-kotlin/src/test/resources/arquillian.xml | 22 -- kotlin-js/.gitignore | 13 - kotlin-js/README.md | 7 - kotlin-js/build.gradle | 27 -- kotlin-js/gradle/wrapper/gradle-wrapper.jar | Bin 58694 -> 0 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 - kotlin-js/gradlew | 183 ---------- kotlin-js/gradlew.bat | 103 ------ kotlin-js/package.json | 15 - kotlin-js/settings.gradle | 1 - .../com/baeldung/kotlinjs/CryptoRate.kt | 27 -- kotlin-js/src/main/resources/logback.xml | 13 - kotlin-libraries-2/.gitignore | 14 - kotlin-libraries-2/README.md | 14 - kotlin-libraries-2/pom.xml | 92 ----- kotlin-libraries-2/resources/logback.xml | 11 - .../kotlin/com/baeldung/fuel/Interceptors.kt | 11 - .../src/main/kotlin/com/baeldung/fuel/Post.kt | 15 - .../com/baeldung/fuel/PostRoutingAPI.kt | 42 --- .../injekt/DelegateInjectionApplication.kt | 60 ---- .../com/baeldung/injekt/KeyedApplication.kt | 41 --- .../com/baeldung/injekt/ModularApplication.kt | 47 --- .../baeldung/injekt/PerThreadApplication.kt | 52 --- .../com/baeldung/injekt/SimpleApplication.kt | 38 -- .../com/baeldung/kotlin/jackson/Book.kt | 8 - .../com/baeldung/kotlin/jackson/Movie.kt | 3 - .../com/baeldung/fuel/FuelHttpLiveTest.kt | 280 --------------- .../kotlin/com/baeldung/gson/GsonUnitTest.kt | 30 -- .../immutable/KotlinxImmutablesUnitTest.kt | 27 -- .../kotlin/immutable/ReadOnlyUnitTest.kt | 73 ---- .../kotlin/jackson/JacksonUnitTest.kt | 122 ------- .../baeldung/kotlin/rxkotlin/RxKotlinTest.kt | 157 --------- .../com/baeldung/kovenant/KovenantTest.kt | 192 ---------- .../baeldung/kovenant/KovenantTimeoutTest.kt | 38 -- .../baeldung/mockk/AnnotationMockKUnitTest.kt | 44 --- .../com/baeldung/mockk/BasicMockKUnitTest.kt | 92 ----- .../mockk/HierarchicalMockKUnitTest.kt | 33 -- .../com/baeldung/mockk/TestableService.kt | 12 - kotlin-libraries/.gitignore | 14 - kotlin-libraries/README.md | 16 - kotlin-libraries/build.gradle | 62 ---- .../gradle/wrapper/gradle-wrapper.jar | Bin 54329 -> 0 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 - kotlin-libraries/gradlew | 172 --------- kotlin-libraries/gradlew.bat | 84 ----- kotlin-libraries/pom.xml | 171 --------- kotlin-libraries/resources/logback.xml | 11 - kotlin-libraries/settings.gradle | 2 - .../com/baeldung/klaxon/CustomProduct.kt | 9 - .../kotlin/com/baeldung/klaxon/Product.kt | 3 - .../kotlin/com/baeldung/klaxon/ProductData.kt | 3 - .../FunctionalErrorHandlingWithEither.kt | 54 --- .../FunctionalErrorHandlingWithOption.kt | 46 --- .../com/baeldung/kotlin/kodein/Controller.kt | 3 - .../kotlin/com/baeldung/kotlin/kodein/Dao.kt | 3 - .../com/baeldung/kotlin/kodein/JdbcDao.kt | 3 - .../com/baeldung/kotlin/kodein/MongoDao.kt | 3 - .../com/baeldung/kotlin/kodein/Service.kt | 3 - .../baeldung/kotlin/mockito/BookService.kt | 6 - .../kotlin/mockito/LendBookManager.kt | 11 - .../com/baeldung/kovert/AnnotatedServer.kt | 73 ---- .../kotlin/com/baeldung/kovert/ErrorServer.kt | 75 ---- .../kotlin/com/baeldung/kovert/JsonServer.kt | 76 ---- .../kotlin/com/baeldung/kovert/NoopServer.kt | 57 --- .../com/baeldung/kovert/SecuredServer.kt | 68 ---- .../com/baeldung/kovert/SimpleServer.kt | 65 ---- .../kotlin/com/baeldung/ktor/APIServer.kt | 73 ---- .../src/main/resources/kovert.conf | 15 - .../com/baeldung/klaxon/KlaxonUnitTest.kt | 163 --------- .../kotlin/arrow/FunctionalDataTypes.kt | 143 -------- .../FunctionalErrorHandlingWithEitherTest.kt | 68 ---- .../FunctionalErrorHandlingWithOptionTest.kt | 34 -- .../baeldung/kotlin/exposed/ExposedTest.kt | 333 ------------------ .../com/baeldung/kotlin/junit5/Calculator.kt | 17 - .../kotlin/junit5/DivideByZeroException.kt | 3 - .../baeldung/kotlin/khttp/KhttpLiveTest.kt | 153 -------- .../baeldung/kotlin/kodein/KodeinUnitTest.kt | 191 ---------- .../kotlin/mockito/LendBookManagerTest.kt | 30 -- .../LendBookManagerTestMockitoKotlin.kt | 32 -- .../baeldung/kotlin/rxkotlin/RxKotlinTest.kt | 157 --------- .../kotlin/spek/CalculatorSubjectTest5.kt | 19 - .../baeldung/kotlin/spek/CalculatorTest5.kt | 32 -- .../baeldung/kotlin/spek/DataDrivenTest5.kt | 21 -- .../com/baeldung/kotlin/spek/GroupTest5.kt | 62 ---- kotlin-quasar/README.md | 4 - kotlin-quasar/pom.xml | 153 -------- .../com/baeldung/quasar/QuasarHelloWorld.kt | 19 - .../com/baeldung/quasar/ActorsBehaviorTest.kt | 157 --------- .../kotlin/com/baeldung/quasar/ActorsTest.kt | 298 ---------------- .../com/baeldung/quasar/ChannelsTest.kt | 155 -------- .../com/baeldung/quasar/DataflowTest.kt | 35 -- .../kotlin/com/baeldung/quasar/PiAsyncTest.kt | 53 --- .../baeldung/quasar/ReactiveStreamsTest.kt | 135 ------- .../quasar/SuspendableCallableTest.kt | 48 --- .../quasar/SuspensableRunnableTest.kt | 47 --- parent-kotlin/README.md | 3 - parent-kotlin/pom.xml | 223 ------------ pom.xml | 26 +- .../spring-boot-kotlin/README.md | 6 - .../spring-boot-kotlin/pom.xml | 119 ------- .../SpringApplication.kt | 11 - .../config/DatastoreConfig.kt | 32 -- .../config/RouterConfiguration.kt | 19 - .../config/WebClientConfiguration.kt | 12 - .../controller/ProductController.kt | 49 --- .../controller/ProductControllerCoroutines.kt | 49 --- .../controller/ProductStockView.kt | 15 - .../handlers/ProductsHandler.kt | 48 --- .../nonblockingcoroutines/model/Product.kt | 7 - .../repository/ProductRepository.kt | 33 -- .../repository/ProductRepositoryCoroutines.kt | 39 -- .../src/main/resources/application.properties | 8 - .../src/main/resources/logback.xml | 13 - .../ProductHandlerTest.kt | 58 --- spring-mvc-kotlin/.gitignore | 1 - spring-mvc-kotlin/README.md | 9 - spring-mvc-kotlin/pom.xml | 82 ----- .../kotlin/allopen/SimpleConfiguration.kt | 7 - .../kotlin/com/baeldung/kotlin/jpa/Person.kt | 21 -- .../com/baeldung/kotlin/jpa/PhoneNumber.kt | 15 - .../kotlin/mockmvc/MockMvcController.kt | 26 -- .../baeldung/kotlin/mockmvc/MockMvcModel.kt | 10 - .../kotlin/mvc/ApplicationWebConfig.kt | 52 --- .../kotlin/mvc/ApplicationWebInitializer.kt | 18 - .../src/main/resources/logback.xml | 13 - .../main/webapp/WEB-INF/spring-web-config.xml | 37 -- .../src/main/webapp/WEB-INF/view/welcome.jsp | 7 - .../src/main/webapp/WEB-INF/web.xml | 24 -- .../kotlin/allopen/SimpleConfigurationTest.kt | 19 - .../jpa/HibernateKotlinIntegrationTest.kt | 66 ---- .../kotlin/mockmvc/MockMvcControllerTest.kt | 61 ---- .../src/test/resources/hibernate.properties | 9 - spring-reactive-kotlin/README.md | 7 - spring-reactive-kotlin/pom.xml | 145 -------- .../HealthTrackerApplication.kt | 11 - .../config/DBConfiguration.kt | 28 -- .../controller/HealthRecordController.kt | 44 --- .../controller/ProfileController.kt | 15 - .../model/AverageHealthStatus.kt | 3 - .../bootmicroservice/model/HealthRecord.kt | 8 - .../bootmicroservice/model/Profile.kt | 8 - .../repository/HealthRecordRepository.kt | 13 - .../repository/ProfileRepository.kt | 8 - .../springreactivekotlin/Application.kt | 11 - .../springreactivekotlin/Controller.kt | 18 - .../baeldung/springreactivekotlin/Device.kt | 5 - .../HomeSensorsHandler.kt | 36 -- .../HomeSensorsRouters.kt | 32 -- .../baeldung/springreactivekotlin/Routes.kt | 16 - .../src/main/resources/application.yml | 1 - .../src/main/resources/logback.xml | 13 - .../src/test/kotlin/RoutesTest.kt | 35 -- .../controller/ProfileControllerTest.kt | 51 --- 438 files changed, 1 insertion(+), 18156 deletions(-) delete mode 100644 core-kotlin-modules/core-kotlin-advanced/README.md delete mode 100644 core-kotlin-modules/core-kotlin-advanced/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/README.md delete mode 100644 core-kotlin-modules/core-kotlin-annotations/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections-2/README.md delete mode 100644 core-kotlin-modules/core-kotlin-collections-2/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-collections-2/src/main/kotlin/com/baeldung/aggregate/AggregateOperations.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections-2/src/test/kotlin/com/baeldung/aggregate/AggregateOperationsUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/README.md delete mode 100644 core-kotlin-modules/core-kotlin-collections/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/README.md delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-datastructures/README.md delete mode 100644 core-kotlin-modules/core-kotlin-datastructures/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt delete mode 100644 core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt delete mode 100644 core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/README.md delete mode 100644 core-kotlin-modules/core-kotlin-date-time/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/README.md delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt delete mode 100644 core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/README.md delete mode 100644 core-kotlin-modules/core-kotlin-io/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt delete mode 100644 core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/README.md delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/README.md delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/README.md delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/README.md delete mode 100644 core-kotlin-modules/core-kotlin-lang/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Point.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Utils.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/CharRange.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Color.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Filter.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/FirstLast.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/OtherRangeFunctions.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Range.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/ReverseRange.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Step.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/UntilRange.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/rangeiterator/CustomColor.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/whenblock/WhenBlockTypes.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/equalityoperators/EqualityTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PointTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/UtilsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/CharRangeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ColorTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FilterTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FirstLastTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/OtherRangeFunctionsTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/RangeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ReverseRangeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/StepTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/UntilRangeTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/rangeiterator/CustomColorTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/trywithresource/UseTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/voidtypes/VoidTypesUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/whenblock/WhenBlockUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-strings/README.md delete mode 100644 core-kotlin-modules/core-kotlin-strings/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-strings/src/main/kotlin/com/baeldung/stringtemplates/Templates.kt delete mode 100644 core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringconcatenation/StringConcatenationTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-testing/README.md delete mode 100644 core-kotlin-modules/core-kotlin-testing/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt delete mode 100644 core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt delete mode 100644 core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/README.md delete mode 100644 core-kotlin-modules/core-kotlin/pom.xml delete mode 100644 core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/ArrayExample.java delete mode 100644 core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/Customer.java delete mode 100644 core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/introduction/StringUtils.java delete mode 100644 core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/Application.java delete mode 100644 core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/services/JavaService.java delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/DefaultArguments.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/NamedArguments.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Example1.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Item.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ItemService.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ListExtension.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/MathematicsOperations.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/mavenjavakotlin/KotlinService.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/java/com/baeldung/introduction/JavaCallToKotlinUnitTest.java delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/ArrayTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/CustomerTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ItemServiceTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/KotlinJavaInteroperabilityTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/LambdaTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ListExtensionTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/random/RandomNumberTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt delete mode 100644 core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt delete mode 100644 core-kotlin-modules/pom.xml delete mode 100644 jee-kotlin/README.md delete mode 100644 jee-kotlin/pom.xml delete mode 100644 jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/entity/Student.kt delete mode 100644 jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/ApplicationConfig.kt delete mode 100644 jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/StudentResource.kt delete mode 100644 jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/service/StudentService.kt delete mode 100644 jee-kotlin/src/main/resources/META-INF/persistence.xml delete mode 100644 jee-kotlin/src/main/webapp/WEB-INF/beans.xml delete mode 100644 jee-kotlin/src/test/kotlin/com/baeldung/jeekotlin/StudentResourceIntegrationTest.java delete mode 100644 jee-kotlin/src/test/resources/arquillian.xml delete mode 100644 kotlin-js/.gitignore delete mode 100644 kotlin-js/README.md delete mode 100644 kotlin-js/build.gradle delete mode 100644 kotlin-js/gradle/wrapper/gradle-wrapper.jar delete mode 100644 kotlin-js/gradle/wrapper/gradle-wrapper.properties delete mode 100755 kotlin-js/gradlew delete mode 100644 kotlin-js/gradlew.bat delete mode 100644 kotlin-js/package.json delete mode 100755 kotlin-js/settings.gradle delete mode 100755 kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt delete mode 100644 kotlin-js/src/main/resources/logback.xml delete mode 100644 kotlin-libraries-2/.gitignore delete mode 100644 kotlin-libraries-2/README.md delete mode 100644 kotlin-libraries-2/pom.xml delete mode 100644 kotlin-libraries-2/resources/logback.xml delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Interceptors.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Post.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/PostRoutingAPI.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/DelegateInjectionApplication.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/KeyedApplication.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/ModularApplication.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/PerThreadApplication.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/SimpleApplication.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt delete mode 100644 kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/KotlinxImmutablesUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/ReadOnlyUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTimeoutTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/AnnotationMockKUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/BasicMockKUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/HierarchicalMockKUnitTest.kt delete mode 100644 kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/TestableService.kt delete mode 100644 kotlin-libraries/.gitignore delete mode 100644 kotlin-libraries/README.md delete mode 100644 kotlin-libraries/build.gradle delete mode 100644 kotlin-libraries/gradle/wrapper/gradle-wrapper.jar delete mode 100644 kotlin-libraries/gradle/wrapper/gradle-wrapper.properties delete mode 100644 kotlin-libraries/gradlew delete mode 100644 kotlin-libraries/gradlew.bat delete mode 100644 kotlin-libraries/pom.xml delete mode 100644 kotlin-libraries/resources/logback.xml delete mode 100644 kotlin-libraries/settings.gradle delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/AnnotatedServer.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/ErrorServer.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/JsonServer.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/NoopServer.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SecuredServer.kt delete mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SimpleServer.kt delete mode 100755 kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt delete mode 100644 kotlin-libraries/src/main/resources/kovert.conf delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt delete mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt delete mode 100644 kotlin-quasar/README.md delete mode 100644 kotlin-quasar/pom.xml delete mode 100644 kotlin-quasar/src/main/kotlin/com/baeldung/quasar/QuasarHelloWorld.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsBehaviorTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ChannelsTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/DataflowTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/PiAsyncTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ReactiveStreamsTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspendableCallableTest.kt delete mode 100644 kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspensableRunnableTest.kt delete mode 100644 parent-kotlin/README.md delete mode 100644 parent-kotlin/pom.xml delete mode 100644 spring-boot-modules/spring-boot-kotlin/README.md delete mode 100644 spring-boot-modules/spring-boot-kotlin/pom.xml delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/SpringApplication.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/DatastoreConfig.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/RouterConfiguration.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/WebClientConfiguration.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductController.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductStockView.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/model/Product.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/main/resources/logback.xml delete mode 100644 spring-boot-modules/spring-boot-kotlin/src/test/kotlin/com/baeldung/nonblockingcoroutines/ProductHandlerTest.kt delete mode 100644 spring-mvc-kotlin/.gitignore delete mode 100644 spring-mvc-kotlin/README.md delete mode 100644 spring-mvc-kotlin/pom.xml delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/allopen/SimpleConfiguration.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/Person.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/PhoneNumber.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcController.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcModel.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebConfig.kt delete mode 100644 spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebInitializer.kt delete mode 100644 spring-mvc-kotlin/src/main/resources/logback.xml delete mode 100644 spring-mvc-kotlin/src/main/webapp/WEB-INF/spring-web-config.xml delete mode 100644 spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp delete mode 100755 spring-mvc-kotlin/src/main/webapp/WEB-INF/web.xml delete mode 100644 spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/allopen/SimpleConfigurationTest.kt delete mode 100644 spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/jpa/HibernateKotlinIntegrationTest.kt delete mode 100644 spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/mockmvc/MockMvcControllerTest.kt delete mode 100644 spring-mvc-kotlin/src/test/resources/hibernate.properties delete mode 100644 spring-reactive-kotlin/README.md delete mode 100644 spring-reactive-kotlin/pom.xml delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Application.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Controller.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Device.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsHandler.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsRouters.kt delete mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Routes.kt delete mode 100644 spring-reactive-kotlin/src/main/resources/application.yml delete mode 100644 spring-reactive-kotlin/src/main/resources/logback.xml delete mode 100644 spring-reactive-kotlin/src/test/kotlin/RoutesTest.kt delete mode 100644 spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt diff --git a/core-kotlin-modules/core-kotlin-advanced/README.md b/core-kotlin-modules/core-kotlin-advanced/README.md deleted file mode 100644 index 2e99e3b078..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## Core Kotlin Advanced - -This module contains articles about advanced topics in Kotlin. - -### Relevant articles: -- [Building DSLs in Kotlin](https://www.baeldung.com/kotlin-dsl) -- [Regular Expressions in Kotlin](https://www.baeldung.com/kotlin-regular-expressions) -- [Idiomatic Logging in Kotlin](https://www.baeldung.com/kotlin-logging) -- [Mapping of Data Objects in Kotlin](https://www.baeldung.com/kotlin-data-objects) -- [Reflection with Kotlin](https://www.baeldung.com/kotlin-reflection) -- [Kotlin Contracts](https://www.baeldung.com/kotlin-contracts) diff --git a/core-kotlin-modules/core-kotlin-advanced/pom.xml b/core-kotlin-modules/core-kotlin-advanced/pom.xml deleted file mode 100644 index 5ddfef23cc..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - core-kotlin-advanced - core-kotlin-advanced - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 1.3.30 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt deleted file mode 100644 index ca0b13cdc7..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.contract - -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract - -@ExperimentalContracts -inline fun myRun(block: () -> R): R { - contract { - callsInPlace(block, InvocationKind.EXACTLY_ONCE) - } - return block() -} - -@ExperimentalContracts -fun callsInPlace() { - val i: Int - myRun { - i = 1 // Without contract initialization is forbidden due to possible re-assignment - } - println(i) // Without contract variable might be uninitialized -} - diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt deleted file mode 100644 index 56f667af82..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.contract - -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract - -data class Request(val arg: String) - -class Service { - - @ExperimentalContracts - fun process(request: Request?) { - validate(request) - println(request.arg) - } - -} - -@ExperimentalContracts -private fun validate(request: Request?) { - contract { - returns() implies (request != null) - } - if (request == null) { - throw IllegalArgumentException("Undefined request") - } -} - -data class MyEvent(val message: String) - -@ExperimentalContracts -fun processEvent(event: Any?) { - if (isInterested(event)) { - println(event.message) // Compiler makes smart cast here with the help of contract - } -} - -@ExperimentalContracts -fun isInterested(event: Any?): Boolean { - contract { - returns(true) implies (event is MyEvent) - } - return event is MyEvent -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt deleted file mode 100644 index fdbf95f7ba..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.datamapping - -data class User( - val firstName: String, - val lastName: String, - val street: String, - val houseNumber: String, - val phone: String, - val age: Int, - val password: String) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt deleted file mode 100644 index 1f3d7f3b47..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.datamapping - -import kotlin.reflect.full.memberProperties - -fun User.toUserView() = UserView( - name = "$firstName $lastName", - address = "$street $houseNumber", - telephone = phone, - age = age -) - -fun User.toUserViewReflection() = with(::UserView) { - val propertiesByName = User::class.memberProperties.associateBy { it.name } - callBy(parameters.associate { parameter -> - parameter to when (parameter.name) { - UserView::name.name -> "$firstName $lastName" - UserView::address.name -> "$street $houseNumber" - UserView::telephone.name -> phone - else -> propertiesByName[parameter.name]?.get(this@toUserViewReflection) - } - }) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt deleted file mode 100644 index e1b6de6b57..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.datamapping - -data class UserView( - val name: String, - val address: String, - val telephone: String, - val age: Int -) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt deleted file mode 100644 index 207e9dbd53..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.baeldung.dsl - -abstract class Condition { - - fun and(initializer: Condition.() -> Unit) { - addCondition(And().apply(initializer)) - } - - fun or(initializer: Condition.() -> Unit) { - addCondition(Or().apply(initializer)) - } - - infix fun String.eq(value: Any?) { - addCondition(Eq(this, value)) - } - - protected abstract fun addCondition(condition: Condition) -} - -open class CompositeCondition(private val sqlOperator: String) : Condition() { - private val conditions = mutableListOf() - - override fun addCondition(condition: Condition) { - conditions += condition - } - - override fun toString(): String { - return if (conditions.size == 1) { - conditions.first().toString() - } else { - conditions.joinToString(prefix = "(", postfix = ")", separator = " $sqlOperator ") { - "$it" - } - } - } -} - -class And : CompositeCondition("and") - -class Or : CompositeCondition("or") - -class Eq(private val column: String, private val value: Any?) : Condition() { - - init { - if (value != null && value !is Number && value !is String) { - throw IllegalArgumentException("Only , numbers and strings values can be used in the 'where' clause") - } - } - - override fun addCondition(condition: Condition) { - throw IllegalStateException("Can't add a nested condition to the sql 'eq'") - } - - override fun toString(): String { - return when (value) { - null -> "$column is null" - is String -> "$column = '$value'" - else -> "$column = $value" - } - } -} - -class SqlSelectBuilder { - - private val columns = mutableListOf() - private lateinit var table: String - private var condition: Condition? = null - - fun select(vararg columns: String) { - if (columns.isEmpty()) { - throw IllegalArgumentException("At least one column should be defined") - } - if (this.columns.isNotEmpty()) { - throw IllegalStateException("Detected an attempt to re-define columns to fetch. Current columns list: " - + "${this.columns}, new columns list: $columns") - } - this.columns.addAll(columns) - } - - fun from(table: String) { - this.table = table - } - - fun where(initializer: Condition.() -> Unit) { - condition = And().apply(initializer) - } - - fun build(): String { - if (!::table.isInitialized) { - throw IllegalStateException("Failed to build an sql select - target table is undefined") - } - return toString() - } - - override fun toString(): String { - val columnsToFetch = - if (columns.isEmpty()) { - "*" - } else { - columns.joinToString(", ") - } - val conditionString = - if (condition == null) { - "" - } else { - " where $condition" - } - return "select $columnsToFetch from $table$conditionString" - } -} - -fun query(initializer: SqlSelectBuilder.() -> Unit): SqlSelectBuilder { - return SqlSelectBuilder().apply(initializer) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt deleted file mode 100644 index 01edf5e871..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.logging - -import org.slf4j.Logger - -open class LoggerAsExtensionOnAny { - val logger = logger() - - fun log(s: String) { - logger().info(s) - logger.info(s) - } -} - -class ExtensionSubclass : LoggerAsExtensionOnAny() - -fun T.logger(): Logger = getLogger(getClassForLogging(javaClass)) - -fun main(args: Array) { - LoggerAsExtensionOnAny().log("test") - ExtensionSubclass().log("sub") - "foo".logger().info("foo") - 1.logger().info("uh-oh!") - SomeOtherClass().logger() -} - -class SomeOtherClass { - fun logger(): String { - return "foo" - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt deleted file mode 100644 index 8210361345..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.logging - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -interface Logging - -inline fun T.logger(): Logger = - //Wrong logger name! - //LoggerFactory.getLogger(javaClass.name + " w/interface") - LoggerFactory.getLogger(getClassForLogging(T::class.java).name + " w/interface") - -open class LoggerAsExtensionOnMarkerInterface : Logging { - companion object : Logging { - val logger = logger() - } - - fun log(s: String) { - logger().info(s) - logger.info(s) - } -} - -class MarkerExtensionSubclass : LoggerAsExtensionOnMarkerInterface() - -fun main(args: Array) { - LoggerAsExtensionOnMarkerInterface().log("test") - MarkerExtensionSubclass().log("sub") - "foo".logger().info("foo") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt deleted file mode 100644 index 60ac0800e2..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.logging - -open class LoggerAsProperty { - private val logger = getLogger(javaClass) - - fun log(s: String) { - logger.info(s) - } - -} - -class PropertySubclass : LoggerAsProperty() - -fun main(args: Array) { - LoggerAsProperty().log("test") - PropertySubclass().log("sub") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt deleted file mode 100644 index 83cde2b446..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.logging - -import org.slf4j.Logger -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -open class LoggerAsPropertyDelegate { - private val lazyLogger by lazyLogger() - protected val logger by LoggerDelegate() - private val logger2 = logger - - companion object { - private val lazyLoggerComp by lazyLogger() - private val loggerComp by LoggerDelegate() - } - - open fun log(s: String) { - logger.info(s) - logger2.info(s) - lazyLogger.info(s) - loggerComp.info(s) - lazyLoggerComp.info(s) - } - -} - -class DelegateSubclass : LoggerAsPropertyDelegate() { - override fun log(s: String) { - logger.info("-- in sub") - super.log(s) - } -} - -fun lazyLogger(forClass: Class<*>): Lazy = - lazy { getLogger(getClassForLogging(forClass)) } - -fun T.lazyLogger(): Lazy = lazyLogger(javaClass) - -fun main(args: Array) { - LoggerAsPropertyDelegate().log("test") - DelegateSubclass().log("sub") -} - -class LoggerDelegate : ReadOnlyProperty { - override fun getValue(thisRef: R, property: KProperty<*>) = - getLogger(getClassForLogging(thisRef.javaClass)) -} diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt deleted file mode 100644 index 6a44675e45..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.logging - -open class LoggerInCompanionObject { - companion object { - private val loggerWithExplicitClass = getLogger(LoggerInCompanionObject::class.java) - @Suppress("JAVA_CLASS_ON_COMPANION") - private val loggerWithWrongClass = getLogger(javaClass) - @Suppress("JAVA_CLASS_ON_COMPANION") - private val logger = getLogger(javaClass.enclosingClass) - } - - fun log(s: String) { - loggerWithExplicitClass.info(s) - loggerWithWrongClass.info(s) - logger.info(s) - } - - class Inner { - companion object { - private val loggerWithExplicitClass = getLogger(Inner::class.java) - @Suppress("JAVA_CLASS_ON_COMPANION") - @JvmStatic - private val loggerWithWrongClass = getLogger(javaClass) - @Suppress("JAVA_CLASS_ON_COMPANION") - @JvmStatic - private val logger = getLogger(javaClass.enclosingClass) - } - - fun log(s: String) { - loggerWithExplicitClass.info(s) - loggerWithWrongClass.info(s) - logger.info(s) - } - } - -} - -class CompanionSubclass : LoggerInCompanionObject() - -fun main(args: Array) { - LoggerInCompanionObject().log("test") - LoggerInCompanionObject.Inner().log("test") - CompanionSubclass().log("sub") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt deleted file mode 100644 index 44dba53cb7..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.logging - -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import kotlin.reflect.full.companionObject - -fun getLogger(forClass: Class<*>): Logger = LoggerFactory.getLogger(forClass) - -fun getClassForLogging(javaClass: Class): Class<*> { - return javaClass.enclosingClass?.takeIf { - it.kotlin.companionObject?.java == javaClass - } ?: javaClass -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt deleted file mode 100644 index 44d350ea38..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.datamapping - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertAll -import kotlin.test.assertEquals - -class UserTest { - - @Test - fun `maps User to UserResponse using extension function`() { - val p = buildUser() - val view = p.toUserView() - assertUserView(view) - } - - @Test - fun `maps User to UserResponse using reflection`() { - val p = buildUser() - val view = p.toUserViewReflection() - assertUserView(view) - } - - private fun buildUser(): User { - return User( - "Java", - "Duke", - "Javastreet", - "42", - "1234567", - 30, - "s3cr37" - ) - } - - private fun assertUserView(pr: UserView) { - assertAll( - { assertEquals("Java Duke", pr.name) }, - { assertEquals("Javastreet 42", pr.address) }, - { assertEquals("1234567", pr.telephone) }, - { assertEquals(30, pr.age) } - ) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt deleted file mode 100644 index a370e7f15d..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.dsl - -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test - -class SqlDslTest { - - @Test - fun `when no columns are specified then star is used`() { - doTest("select * from table1") { - from ("table1") - } - } - - @Test - fun `when no condition is specified then correct query is built`() { - doTest("select column1, column2 from table1") { - select("column1", "column2") - from ("table1") - } - } - - @Test(expected = Exception::class) - fun `when no table is specified then an exception is thrown`() { - query { - select("column1") - }.build() - } - - @Test - fun `when a list of conditions is specified then it's respected`() { - doTest("select * from table1 where (column3 = 4 and column4 is null)") { - from ("table1") - where { - "column3" eq 4 - "column4" eq null - } - } - } - - @Test - fun `when 'or' conditions are specified then they are respected`() { - doTest("select * from table1 where (column3 = 4 or column4 is null)") { - from ("table1") - where { - or { - "column3" eq 4 - "column4" eq null - } - } - } - } - - @Test - fun `when either 'and' or 'or' conditions are specified then they are respected`() { - doTest("select * from table1 where ((column3 = 4 or column4 is null) and column5 = 42)") { - from ("table1") - where { - and { - or { - "column3" eq 4 - "column4" eq null - } - "column5" eq 42 - } - } - } - } - - private fun doTest(expected: String, sql: SqlSelectBuilder.() -> Unit) { - assertThat(query(sql).build()).isEqualTo(expected) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt deleted file mode 100644 index c77774dd81..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.reflection - -import org.junit.Ignore -import org.junit.Test -import org.slf4j.LoggerFactory - -@Ignore -class JavaReflectionTest { - private val LOG = LoggerFactory.getLogger(KClassTest::class.java) - - @Test - fun listJavaClassMethods() { - Exception::class.java.methods - .forEach { method -> LOG.info("Method: {}", method) } - } - - @Test - fun listKotlinClassMethods() { - JavaReflectionTest::class.java.methods - .forEach { method -> LOG.info("Method: {}", method) } - } - - @Test - fun listKotlinDataClassMethods() { - data class ExampleDataClass(val name: String, var enabled: Boolean) - - ExampleDataClass::class.java.methods - .forEach { method -> LOG.info("Method: {}", method) } - } - - -} diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt deleted file mode 100644 index f5d83cd13d..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.reflection - -import org.junit.Assert -import org.junit.Ignore -import org.junit.Test -import org.slf4j.LoggerFactory -import java.math.BigDecimal -import kotlin.reflect.full.* - -class KClassTest { - private val LOG = LoggerFactory.getLogger(KClassTest::class.java) - - @Test - fun testKClassDetails() { - val stringClass = String::class - Assert.assertEquals("kotlin.String", stringClass.qualifiedName) - Assert.assertFalse(stringClass.isData) - Assert.assertFalse(stringClass.isCompanion) - Assert.assertFalse(stringClass.isAbstract) - Assert.assertTrue(stringClass.isFinal) - Assert.assertFalse(stringClass.isSealed) - - val listClass = List::class - Assert.assertEquals("kotlin.collections.List", listClass.qualifiedName) - Assert.assertFalse(listClass.isData) - Assert.assertFalse(listClass.isCompanion) - Assert.assertTrue(listClass.isAbstract) - Assert.assertFalse(listClass.isFinal) - Assert.assertFalse(listClass.isSealed) - } - - @Test - fun testGetRelated() { - LOG.info("Companion Object: {}", TestSubject::class.companionObject) - LOG.info("Companion Object Instance: {}", TestSubject::class.companionObjectInstance) - LOG.info("Object Instance: {}", TestObject::class.objectInstance) - - Assert.assertSame(TestObject, TestObject::class.objectInstance) - } - - @Test - fun testNewInstance() { - val listClass = ArrayList::class - - val list = listClass.createInstance() - Assert.assertTrue(list is ArrayList) - } - - @Test - @Ignore - fun testMembers() { - val bigDecimalClass = BigDecimal::class - - LOG.info("Constructors: {}", bigDecimalClass.constructors) - LOG.info("Functions: {}", bigDecimalClass.functions) - LOG.info("Properties: {}", bigDecimalClass.memberProperties) - LOG.info("Extension Functions: {}", bigDecimalClass.memberExtensionFunctions) - } -} - -class TestSubject { - companion object { - val name = "TestSubject" - } -} - -object TestObject { - val answer = 42 -} diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt deleted file mode 100644 index b58c199a7c..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.baeldung.reflection - -import org.junit.Assert -import org.junit.Test -import java.io.ByteArrayInputStream -import java.nio.charset.Charset -import kotlin.reflect.KMutableProperty -import kotlin.reflect.full.starProjectedType - -class KMethodTest { - - @Test - fun testCallMethod() { - val str = "Hello" - val lengthMethod = str::length - - Assert.assertEquals(5, lengthMethod()) - } - - @Test - fun testReturnType() { - val str = "Hello" - val method = str::byteInputStream - - Assert.assertEquals(ByteArrayInputStream::class.starProjectedType, method.returnType) - Assert.assertFalse(method.returnType.isMarkedNullable) - } - - @Test - fun testParams() { - val str = "Hello" - val method = str::byteInputStream - - method.isSuspend - Assert.assertEquals(1, method.parameters.size) - Assert.assertTrue(method.parameters[0].isOptional) - Assert.assertFalse(method.parameters[0].isVararg) - Assert.assertEquals(Charset::class.starProjectedType, method.parameters[0].type) - } - - @Test - fun testMethodDetails() { - val codePoints = String::codePoints - Assert.assertEquals("codePoints", codePoints.name) - Assert.assertFalse(codePoints.isSuspend) - Assert.assertFalse(codePoints.isExternal) - Assert.assertFalse(codePoints.isInline) - Assert.assertFalse(codePoints.isOperator) - - val byteInputStream = String::byteInputStream - Assert.assertEquals("byteInputStream", byteInputStream.name) - Assert.assertFalse(byteInputStream.isSuspend) - Assert.assertFalse(byteInputStream.isExternal) - Assert.assertTrue(byteInputStream.isInline) - Assert.assertFalse(byteInputStream.isOperator) - } - - val readOnlyProperty: Int = 42 - lateinit var mutableProperty: String - - @Test - fun testPropertyDetails() { - val roProperty = this::readOnlyProperty - Assert.assertEquals("readOnlyProperty", roProperty.name) - Assert.assertFalse(roProperty.isLateinit) - Assert.assertFalse(roProperty.isConst) - Assert.assertFalse(roProperty is KMutableProperty<*>) - - val mProperty = this::mutableProperty - Assert.assertEquals("mutableProperty", mProperty.name) - Assert.assertTrue(mProperty.isLateinit) - Assert.assertFalse(mProperty.isConst) - Assert.assertTrue(mProperty is KMutableProperty<*>) - } - - @Test - fun testProperty() { - val prop = this::mutableProperty - - Assert.assertEquals(String::class.starProjectedType, prop.getter.returnType) - - prop.set("Hello") - Assert.assertEquals("Hello", prop.get()) - - prop.setter("World") - Assert.assertEquals("World", prop.getter()) - } -} diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt deleted file mode 100644 index 5cb54b4dda..0000000000 --- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt +++ /dev/null @@ -1,123 +0,0 @@ -package com.baeldung.regex - -import org.junit.Test -import kotlin.test.* - -class RegexTest { - - @Test - fun whenRegexIsInstantiated_thenIsEqualToToRegexMethod() { - val pattern = """a([bc]+)d?\\""" - - assertEquals(Regex.fromLiteral(pattern).pattern, pattern) - assertEquals(pattern, Regex(pattern).pattern) - assertEquals(pattern, pattern.toRegex().pattern) - } - - @Test - fun whenRegexMatches_thenResultIsTrue() { - val regex = """a([bc]+)d?""".toRegex() - - assertTrue(regex.containsMatchIn("xabcdy")) - assertTrue(regex.matches("abcd")) - assertFalse(regex matches "xabcdy") - } - - @Test - fun givenCompletelyMatchingRegex_whenMatchResult_thenDestructuring() { - val regex = """a([bc]+)d?""".toRegex() - - assertNull(regex.matchEntire("xabcdy")) - - val matchResult = regex.matchEntire("abbccbbd") - - assertNotNull(matchResult) - assertEquals(matchResult!!.value, matchResult.groupValues[0]) - assertEquals(matchResult.destructured.toList(), matchResult.groupValues.drop(1)) - assertEquals("bbccbb", matchResult.destructured.component1()) - assertNull(matchResult.next()) - } - - @Test - fun givenPartiallyMatchingRegex_whenMatchResult_thenGroups() { - val regex = """a([bc]+)d?""".toRegex() - var matchResult = regex.find("abcb abbd") - - assertNotNull(matchResult) - assertEquals(matchResult!!.value, matchResult.groupValues[0]) - assertEquals("abcb", matchResult.value) - assertEquals(IntRange(0, 3), matchResult.range) - assertEquals(listOf("abcb", "bcb"), matchResult.groupValues) - assertEquals(matchResult.destructured.toList(), matchResult.groupValues.drop(1)) - - matchResult = matchResult.next() - - assertNotNull(matchResult) - assertEquals("abbd", matchResult!!.value) - assertEquals("bb", matchResult.groupValues[1]) - - matchResult = matchResult.next() - - assertNull(matchResult) - } - - @Test - fun givenPartiallyMatchingRegex_whenMatchResult_thenDestructuring() { - val regex = """([\w\s]+) is (\d+) years old""".toRegex() - val matchResult = regex.find("Mickey Mouse is 95 years old") - val (name, age) = matchResult!!.destructured - - assertEquals("Mickey Mouse", name) - assertEquals("95", age) - } - - @Test - fun givenNonMatchingRegex_whenFindCalled_thenNull() { - val regex = """a([bc]+)d?""".toRegex() - val matchResult = regex.find("foo") - - assertNull(matchResult) - } - - @Test - fun givenNonMatchingRegex_whenFindAllCalled_thenEmptySet() { - val regex = """a([bc]+)d?""".toRegex() - val matchResults = regex.findAll("foo") - - assertNotNull(matchResults) - assertTrue(matchResults.none()) - } - - @Test - fun whenReplace_thenReplacement() { - val regex = """(red|green|blue)""".toRegex() - val beautiful = "Roses are red, Violets are blue" - val grim = regex.replace(beautiful, "dark") - val shiny = regex.replaceFirst(beautiful, "rainbow") - - assertEquals("Roses are dark, Violets are dark", grim) - assertEquals("Roses are rainbow, Violets are blue", shiny) - } - - @Test - fun whenComplexReplace_thenReplacement() { - val regex = """(red|green|blue)""".toRegex() - val beautiful = "Roses are red, Violets are blue" - val reallyBeautiful = regex.replace(beautiful) { - matchResult -> matchResult.value.toUpperCase() + "!" - } - - assertEquals("Roses are RED!, Violets are BLUE!", reallyBeautiful) - } - - @Test - fun whenSplit_thenList() { - val regex = """\W+""".toRegex() - val beautiful = "Roses are red, Violets are blue" - - assertEquals(listOf("Roses", "are", "red", "Violets", "are", "blue"), regex.split(beautiful)) - assertEquals(listOf("Roses", "are", "red", "Violets are blue"), regex.split(beautiful, 4)) - assertEquals(regex.toPattern().split(beautiful).asList(), regex.split(beautiful)) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/README.md b/core-kotlin-modules/core-kotlin-annotations/README.md deleted file mode 100644 index 787b67be11..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Core Kotlin Annotations - -This module contains articles about core Kotlin annotations. - -### Relevant articles: -- [Kotlin Annotations](https://www.baeldung.com/kotlin-annotations) -- [Guide to Kotlin @JvmField](https://www.baeldung.com/kotlin-jvm-field-annotation) -- [Guide to JVM Platform Annotations in Kotlin](https://www.baeldung.com/kotlin-jvm-annotations) diff --git a/core-kotlin-modules/core-kotlin-annotations/pom.xml b/core-kotlin-modules/core-kotlin-annotations/pom.xml deleted file mode 100644 index 77670be151..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - core-kotlin-annotations - core-kotlin-annotations - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 1.3.30 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt deleted file mode 100644 index a8f83446dc..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.annotations - -@Target(AnnotationTarget.FIELD) -annotation class Positive - -@Target(AnnotationTarget.FIELD) -annotation class AllowedNames(val names: Array) diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt deleted file mode 100644 index 6864fe416e..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.annotations - -class Item(@Positive val amount: Float, @AllowedNames(["Alice", "Bob"]) val name: String) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt deleted file mode 100644 index 2b7f2c5590..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.annotations - -fun main(args: Array) { - val item = Item(amount = 1.0f, name = "Bob") - val validator = Validator() - println("Is instance valid? ${validator.isValid(item)}") -} diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt deleted file mode 100644 index 40139048ab..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.annotations - -/** - * Naive annotation-based validator. - * @author A.Shcherbakov - */ -class Validator() { - - /** - * Return true if every item's property annotated with @Positive is positive and if - * every item's property annotated with @AllowedNames has a value specified in that annotation. - */ - fun isValid(item: Item): Boolean { - val fields = item::class.java.declaredFields - for (field in fields) { - field.isAccessible = true - for (annotation in field.annotations) { - val value = field.get(item) - if (field.isAnnotationPresent(Positive::class.java)) { - val amount = value as Float - if (amount < 0) { - return false - } - } - if (field.isAnnotationPresent(AllowedNames::class.java)) { - val allowedNames = field.getAnnotation(AllowedNames::class.java)?.names - val name = value as String - allowedNames?.let { - if (!it.contains(name)) { - return false - } - } - } - } - } - return true - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt deleted file mode 100644 index 55f60bfa81..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.jvmannotations - -import java.util.* - -interface Document { - - @JvmDefault - fun getTypeDefault() = "document" - - fun getType() = "document" -} diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java deleted file mode 100644 index feb71772cb..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.jvmannotations; - -public class HtmlDocument implements Document { - - @Override - public String getType() { - return "HTML"; - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt deleted file mode 100644 index 80180bd924..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt +++ /dev/null @@ -1,66 +0,0 @@ -@file:JvmName("MessageHelper") -@file:JvmMultifileClass //used -package com.baeldung.jvmannotations - -import java.util.* - -@JvmName("getMyUsername") -fun getMyName() : String { - return "myUserId" -} - -object MessageBroker { - @JvmStatic - var totalMessagesSent = 0 - - const val maxMessageLength = 0 - - @JvmStatic - fun clearAllMessages() { - } - - @JvmStatic - @JvmOverloads - @Throws(Exception::class) - fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List { - if(sender.isEmpty()) { - throw Exception() - } - return ArrayList() - } -} - -class Message { - - // this would cause a compilation error since sender is immutable - // @set:JvmName("setSender") - val sender = "myself" - - // this works as name is overridden - @JvmName("getSenderName") - fun getSender() : String = "from:$sender" - - @get:JvmName("getReceiverName") - @set:JvmName("setReceiverName") - var receiver : String = "" - - @get:JvmName("getContent") - @set:JvmName("setContent") - var text = "" - - // generates a warning - @get:JvmName("getId") - private val id = 0 - - @get:JvmName("hasAttachment") - var hasAttachment = true - - var isEncrypted = true - - fun setReceivers(receiverNames : List) { - } - - @JvmName("setReceiverIds") - fun setReceivers(receiverNames : List) { - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt deleted file mode 100644 index 3b19b12e10..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt +++ /dev/null @@ -1,6 +0,0 @@ -@file:JvmMultifileClass -@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants -package com.baeldung.jvmannotations - -fun convert(message: Message) { -} diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt deleted file mode 100644 index 41cb0df939..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.jvmannotations - -import java.util.* -class TextDocument : Document { - override fun getType() = "text" - - fun transformList(list : List) : List { - return list.filter { n -> n.toInt() > 1 } - } - - fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> { - return list.filter { n -> n.toInt() > 1 } - } - - var list : List<@JvmWildcard Any> = ArrayList() -} diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt deleted file mode 100644 index 00f2582d5f..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.jvmannotations - -import java.util.* - -class XmlDocument(d : Document) : Document by d diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt deleted file mode 100644 index e60894ba88..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.jvmfield - -class JvmSample(text:String) { - @JvmField - val sampleText:String = text -} - -class CompanionSample { - companion object { - @JvmField val MAX_LIMIT = 20 - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt deleted file mode 100644 index 5c2b6ef47f..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.annotations - -import org.junit.Test -import kotlin.test.assertTrue -import kotlin.test.assertFalse - -class ValidationTest { - - @Test - fun whenAmountIsOneAndNameIsAlice_thenTrue() { - assertTrue(Validator().isValid(Item(1f, "Alice"))) - } - - @Test - fun whenAmountIsOneAndNameIsBob_thenTrue() { - assertTrue(Validator().isValid(Item(1f, "Bob"))) - } - - - @Test - fun whenAmountIsMinusOneAndNameIsAlice_thenFalse() { - assertFalse(Validator().isValid(Item(-1f, "Alice"))) - } - - @Test - fun whenAmountIsMinusOneAndNameIsBob_thenFalse() { - assertFalse(Validator().isValid(Item(-1f, "Bob"))) - } - - @Test - fun whenAmountIsOneAndNameIsTom_thenFalse() { - assertFalse(Validator().isValid(Item(1f, "Tom"))) - } - - @Test - fun whenAmountIsMinusOneAndNameIsTom_thenFalse() { - assertFalse(Validator().isValid(Item(-1f, "Tom"))) - } - - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt deleted file mode 100644 index 2ec5402e5a..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -import com.baeldung.jvmannotations.*; - -class DocumentTest { - - @Test - fun testDefaultMethod() { - - val myDocument = TextDocument() - val myTextDocument = XmlDocument(myDocument) - - assertEquals("text", myDocument.getType()) - assertEquals("text", myTextDocument.getType()) - assertEquals("document", myTextDocument.getTypeDefault()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt deleted file mode 100644 index 769c0311c4..0000000000 --- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.jvmfield - -import org.junit.Before -import org.junit.Test -import kotlin.test.assertTrue - -class JvmSampleTest { - - var sample = "" - - @Before - fun setUp() { - sample = JvmSample("Hello!").sampleText - } - - @Test - fun givenField_whenCheckValue_thenMatchesValue() { - assertTrue(sample == "Hello!") - } - - @Test - fun givenStaticVariable_whenCheckValue_thenMatchesValue() { - // Sample when is treated as a static variable - assertTrue(CompanionSample.MAX_LIMIT == 20) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections-2/README.md b/core-kotlin-modules/core-kotlin-collections-2/README.md deleted file mode 100644 index 64062ee704..0000000000 --- a/core-kotlin-modules/core-kotlin-collections-2/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Core Kotlin Collections - -This module contains articles about core Kotlin collections. - -## Relevant articles: - -- [Aggregate Operations in Kotlin](https://www.baeldung.com/kotlin/aggregate-operations) diff --git a/core-kotlin-modules/core-kotlin-collections-2/pom.xml b/core-kotlin-modules/core-kotlin-collections-2/pom.xml deleted file mode 100644 index be462eed45..0000000000 --- a/core-kotlin-modules/core-kotlin-collections-2/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - 4.0.0 - core-kotlin-collections-2 - core-kotlin-collections-2 - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 1.3.30 - 3.6.1 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections-2/src/main/kotlin/com/baeldung/aggregate/AggregateOperations.kt b/core-kotlin-modules/core-kotlin-collections-2/src/main/kotlin/com/baeldung/aggregate/AggregateOperations.kt deleted file mode 100644 index a09e101b59..0000000000 --- a/core-kotlin-modules/core-kotlin-collections-2/src/main/kotlin/com/baeldung/aggregate/AggregateOperations.kt +++ /dev/null @@ -1,107 +0,0 @@ -package com.baeldung.aggregate - -class AggregateOperations { - private val numbers = listOf(1, 15, 3, 8) - - fun countList(): Int { - return numbers.count() - } - - fun sumList(): Int { - return numbers.sum() - } - - fun averageList(): Double { - return numbers.average() - } - - fun maximumInList(): Int? { - return numbers.max() - } - - fun minimumInList(): Int? { - return numbers.min() - } - - fun maximumByList(): Int? { - return numbers.maxBy { it % 5 } - } - - fun minimumByList(): Int? { - return numbers.minBy { it % 5 } - } - - fun maximumWithList(): String? { - val strings = listOf("Berlin", "Kolkata", "Prague", "Barcelona") - return strings.maxWith(compareBy { it.length % 4 }) - } - - fun minimumWithList(): String? { - val strings = listOf("Berlin", "Kolkata", "Prague", "Barcelona") - return strings.minWith(compareBy { it.length % 4 }) - } - - fun sumByList(): Int { - return numbers.sumBy { it * 5 } - } - - fun sumByDoubleList(): Double { - return numbers.sumByDouble { it.toDouble() / 8 } - } - - fun foldList(): Int { - return numbers.fold(100) { total, it -> - println("total = $total, it = $it") - total - it - } // ((((100 - 1)-15)-3)-8) = 73 - } - - fun foldRightList(): Int { - return numbers.foldRight(100) { it, total -> - println("total = $total, it = $it") - total - it - } // ((((100-8)-3)-15)-1) = 73 - } - - fun foldIndexedList(): Int { - return numbers.foldIndexed(100) { index, total, it -> - println("total = $total, it = $it, index = $index") - if (index.minus(2) >= 0) total - it else total - } // ((100 - 3)-8) = 89 - } - - fun foldRightIndexedList(): Int { - return numbers.foldRightIndexed(100) { index, it, total -> - println("total = $total, it = $it, index = $index") - if (index.minus(2) >= 0) total - it else total - } // ((100 - 8)-3) = 89 - } - - fun reduceList(): Int { - return numbers.reduce { total, it -> - println("total = $total, it = $it") - total - it - } // (((1 - 15)-3)-8) = -25 - } - - fun reduceRightList(): Int { - return numbers.reduceRight() { it, total -> - println("total = $total, it = $it") - total - it - } // ((8-3)-15)-1) = -11 - } - - fun reduceIndexedList(): Int { - return numbers.reduceIndexed { index, total, it -> - println("total = $total, it = $it, index = $index") - if (index.minus(2) >= 0) total - it else total - } // ((1-3)-8) = -10 - } - - fun reduceRightIndexedList(): Int { - return numbers.reduceRightIndexed { index, it, total -> - println("total = $total, it = $it, index = $index") - if (index.minus(2) >= 0) total - it else total - } // ((8-3) = 5 - } -} diff --git a/core-kotlin-modules/core-kotlin-collections-2/src/test/kotlin/com/baeldung/aggregate/AggregateOperationsUnitTest.kt b/core-kotlin-modules/core-kotlin-collections-2/src/test/kotlin/com/baeldung/aggregate/AggregateOperationsUnitTest.kt deleted file mode 100644 index a619759b0a..0000000000 --- a/core-kotlin-modules/core-kotlin-collections-2/src/test/kotlin/com/baeldung/aggregate/AggregateOperationsUnitTest.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.baeldung.aggregate - -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class AggregateOperationsUnitTest { - - private val classUnderTest: AggregateOperations = AggregateOperations() - - @Test - fun whenCountOfList_thenReturnsValue() { - assertEquals(4, classUnderTest.countList()) - } - - @Test - fun whenSumOfList_thenReturnsTotalValue() { - assertEquals(27, classUnderTest.sumList()) - } - - @Test - fun whenAverageOfList_thenReturnsValue() { - assertEquals(6.75, classUnderTest.averageList()) - } - - @Test - fun whenMaximumOfList_thenReturnsMaximumValue() { - assertEquals(15, classUnderTest.maximumInList()) - } - - @Test - fun whenMinimumOfList_thenReturnsMinimumValue() { - assertEquals(1, classUnderTest.minimumInList()) - } - - @Test - fun whenMaxByList_thenReturnsLargestValue() { - assertEquals(3, classUnderTest.maximumByList()) - } - - @Test - fun whenMinByList_thenReturnsSmallestValue() { - assertEquals(15, classUnderTest.minimumByList()) - } - - @Test - fun whenMaxWithList_thenReturnsLargestValue(){ - assertEquals("Kolkata", classUnderTest.maximumWithList()) - } - - @Test - fun whenMinWithList_thenReturnsSmallestValue(){ - assertEquals("Barcelona", classUnderTest.minimumWithList()) - } - - @Test - fun whenSumByList_thenReturnsIntegerValue(){ - assertEquals(135, classUnderTest.sumByList()) - } - - @Test - fun whenSumByDoubleList_thenReturnsDoubleValue(){ - assertEquals(3.375, classUnderTest.sumByDoubleList()) - } - - @Test - fun whenFoldList_thenReturnsValue(){ - assertEquals(73, classUnderTest.foldList()) - } - - @Test - fun whenFoldRightList_thenReturnsValue(){ - assertEquals(73, classUnderTest.foldRightList()) - } - - @Test - fun whenFoldIndexedList_thenReturnsValue(){ - assertEquals(89, classUnderTest.foldIndexedList()) - } - - @Test - fun whenFoldRightIndexedList_thenReturnsValue(){ - assertEquals(89, classUnderTest.foldRightIndexedList()) - } - - @Test - fun whenReduceList_thenReturnsValue(){ - assertEquals(-25, classUnderTest.reduceList()) - } - - @Test - fun whenReduceRightList_thenReturnsValue(){ - assertEquals(-11, classUnderTest.reduceRightList()) - } - - @Test - fun whenReduceIndexedList_thenReturnsValue(){ - assertEquals(-10, classUnderTest.reduceIndexedList()) - } - - @Test - fun whenReduceRightIndexedList_thenReturnsValue(){ - assertEquals(5, classUnderTest.reduceRightIndexedList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/README.md b/core-kotlin-modules/core-kotlin-collections/README.md deleted file mode 100644 index 2ebb748cba..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Core Kotlin Collections - -This module contains articles about core Kotlin collections. - -### Relevant articles: - -- [Split a List Into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts) -- [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list) -- [Overview of Kotlin Collections API](https://www.baeldung.com/kotlin-collections-api) -- [Converting a List to Map in Kotlin](https://www.baeldung.com/kotlin-list-to-map) -- [Filtering Kotlin Collections](https://www.baeldung.com/kotlin-filter-collection) -- [Collection Transformations in Kotlin](https://www.baeldung.com/kotlin-collection-transformations) -- [Difference between fold and reduce in Kotlin](https://www.baeldung.com/kotlin/fold-vs-reduce) -- [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort) -- [Working With Lists in Kotlin](https://www.baeldung.com/kotlin/lists) -- [Iterating Collections by Index in Kotlin](https://www.baeldung.com/kotlin/iterating-collections-by-index) diff --git a/core-kotlin-modules/core-kotlin-collections/pom.xml b/core-kotlin-modules/core-kotlin-collections/pom.xml deleted file mode 100644 index 52401d267c..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - 4.0.0 - core-kotlin-collections - core-kotlin-collections - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 1.3.30 - 3.6.1 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt deleted file mode 100644 index 07fb595ede..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.index - -fun main() { - - // Index only - val colors = listOf("Red", "Green", "Blue") - for (i in colors.indices) { - println(colors[i]) - } - - val colorArray = arrayOf("Red", "Green", "Blue") - for (i in colorArray.indices) { - println(colorArray[i]) - } - - (0 until colors.size).forEach { println(colors[it]) } - for (i in 0 until colors.size) { - println(colors[i]) - } - - // Index and Value - colors.forEachIndexed { i, v -> println("The value for index $i is $v") } - for (indexedValue in colors.withIndex()) { - println("The value for index ${indexedValue.index} is ${indexedValue.value}") - } - - for ((i, v) in colors.withIndex()) { - println("The value for index $i is $v") - } - - colors.filterIndexed { i, _ -> i % 2 == 0 } - colors.filterIndexed { _, v -> v == "RED" } -} diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt deleted file mode 100644 index a29eabe623..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt +++ /dev/null @@ -1,204 +0,0 @@ -package com.baeldung.kotlin.collections - -import kotlin.collections.List - -class ListExample { - - private val countries = listOf("Germany", "India", "Japan", "Brazil", "Australia") - private val cities = mutableListOf("Berlin", "Calcutta", "Seoul", "Sao Paulo", "Sydney") - - fun createList(): List { - val countryList = listOf("Germany", "India", "Japan", "Brazil") - return countryList - } - - fun createMutableList(): MutableList { - val cityList = mutableListOf("Berlin", "Calcutta", "Seoul", "Sao Paulo") - return cityList - } - - fun iterateUsingForEachLoop(): List { - val countryLength = mutableListOf() - countries.forEach { it -> - print("$it ") - println(" Length: ${it.length}") - countryLength.add(it.length) - } - return countryLength - } - - fun iterateUsingForLoop(): List { - val countryLength = mutableListOf() - for (country in countries) { - print("$country ") - println(" Length: ${country.length}") - countryLength.add(country.length) - } - return countryLength - } - - fun iterateUsingForLoopRange(): List { - val countryLength = mutableListOf() - for (i in 0 until countries.size) { - print("${countries[i]} ") - println(" Length: ${countries[i].length}") - countryLength.add(countries[i].length) - } - return countryLength - } - - fun iterateUsingForEachIndexedLoop(): List { - val countryLength = mutableListOf() - countries.forEachIndexed { i, e -> - println("country[$i] = $e") - print(" Index: $i") - println(" Length: ${e.length}") - countryLength.add(e.length) - } - return countryLength - } - - fun iterateUsingListIterator() { - val iterator = countries.listIterator() - while (iterator.hasNext()) { - val country = iterator.next() - print("$country ") - } - println() - - while (iterator.hasPrevious()) { - println("Index: ${iterator.previousIndex()}") - } - } - - fun iterateUsingIterator() { - val iterator = cities.iterator() - iterator.next() - iterator.remove() - println(cities) - } - - fun iterateUsingMutableListIterator() { - val iterator = cities.listIterator(1) - iterator.next() - iterator.add("London") - iterator.next() - iterator.set("Milan") - println(cities) - } - - fun retrieveElementsInList(): String { - println(countries[2]) - return countries[2] - } - - fun retrieveElementsUsingGet(): String { - println(countries.get(3)) - return countries.get(3) - } - - fun retrieveElementsFirstAndLast(): String? { - println(countries.first()) - println(countries.last()) - println(countries.first { it.length > 7 }) - println(countries.last { it.startsWith("J") }) - println(countries.firstOrNull { it.length > 8 }) - return countries.firstOrNull { it.length > 8 } - } - - fun retrieveSubList(): List { - val subList = countries.subList(1, 4) - println(subList) - return subList - } - - fun retrieveListSliceUsingIndices(): List { - val sliceList = countries.slice(1..4) - println(sliceList) - return sliceList - } - - fun retrieveListSliceUsingIndicesList(): List { - val sliceList = countries.slice(listOf(1, 4)) - println(sliceList) - return sliceList - } - - fun countList(): Int { - val count = countries.count() - println(count) - return count - } - - fun countListUsingPredicate(): Int { - val count = countries.count { it.length > 5 } - println(count) - return count - } - - fun countListUsingProperty(): Int { - val size = countries.size - println(size) - return size - } - - fun addToList(): List { - cities.add("Barcelona") - println(cities) - cities.add(3, "London") - println(cities) - cities.addAll(listOf("Singapore", "Moscow")) - println(cities) - cities.addAll(2, listOf("Prague", "Amsterdam")) - println(cities) - return cities - } - - fun removeFromList(): List { - cities.remove("Seoul") - println(cities) - cities.removeAt(1) - println(cities) - return cities - } - - fun replaceFromList(): List { - cities.set(3, "Prague") - println(cities) - cities[4] = "Moscow" - println(cities) - cities.fill("Barcelona") - println(cities) - return cities - } - - fun sortMutableList(): List { - cities.sort() - println(cities) - cities.sortDescending() - println(cities) - return cities - } - - fun sortList(): List { - val sortedCountries = countries.sorted() - println("countries = $countries") - println("sortedCountries = $sortedCountries") - val sortedCountriesDescending = countries.sortedDescending() - println("countries = $countries") - println("sortedCountriesDescending = $sortedCountriesDescending") - return sortedCountriesDescending - } - - fun checkOneElementInList(): Boolean { - return countries.contains("Germany") - } - - fun checkOneElementInListUsingOperator(): Boolean { - return "Spain" in countries - } - - fun checkElementsInList(): Boolean { - return cities.containsAll(listOf("Calcutta", "Sao Paulo", "Sydney")) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt deleted file mode 100644 index bf3163bc8f..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.sorting - -fun sortMethodUsage() { - val sortedValues = mutableListOf(1, 2, 7, 6, 5, 6) - sortedValues.sort() - println(sortedValues) -} - -fun sortByMethodUsage() { - val sortedValues = mutableListOf(1 to "a", 2 to "b", 7 to "c", 6 to "d", 5 to "c", 6 to "e") - sortedValues.sortBy { it.second } - println(sortedValues) -} - -fun sortWithMethodUsage() { - val sortedValues = mutableListOf(1 to "a", 2 to "b", 7 to "c", 6 to "d", 5 to "c", 6 to "e") - sortedValues.sortWith(compareBy({it.second}, {it.first})) - println(sortedValues) -} - -fun > getSimpleComparator() : Comparator { - val ascComparator = naturalOrder() - return ascComparator -} - -fun getComplexComparator() { - val complexComparator = compareBy>({it.first}, {it.second}) -} - -fun nullHandlingUsage() { - val sortedValues = mutableListOf(1 to "a", 2 to null, 7 to "c", 6 to "d", 5 to "c", 6 to "e") - sortedValues.sortWith(nullsLast(compareBy { it.second })) - println(sortedValues) -} - -fun extendedComparatorUsage() { - val students = mutableListOf(21 to "Helen", 21 to "Tom", 20 to "Jim") - - val ageComparator = compareBy> {it.first} - val ageAndNameComparator = ageComparator.thenByDescending {it.second} - println(students.sortedWith(ageAndNameComparator)) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt deleted file mode 100644 index 67fbb29026..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt +++ /dev/null @@ -1,212 +0,0 @@ -package com.baeldung.collections - -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class CollectionsTest { - - @Test - fun whenUseDifferentCollections_thenSuccess() { - val theList = listOf("one", "two", "three") - assertTrue(theList.contains("two")) - - val theMutableList = mutableListOf("one", "two", "three") - theMutableList.add("four") - assertTrue(theMutableList.contains("four")) - - val theSet = setOf("one", "two", "three") - assertTrue(theSet.contains("three")) - - val theMutableSet = mutableSetOf("one", "two", "three") - theMutableSet.add("four") - assertTrue(theMutableSet.contains("four")) - - val theMap = mapOf(1 to "one", 2 to "two", 3 to "three") - assertEquals(theMap[2], "two") - - val theMutableMap = mutableMapOf(1 to "one", 2 to "two", 3 to "three") - theMutableMap[4] = "four" - assertEquals(theMutableMap[4], "four") - } - - @Test - fun whenSliceCollection_thenSuccess() { - val theList = listOf("one", "two", "three") - val resultList = theList.slice(1..2) - - assertEquals(2, resultList.size) - assertTrue(resultList.contains("two")) - } - - @Test - fun whenJoinTwoCollections_thenSuccess() { - val firstList = listOf("one", "two", "three") - val secondList = listOf("four", "five", "six") - val resultList = firstList + secondList - - assertEquals(6, resultList.size) - assertTrue(resultList.contains("two")) - assertTrue(resultList.contains("five")) - } - - @Test - fun whenFilterNullValues_thenSuccess() { - val theList = listOf("one", null, "two", null, "three") - val resultList = theList.filterNotNull() - - assertEquals(3, resultList.size) - } - - @Test - fun whenFilterNonPositiveValues_thenSuccess() { - val theList = listOf(1, 2, -3, -4, 5, -6) - val resultList = theList.filter { it > 0 } - //val resultList = theList.filter{ x -> x > 0} - - assertEquals(3, resultList.size) - assertTrue(resultList.contains(1)) - assertFalse(resultList.contains(-4)) - } - - @Test - fun whenDropFirstItems_thenRemoved() { - val theList = listOf("one", "two", "three", "four") - val resultList = theList.drop(2) - - assertEquals(2, resultList.size) - assertFalse(resultList.contains("one")) - assertFalse(resultList.contains("two")) - } - - @Test - fun whenDropFirstItemsBasedOnCondition_thenRemoved() { - val theList = listOf("one", "two", "three", "four") - val resultList = theList.dropWhile { it.length < 4 } - - assertEquals(2, resultList.size) - assertFalse(resultList.contains("one")) - assertFalse(resultList.contains("two")) - } - - @Test - fun whenExcludeItems_thenRemoved() { - val firstList = listOf("one", "two", "three") - val secondList = listOf("one", "three") - val resultList = firstList - secondList - - assertEquals(1, resultList.size) - assertTrue(resultList.contains("two")) - } - - @Test - fun whenSearchForExistingItem_thenFound() { - val theList = listOf("one", "two", "three") - - assertTrue("two" in theList) - } - - @Test - fun whenGroupItems_thenSuccess() { - val theList = listOf(1, 2, 3, 4, 5, 6) - val resultMap = theList.groupBy { it % 3 } - - assertEquals(3, resultMap.size) - print(resultMap[1]) - assertTrue(resultMap[1]!!.contains(1)) - assertTrue(resultMap[2]!!.contains(5)) - } - - @Test - fun whenApplyFunctionToAllItems_thenSuccess() { - val theList = listOf(1, 2, 3, 4, 5, 6) - val resultList = theList.map { it * it } - print(resultList) - assertEquals(4, resultList[1]) - assertEquals(9, resultList[2]) - } - - @Test - fun whenApplyMultiOutputFunctionToAllItems_thenSuccess() { - val theList = listOf("John", "Tom") - val resultList = theList.flatMap { it.toLowerCase().toList() } - print(resultList) - assertEquals(7, resultList.size) - assertTrue(resultList.contains('j')) - } - - @Test - fun whenApplyFunctionToAllItemsWithStartingValue_thenSuccess() { - val theList = listOf(1, 2, 3, 4, 5, 6) - val finalResult = theList.fold(1000, { oldResult, currentItem -> oldResult + (currentItem * currentItem) }) - print(finalResult) - assertEquals(1091, finalResult) - } - - @Test - fun whenApplyingChunked_thenShouldBreakTheCollection() { - val theList = listOf(1, 2, 3, 4, 5) - val chunked = theList.chunked(2) - - assertThat(chunked.size).isEqualTo(3) - assertThat(chunked.first()).contains(1, 2) - assertThat(chunked[1]).contains(3, 4) - assertThat(chunked.last()).contains(5) - } - - @Test - fun whenApplyingChunkedWithTransformation_thenShouldBreakTheCollection() { - val theList = listOf(1, 2, 3, 4, 5) - val chunked = theList.chunked(3) { it.joinToString(", ") } - - assertThat(chunked.size).isEqualTo(2) - assertThat(chunked.first()).isEqualTo("1, 2, 3") - assertThat(chunked.last()).isEqualTo("4, 5") - } - - @Test - fun whenApplyingWindowed_thenShouldCreateSlidingWindowsOfElements() { - val theList = (1..6).toList() - val windowed = theList.windowed(3) - - assertThat(windowed.size).isEqualTo(4) - assertThat(windowed.first()).contains(1, 2, 3) - assertThat(windowed[1]).contains(2, 3, 4) - assertThat(windowed[2]).contains(3, 4, 5) - assertThat(windowed.last()).contains(4, 5, 6) - } - - @Test - fun whenApplyingWindowedWithTwoSteps_thenShouldCreateSlidingWindowsOfElements() { - val theList = (1..6).toList() - val windowed = theList.windowed(size = 3, step = 2) - - assertThat(windowed.size).isEqualTo(2) - assertThat(windowed.first()).contains(1, 2, 3) - assertThat(windowed.last()).contains(3, 4, 5) - } - - @Test - fun whenApplyingPartialWindowedWithTwoSteps_thenShouldCreateSlidingWindowsOfElements() { - val theList = (1..6).toList() - val windowed = theList.windowed(size = 3, step = 2, partialWindows = true) - - assertThat(windowed.size).isEqualTo(3) - assertThat(windowed.first()).contains(1, 2, 3) - assertThat(windowed[1]).contains(3, 4, 5) - assertThat(windowed.last()).contains(5, 6) - } - - @Test - fun whenApplyingTransformingWindows_thenShouldCreateSlidingWindowsOfElements() { - val theList = (1..6).toList() - val windowed = theList.windowed(size = 3, step = 2, partialWindows = true) { it.joinToString(", ") } - - assertThat(windowed.size).isEqualTo(3) - assertThat(windowed.first()).isEqualTo("1, 2, 3") - assertThat(windowed[1]).isEqualTo("3, 4, 5") - assertThat(windowed.last()).isEqualTo("5, 6") - } -} diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt deleted file mode 100644 index 68f7040c4c..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class AssociateUnitTest { - @Test - fun testToMap() { - val input = listOf(Pair("one", 1), Pair("two", 2)) - val map = input.toMap() - assertEquals(mapOf("one" to 1, "two" to 2), map) - } - - @Test - fun testAssociateWith() { - val inputs = listOf("Hi", "there") - val map = inputs.associateWith { k -> k.length } - assertEquals(mapOf("Hi" to 2, "there" to 5), map) - } - - @Test - fun testAssociateBy() { - val inputs = listOf("Hi", "there") - val map = inputs.associateBy { v -> v.length } - assertEquals(mapOf(2 to "Hi", 5 to "there"), map) - } - - @Test - fun testAssociate() { - val inputs = listOf("Hi", "there") - val map = inputs.associate { e -> Pair(e.toUpperCase(), e.reversed()) } - assertEquals(mapOf("HI" to "iH", "THERE" to "ereht"), map) - } - - @Test - fun testAssociateByDuplicateKeys() { - val inputs = listOf("one", "two") - val map = inputs.associateBy { v -> v.length } - assertEquals(mapOf(3 to "two"), map) - } - - @Test - fun testGroupBy() { - val inputs = listOf("one", "two", "three") - val map = inputs.groupBy { v -> v.length } - assertEquals(mapOf(3 to listOf("one", "two"), 5 to listOf("three")), map) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt deleted file mode 100644 index 591577e4f3..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class FilterUnitTest { - @Test - fun testFilterWithLambda() { - val input = listOf(1, 2, 3, 4, 5) - val filtered = input.filter { it <= 3 } - assertEquals(listOf(1, 2, 3), filtered) - } - - @Test - fun testFilterWithMethodReference() { - val input = listOf(1, 2, 3, 4, 5) - val filtered = input.filter(this::isSmall) - assertEquals(listOf(1, 2, 3), filtered) - } - - @Test - fun testFilterNotWithMethodReference() { - val input = listOf(1, 2, 3, 4, 5) - val filtered = input.filterNot(this::isSmall) - assertEquals(listOf(4, 5), filtered) - } - - @Test - fun testFilterIndexed() { - val input = listOf(5, 4, 3, 2, 1) - val filtered = input.filterIndexed { index, element -> index < 3 } - assertEquals(listOf(5, 4, 3), filtered) - } - - @Test - fun testFilterNotNull() { - val nullable: List = listOf("Hello", null, "World") - val nonnull: List = nullable.filterNotNull() - assertEquals(listOf("Hello", "World"), nonnull) - } - - private fun isSmall(i: Int) = i <= 3 -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt deleted file mode 100644 index 69fbceb8e3..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class FlattenUnitTest { - @Test - fun testFlatten() { - val inputs = listOf("one", "two", "three") - val characters = inputs.map(String::toList) - val flattened = characters.flatten(); - assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), flattened) - } - - @Test - fun testFlatMap() { - val inputs = listOf("one", "two", "three") - val characters = inputs.flatMap(String::toList) - assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), characters) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt deleted file mode 100644 index 2ac0cdca50..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class JoinToUnitTest { - @Test - fun testJoinToString() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val simpleString = inputs.joinToString() - assertEquals("Jan, Feb, Mar, Apr, May", simpleString) - - val detailedString = inputs.joinToString(separator = ",", prefix="Months: ", postfix=".") - assertEquals("Months: Jan,Feb,Mar,Apr,May.", detailedString) - } - - @Test - fun testJoinToStringLimits() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val simpleString = inputs.joinToString(limit = 3) - assertEquals("Jan, Feb, Mar, ...", simpleString) - } - - @Test - fun testJoinToStringTransform() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val simpleString = inputs.joinToString(transform = String::toUpperCase) - assertEquals("JAN, FEB, MAR, APR, MAY", simpleString) - } - - @Test - fun testJoinTo() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val output = StringBuilder() - output.append("My ") - .append(inputs.size) - .append(" elements: ") - inputs.joinTo(output) - - assertEquals("My 5 elements: Jan, Feb, Mar, Apr, May", output.toString()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt deleted file mode 100644 index e22fcbe903..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class MapUnitTest { - @Test - fun testMapWithLambda() { - val input = listOf("one", "two", "three") - - val reversed = input.map { it.reversed() } - assertEquals(listOf("eno", "owt", "eerht"), reversed) - - val lengths = input.map { it.length } - assertEquals(listOf(3, 3, 5), lengths) - } - - @Test - fun testMapIndexed() { - val input = listOf(3, 2, 1) - val result = input.mapIndexed { index, value -> index * value } - assertEquals(listOf(0, 2, 2), result) - } - - @Test - fun testMapNotNull() { - val input = listOf(1, 2, 3, 4, 5) - val smallSquares = input.mapNotNull { - if (it <= 3) { - it * it - } else { - null - } - } - assertEquals(listOf(1, 4, 9), smallSquares) - } - - @Test - fun mapMapKeys() { - val inputs = mapOf("one" to 1, "two" to 2, "three" to 3) - - val uppercases = inputs.mapKeys { it.key.toUpperCase() } - assertEquals(mapOf("ONE" to 1, "TWO" to 2, "THREE" to 3), uppercases) - } - - @Test - fun mapMapValues() { - val inputs = mapOf("one" to 1, "two" to 2, "three" to 3) - - val squares = inputs.mapValues { it.value * it.value } - assertEquals(mapOf("one" to 1, "two" to 4, "three" to 9), squares) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt deleted file mode 100644 index 6821b7cdb9..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class ReduceUnitTest { - @Test - fun testJoinToStringAsReduce() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val result = inputs.reduce { acc, next -> "$acc, $next" } - assertEquals("Jan, Feb, Mar, Apr, May", result) - } - - @Test - fun testFoldToLength() { - val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") - - val result = inputs.fold(0) { acc, next -> acc + next.length } - assertEquals(15, result) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt deleted file mode 100644 index 66aeeceef4..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.collections.transformations - -import org.junit.Assert.assertEquals -import org.junit.Test - -class ZipUnitTest { - @Test - fun testZip() { - val left = listOf("one", "two", "three") - val right = listOf(1, 2, 3) - val zipped = left.zip(right) - assertEquals (listOf(Pair("one", 1), Pair("two", 2), Pair("three", 3)), zipped) - } - - @Test - fun testZipShort() { - val left = listOf("one", "two") - val right = listOf(1, 2, 3) - val zipped = left.zip(right) - assertEquals (listOf(Pair("one", 1), Pair("two", 2)), zipped) - } - - @Test - fun testUnzip() { - val left = listOf("one", "two", "three") - val right = listOf(1, 2, 3) - val zipped = left.zip(right) - - val (newLeft, newRight) = zipped.unzip() - assertEquals(left, newLeft) - assertEquals(right, newRight) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt deleted file mode 100644 index 20797cc633..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.filter - -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Test - -internal class ChunkedTest { - - @Test - fun givenDNAFragmentString_whenChunking_thenProduceListOfChunks() { - val dnaFragment = "ATTCGCGGCCGCCAA" - - val fragments = dnaFragment.chunked(3) - - assertIterableEquals(listOf("ATT", "CGC", "GGC", "CGC", "CAA"), fragments) - } - - @Test - fun givenDNAString_whenChunkingWithTransformer_thenProduceTransformedList() { - val codonTable = mapOf("ATT" to "Isoleucine", "CAA" to "Glutamine", "CGC" to "Arginine", "GGC" to "Glycine") - val dnaFragment = "ATTCGCGGCCGCCAA" - - val proteins = dnaFragment.chunked(3) { codon -> - codonTable[codon.toString()] ?: error("Unknown codon") - } - - assertIterableEquals(listOf("Isoleucine", "Arginine", "Glycine", "Arginine", "Glutamine"), proteins) - } - - @Test - fun givenListOfValues_whenChunking_thenProduceListOfArrays() { - val whole = listOf(1, 4, 7, 4753, 2, 34, 62, 76, 5868, 0) - val chunks = whole.chunked(6) - - val expected = listOf(listOf(1, 4, 7, 4753, 2, 34), listOf(62, 76, 5868, 0)) - - assertIterableEquals(expected, chunks) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt deleted file mode 100644 index 4cc6f647e1..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.filter - -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Test - -internal class DistinctTest { - data class SmallClass(val key: String, val num: Int) - - @Test - fun whenApplyingDistinct_thenReturnListOfNoDuplicateValues() { - val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9) - val result = array.distinct() - val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) - - assertIterableEquals(expected, result) - } - - @Test - fun givenArrayOfClassObjects_whenApplyingDistinctOnClassProperty_thenReturnListDistinctOnThatValue() { - - val original = arrayOf( - SmallClass("key1", 1), - SmallClass("key2", 2), - SmallClass("key3", 3), - SmallClass("key4", 3), - SmallClass("er", 9), - SmallClass("er", 10), - SmallClass("er", 11)) - - val actual = original.distinctBy { it.key } - - val expected = listOf( - SmallClass("key1", 1), - SmallClass("key2", 2), - SmallClass("key3", 3), - SmallClass("key4", 3), - SmallClass("er", 9)) - - - assertIterableEquals(expected, actual) - } - - @Test - fun givenArrayOfClassObjects_whenApplyingComplicatedSelector_thenReturnFirstElementToMatchEachSelectorValue() { - val array = arrayOf( - SmallClass("key1", 1), - SmallClass("key2", 2), - SmallClass("key3", 3), - SmallClass("key4", 3), - SmallClass("er", 9), - SmallClass("er", 10), - SmallClass("er", 11), - SmallClass("er", 11), - SmallClass("er", 91), - SmallClass("blob", 22), - SmallClass("dob", 27), - SmallClass("high", 201_434_314)) - - val actual = array.distinctBy { Math.floor(it.num / 10.0) } - - val expected = listOf( - SmallClass("key1", 1), - SmallClass("er", 10), - SmallClass("er", 91), - SmallClass("blob", 22), - SmallClass("high", 201_434_314)) - - assertIterableEquals(expected, actual) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt deleted file mode 100644 index 7c2685f39b..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.filter - -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Test - -internal class DropTest { - - @Test - fun whenDroppingFirstTwoItemsOfArray_thenTwoLess() { - val array = arrayOf(1, 2, 3, 4) - val result = array.drop(2) - val expected = listOf(3, 4) - - assertIterableEquals(expected, result) - } - - @Test - fun whenDroppingMoreItemsOfArray_thenEmptyList() { - val array = arrayOf(1, 2, 3, 4) - val result = array.drop(5) - val expected = listOf() - - assertIterableEquals(expected, result) - } - - @Test - fun givenArray_whenDroppingLastElement_thenReturnListWithoutLastElement() { - val array = arrayOf("1", "2", "3", "4") - val result = array.dropLast(1) - val expected = listOf("1", "2", "3") - - assertIterableEquals(expected, result) - } - - @Test - fun givenArrayOfFloats_whenDroppingLastUntilPredicateIsFalse_thenReturnSubsetListOfFloats() { - val array = arrayOf(1f, 1f, 1f, 1f, 1f, 2f, 1f, 1f, 1f) - val result = array.dropLastWhile { it == 1f } - val expected = listOf(1f, 1f, 1f, 1f, 1f, 2f) - - assertIterableEquals(expected, result) - } - - @Test - fun givenList_whenDroppingMoreThanAvailable_thenThrowException() { - val list = listOf('a', 'e', 'i', 'o', 'u') - val result = list.drop(6) - val expected: List = listOf() - - assertIterableEquals(expected, result) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt deleted file mode 100644 index efe6354f25..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.filter - -import org.apache.commons.math3.primes.Primes -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Test -import kotlin.test.assertTrue - -internal class FilterTest { - - @Test - fun givenAscendingValueMap_whenFilteringOnValue_ThenReturnSubsetOfMap() { - val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3) - val filteredMap = originalMap.filter { it.value < 2 } - val expectedMap = mapOf("key1" to 1) - - assertTrue { expectedMap == filteredMap } - } - - @Test - fun givenSeveralCollections_whenFilteringToAccumulativeList_thenListContainsAllContents() { - val array1 = arrayOf(90, 92, 93, 94, 92, 95, 93) - val array2 = sequenceOf(51, 31, 83, 674_506_111, 256_203_161, 15_485_863) - val list1 = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - val primes = mutableListOf() - - val expected = listOf(2, 3, 5, 7, 31, 83, 15_485_863, 256_203_161, 674_506_111) - - val primeCheck = { num: Int -> Primes.isPrime(num) } - - array1.filterTo(primes, primeCheck) - list1.filterTo(primes, primeCheck) - array2.filterTo(primes, primeCheck) - - primes.sort() - - assertIterableEquals(expected, primes) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt deleted file mode 100644 index 793fe68427..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.filter - -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Assertions.assertThrows -import org.junit.jupiter.api.Test - -internal class SliceTest { - - @Test - fun whenSlicingAnArrayWithDotRange_ThenListEqualsTheSlice() { - val original = arrayOf(1, 2, 3, 2, 1) - val actual = original.slice(1..3) - val expected = listOf(2, 3, 2) - - assertIterableEquals(expected, actual) - } - - @Test - fun whenSlicingAnArrayWithDownToRange_thenListMadeUpOfReverseSlice() { - val original = arrayOf(1, 2, 3, 2, 1) - val actual = original.slice(3 downTo 0) - val expected = listOf(2, 3, 2, 1) - - assertIterableEquals(expected, actual) - } - -// From the 1.3 version of Kotlin APIs, slice doesn't return array of nulls but throw IndexOutOfBoundsException -// @Test -// fun whenSlicingBeyondTheRangeOfTheArray_thenContainManyNulls() { -// val original = arrayOf(12, 3, 34, 4) -// val actual = original.slice(3..8) -// val expected = listOf(4, null, null, null, null, null) -// -// assertIterableEquals(expected, actual) -// } - - @Test - fun whenSlicingBeyondRangeOfArrayWithStep_thenOutOfBoundsException() { - assertThrows(ArrayIndexOutOfBoundsException::class.java) { - val original = arrayOf(12, 3, 34, 4) - original.slice(3..8 step 2) - } - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt deleted file mode 100644 index d021177de8..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.filter - -import org.junit.jupiter.api.Assertions.assertIterableEquals -import org.junit.jupiter.api.Test - -internal class TakeTest { - - @Test - fun `given array of alternating types, when predicating on 'is String', then produce list of array up until predicate is false`() { - val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) - val actualList = originalArray.takeWhile { it is String } - val expectedList = listOf("val1") - - assertIterableEquals(expectedList, actualList) - } - - @Test - fun `given array of alternating types, when taking 4 items, then produce list of first 4 items`() { - val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) - val actualList = originalArray.take(4) - val expectedList = listOf("val1", 2, "val3", 4) - - println(originalArray.drop(4)) - println(actualList) - - assertIterableEquals(expectedList, actualList) - } - - @Test - fun `when taking more items than available, then return all elements`() { - val originalArray = arrayOf(1, 2) - val actual = originalArray.take(10) - val expected = listOf(1, 2) - - assertIterableEquals(expected, actual) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt deleted file mode 100644 index 52e7e2a5b5..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.findelement - -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class FindAnElementInAListUnitTest { - - var batmans: List = listOf("Christian Bale", "Michael Keaton", "Ben Affleck", "George Clooney") - - @Test - fun whenFindASpecificItem_thenItemIsReturned() { - //Returns the first element matching the given predicate, or null if no such element was found. - val theFirstBatman = batmans.find { actor -> "Michael Keaton".equals(actor) } - assertEquals(theFirstBatman, "Michael Keaton") - } - - @Test - fun whenFilterWithPredicate_thenMatchingItemsAreReturned() { - //Returns a list containing only elements matching the given predicate. - val theCoolestBatmans = batmans.filter { actor -> actor.contains("a") } - assertTrue(theCoolestBatmans.contains("Christian Bale") && theCoolestBatmans.contains("Michael Keaton")) - } - - @Test - fun whenFilterNotWithPredicate_thenMatchingItemsAreReturned() { - //Returns a list containing only elements not matching the given predicate. - val theMehBatmans = batmans.filterNot { actor -> actor.contains("a") } - assertFalse(theMehBatmans.contains("Christian Bale") && theMehBatmans.contains("Michael Keaton")) - assertTrue(theMehBatmans.contains("Ben Affleck") && theMehBatmans.contains("George Clooney")) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt deleted file mode 100644 index 7b263914c6..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.foldvsreduce - -import org.junit.Test -import org.junit.jupiter.api.assertThrows -import java.lang.RuntimeException -import kotlin.test.assertEquals - -class FoldAndReduceTest { - - @Test - fun testReduceLimitations() { - val numbers: List = listOf(1, 2, 3) - val sum: Number = numbers.reduce { acc, next -> acc + next } - assertEquals(6, sum) - - val emptyList = listOf() - assertThrows { emptyList.reduce { acc, next -> acc + next } } - - // doesn't compile - // val sum = numbers.reduce { acc, next -> acc.toLong() + next.toLong()} - } - - @Test - fun testFold() { - - val numbers: List = listOf(1, 2, 3) - val sum: Int = numbers.fold(0, { acc, next -> acc + next }) - assertEquals(6, sum) - - //change result type - val sumLong: Long = numbers.fold(0L, { acc, next -> acc + next.toLong() }) - assertEquals(6L, sumLong) - - val emptyList = listOf() - val emptySum = emptyList.fold(0, { acc, next -> acc + next }) - assertEquals(0, emptySum) - - //power of changing result type - val (even, odd) = numbers.fold(Pair(listOf(), listOf()), { acc, next -> - if (next % 2 == 0) Pair(acc.first + next, acc.second) - else Pair(acc.first, acc.second + next) - }) - - assertEquals(listOf(2), even) - assertEquals(listOf(1, 3), odd) - } - - @Test - fun testVariationsOfFold() { - val numbers = listOf(1, 2, 3) - val reversed = numbers.foldRight(listOf(), { next, acc -> acc + next}) - assertEquals(listOf(3,2,1), reversed) - - val reversedIndexes = numbers.foldRightIndexed(listOf(), { i, _, acc -> acc + i }) - assertEquals(listOf(2,1,0), reversedIndexes) - } - - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt deleted file mode 100644 index 71fe3bf1e0..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt +++ /dev/null @@ -1,126 +0,0 @@ -package com.baeldung.kotlin.collections - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class ListExampleUnitTest { - - private val classUnderTest: ListExample = ListExample() - - @Test - fun whenListIsCreated_thenContainsElements() { - assertTrue(classUnderTest.createList().contains("India")) - assertTrue(classUnderTest.createMutableList().contains("Seoul")) - } - - @Test - fun whenIterateUsingForEachLoop_thenSuccess() { - assertEquals(7, classUnderTest.iterateUsingForEachLoop()[0]) - } - - @Test - fun whenIterateUsingForLoop_thenSuccess() { - assertEquals(5, classUnderTest.iterateUsingForLoop()[1]) - } - - @Test - fun whenIterateUsingForLoopRange_thenSuccess() { - assertEquals(6, classUnderTest.iterateUsingForLoopRange()[3]) - } - - @Test - fun whenIterateUsingForEachIndexedLoop_thenSuccess() { - assertEquals(9, classUnderTest.iterateUsingForEachIndexedLoop()[4]) - } - - @Test - fun whenRetrieveElementsInList_thenSuccess() { - assertEquals("Japan", classUnderTest.retrieveElementsInList()) - } - - @Test - fun whenRetrieveElementsUsingGet_thenSuccess() { - assertEquals("Brazil", classUnderTest.retrieveElementsUsingGet()) - } - - @Test - fun whenRetrieveElementsFirstAndLast_thenSuccess() { - assertEquals("Australia", classUnderTest.retrieveElementsFirstAndLast()) - } - - @Test - fun whenRetrieveSubList_thenSuccess() { - assertEquals(3, classUnderTest.retrieveSubList().size) - } - - @Test - fun whenRetrieveListSliceUsingIndices_thenSuccess() { - assertEquals(4, classUnderTest.retrieveListSliceUsingIndices().size) - } - - @Test - fun whenRetrieveListSliceUsingIndicesList_thenSuccess() { - assertEquals(2, classUnderTest.retrieveListSliceUsingIndicesList().size) - } - - @Test - fun whenCountList_thenSuccess() { - assertEquals(5, classUnderTest.countList()) - } - - @Test - fun whenCountListUsingPredicate_thenSuccess() { - assertEquals(3, classUnderTest.countListUsingPredicate()) - } - - @Test - fun whenCountListUsingProperty_thenSuccess() { - assertEquals(5, classUnderTest.countListUsingProperty()) - } - - @Test - fun whenAddToList_thenSuccess() { - assertEquals(11, classUnderTest.addToList().count()) - } - - @Test - fun whenRemoveFromList_thenSuccess() { - val list = classUnderTest.removeFromList() - assertEquals(3, list.size) - assertEquals("Sao Paulo", list[1]) - } - - @Test - fun whenReplaceFromList_thenSuccess() { - val list = classUnderTest.replaceFromList() - assertEquals(5, list.size) - assertEquals("Barcelona", list[1]) - } - - @Test - fun whenSortMutableList_thenSuccess() { - assertEquals("Sydney", classUnderTest.sortMutableList()[0]) - } - - @Test - fun whenSortList_thenSuccess() { - assertEquals("India", classUnderTest.sortList()[1]) - } - - @Test - fun whenCheckOneElementInList_thenSuccess() { - assertTrue(classUnderTest.checkOneElementInList()) - } - - @Test - fun whenCheckOneElementInListUsingOperator_thenSuccess() { - assertFalse(classUnderTest.checkOneElementInListUsingOperator()) - } - - @Test - fun whenCheckElementsInList_thenSuccess() { - assertTrue(classUnderTest.checkElementsInList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt deleted file mode 100644 index 93e4f11fdf..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.listtomap - -import org.junit.Test -import kotlin.test.assertTrue - -class ListToMapTest { - - val user1 = User("John", 18, listOf("Hiking, Swimming")) - val user2 = User("Sara", 25, listOf("Chess, Board Games")) - val user3 = User("Dave", 34, listOf("Games, Racing sports")) - val user4 = User("John", 30, listOf("Reading, Poker")) - - @Test - fun givenList_whenConvertToMap_thenResult() { - val myList = listOf(user1, user2, user3) - val myMap = myList.map { it.name to it.age }.toMap() - - assertTrue(myMap.get("John") == 18) - } - - @Test - fun givenList_whenAssociatedBy_thenResult() { - val myList = listOf(user1, user2, user3) - val myMap = myList.associateBy({ it.name }, { it.hobbies }) - - assertTrue(myMap.get("John")!!.contains("Hiking, Swimming")) - } - - @Test - fun givenStringList_whenConvertToMap_thenResult() { - val myList = listOf("a", "b", "c") - val myMap = myList.map { it to it }.toMap() - - assertTrue(myMap.get("a") == "a") - } - - @Test - fun givenStringList_whenAssociate_thenResult() { - val myList = listOf("a", "b", "c", "c", "b") - val myMap = myList.associate{ it to it } - - assertTrue(myMap.get("a") == "a") - } - - @Test - fun givenStringList_whenAssociateTo_thenResult() { - val myList = listOf("a", "b", "c", "c", "b") - val myMap = mutableMapOf() - - myList.associateTo(myMap) {it to it} - - assertTrue(myMap.get("a") == "a") - } - - @Test - fun givenStringList_whenAssociateByTo_thenResult() { - val myList = listOf(user1, user2, user3, user4) - val myMap = mutableMapOf() - - myList.associateByTo(myMap, {it.name}, {it.age}) - - assertTrue(myMap.get("Dave") == 34) - } - - @Test - fun givenStringList_whenAssociateByToUser_thenResult() { - val myList = listOf(user1, user2, user3, user4) - val myMap = mutableMapOf() - - myList.associateByTo(myMap) {it.name} - - assertTrue(myMap.get("Dave")!!.age == 34) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt deleted file mode 100644 index 89eb9ac701..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.listtomap - -data class User(val name: String, val age: Int, val hobbies: List) diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt deleted file mode 100644 index 7ac0efa4ef..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.sorting - -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test - -class SortingExampleKtTest { - - @Test - fun naturalOrderComparator_ShouldBeAscendingTest() { - val resultingList = listOf(1, 5, 6, 6, 2, 3, 4).sortedWith(getSimpleComparator()) - assertTrue(listOf(1, 2, 3, 4, 5, 6, 6) == resultingList) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt deleted file mode 100644 index 627c7eaacf..0000000000 --- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.baeldung.splitlist - -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class SplitListIntoPartsTest { - private val evenList = listOf(0, "a", 1, "b", 2, "c"); - - private val unevenList = listOf(0, "a", 1, "b", 2, "c", 3); - - private fun verifyList(resultList: List>) { - assertEquals("[[0, a], [1, b], [2, c]]", resultList.toString()) - } - - private fun verifyPartialList(resultList: List>) { - assertEquals("[[0, a], [1, b], [2, c], [3]]", resultList.toString()) - } - - @Test - fun whenChunked_thenListIsSplit() { - val resultList = evenList.chunked(2) - verifyList(resultList) - } - - @Test - fun whenUnevenChunked_thenListIsSplit() { - val resultList = unevenList.chunked(2) - verifyPartialList(resultList) - } - - @Test - fun whenWindowed_thenListIsSplit() { - val resultList = evenList.windowed(2, 2) - verifyList(resultList) - } - - @Test - fun whenUnevenPartialWindowed_thenListIsSplit() { - val resultList = unevenList.windowed(2, 2, partialWindows = true) - verifyPartialList(resultList) - } - - @Test - fun whenUnevenWindowed_thenListIsSplit() { - val resultList = unevenList.windowed(2, 2, partialWindows = false) - verifyList(resultList) - } - - @Test - fun whenGroupByWithAscendingNumbers_thenListIsSplit() { - val numberList = listOf(1, 2, 3, 4, 5, 6); - val resultList = numberList.groupBy { (it + 1) / 2 } - assertEquals("[[1, 2], [3, 4], [5, 6]]", resultList.values.toString()) - assertEquals("[1, 2, 3]", resultList.keys.toString()) - } - - @Test - fun whenGroupByWithAscendingNumbersUneven_thenListIsSplit() { - val numberList = listOf(1, 2, 3, 4, 5, 6, 7); - val resultList = numberList.groupBy { (it + 1) / 2 }.values - assertEquals("[[1, 2], [3, 4], [5, 6], [7]]", resultList.toString()) - } - - @Test - fun whenGroupByWithRandomNumbers_thenListIsSplitInWrongWay() { - val numberList = listOf(1, 3, 8, 20, 23, 30); - val resultList = numberList.groupBy { (it + 1) / 2 } - assertEquals("[[1], [3], [8], [20], [23], [30]]", resultList.values.toString()) - assertEquals("[1, 2, 4, 10, 12, 15]", resultList.keys.toString()) - } - - @Test - fun whenWithIndexGroupBy_thenListIsSplit() { - val resultList = evenList.withIndex() - .groupBy { it.index / 2 } - .map { it.value.map { it.value } } - verifyList(resultList) - } - - @Test - fun whenWithIndexGroupByUneven_thenListIsSplit() { - val resultList = unevenList.withIndex() - .groupBy { it.index / 2 } - .map { it.value.map { it.value } } - verifyPartialList(resultList) - } - - @Test - fun whenFoldIndexed_thenListIsSplit() { - val resultList = evenList.foldIndexed(ArrayList>(evenList.size / 2)) { index, acc, item -> - if (index % 2 == 0) { - acc.add(ArrayList(2)) - } - acc.last().add(item) - acc - } - verifyList(resultList) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/README.md b/core-kotlin-modules/core-kotlin-concurrency/README.md deleted file mode 100644 index 22619b156f..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Core Kotlin Concurrency - -This module contains articles about concurrency in Kotlin. - -### Relevant articles: -- [Threads vs Coroutines in Kotlin](https://www.baeldung.com/kotlin-threads-coroutines) -- [Introduction to Kotlin Coroutines](https://www.baeldung.com/kotlin-coroutines) -- [Introduction to Channels in Kotlin](https://www.baeldung.com/kotlin/channels) diff --git a/core-kotlin-modules/core-kotlin-concurrency/pom.xml b/core-kotlin-modules/core-kotlin-concurrency/pom.xml deleted file mode 100644 index 7c3b0fb5b6..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - core-kotlin-concurrency - core-kotlin-concurrency - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 1.3.30 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt deleted file mode 100644 index 5fefc2f95e..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/BufferedChannel.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.cancelChildren -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking - -fun main() = runBlocking { - val basket = Channel(1) - - launch { // coroutine1 - val fruits = listOf("Apple", "Orange", "Banana") - for (fruit in fruits) { - println("coroutine1: Sending $fruit") - basket.send(fruit) - } - } - - launch { // coroutine2 - repeat(3) { - delay(100) - println("coroutine2: Received ${basket.receive()}") - } - } - - delay(2000) - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt deleted file mode 100644 index 6225eeb107..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ConflatedChannel.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.cancelChildren -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.Channel.Factory.CONFLATED -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking - -fun main() = runBlocking { - val basket = Channel(CONFLATED) - - launch { // coroutine1 - val fruits = listOf("Apple", "Orange", "Banana") - for (fruit in fruits) { - println("coroutine1: Sending $fruit") - basket.send(fruit) - } - } - - launch { // coroutine2 - println("coroutine2: Received ${basket.receive()}") - } - - delay(2000) - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt deleted file mode 100644 index abc8be4d18..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/PizzaPipeline.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.channels - -import com.baeldung.channels.OrderStatus.* -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.produce - -enum class OrderStatus { ORDERED, BAKED, TOPPED, SERVED } - -data class PizzaOrder(val orderNumber: Int, val orderStatus: OrderStatus = ORDERED) - -@ExperimentalCoroutinesApi -fun CoroutineScope.baking(orders: ReceiveChannel) = produce { - for (order in orders) { - delay(200) - println("Baking ${order.orderNumber}") - send(order.copy(orderStatus = BAKED)) - } -} - -@ExperimentalCoroutinesApi -fun CoroutineScope.topping(orders: ReceiveChannel) = produce { - for (order in orders) { - delay(50) - println("Topping ${order.orderNumber}") - send(order.copy(orderStatus = TOPPED)) - } -} - -@ExperimentalCoroutinesApi -fun CoroutineScope.produceOrders(count: Int) = produce { - repeat(count) { - delay(50) - send(PizzaOrder(orderNumber = it + 1)) - } -} - -@ObsoleteCoroutinesApi -@ExperimentalCoroutinesApi -fun main() = runBlocking { - val orders = produceOrders(3) - - val readyOrders = topping(baking(orders)) - - for (order in readyOrders) { - println("Serving ${order.orderNumber}") - } - - delay(3000) - println("End!") - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt deleted file mode 100644 index 37f3c7d7bb..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/ProducerConsumer.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.produce -import kotlinx.coroutines.runBlocking - -@ExperimentalCoroutinesApi -fun CoroutineScope.produceFruits(): ReceiveChannel = produce { - val fruits = listOf("Apple", "Orange", "Apple") - for (fruit in fruits) send(fruit) -} - -@ExperimentalCoroutinesApi -fun main() = runBlocking { - val fruitChannel = produceFruits() - for (fruit in fruitChannel) { - println(fruit) - } - println("End!") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt deleted file mode 100644 index d4b554bced..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/RendezvousChannel.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.Channel - -fun main() = runBlocking { - val basket = Channel() - - launch { // coroutine1 - val fruits = listOf("Apple", "Orange", "Banana") - for (fruit in fruits) { - println("coroutine1: Sending $fruit") - basket.send(fruit) - } - } - - launch { // coroutine2 - repeat(3) { - delay(100) - println("coroutine2: Received ${basket.receive()}") - } - } - - delay(2000) - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt deleted file mode 100644 index 5ed95debe8..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SeveralProducersOneConsumer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.cancelChildren -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.SendChannel -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking - -suspend fun fetchYoutubeVideos(channel: SendChannel) { - val videos = listOf("cat video", "food video") - for (video in videos) { - delay(100) - channel.send(video) - } -} - -suspend fun fetchTweets(channel: SendChannel) { - val tweets = listOf("tweet: Earth is round", "tweet: Coroutines and channels are cool") - for (tweet in tweets) { - delay(100) - channel.send(tweet) - } -} - -fun main() = runBlocking { - val aggregate = Channel() - launch { fetchYoutubeVideos(aggregate) } - launch { fetchTweets(aggregate) } - - repeat(4) { - println(aggregate.receive()) - } - - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt deleted file mode 100644 index f8f7b4b23b..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/SingleProducerSeveralConsumers.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.produce - -@ExperimentalCoroutinesApi -fun CoroutineScope.producePizzaOrders(): ReceiveChannel = produce { - var x = 1 - while (true) { - send("Pizza Order No. ${x++}") - delay(100) - } -} - -fun CoroutineScope.pizzaOrderProcessor(id: Int, orders: ReceiveChannel) = launch { - for (order in orders) { - println("Processor #$id is processing $order") - } -} - -@ExperimentalCoroutinesApi -fun main() = runBlocking { - val pizzaOrders = producePizzaOrders() - repeat(3) { - pizzaOrderProcessor(it + 1, pizzaOrders) - } - - delay(1000) - pizzaOrders.cancel() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt deleted file mode 100644 index 85c0dc8d04..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/TickerChannel.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.channels.ticker -import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking -import java.time.Duration -import kotlin.random.Random - -fun stockPrice(stock: String): Double { - log("Fetching stock price of $stock") - return Random.nextDouble(2.0, 3.0) -} - -fun main() = runBlocking { - val tickerChannel = ticker(Duration.ofSeconds(5).toMillis()) - - repeat(3) { - tickerChannel.receive() - log(stockPrice("TESLA")) - } - - delay(Duration.ofSeconds(11).toMillis()) - tickerChannel.cancel() -} diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt deleted file mode 100644 index e4725ca903..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/UnlimitedChannel.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.cancelChildren -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking - -fun main() = runBlocking { - val channel = Channel(UNLIMITED) - - launch { // coroutine1 - repeat(100) { - println("coroutine1: Sending $it") - channel.send(it) - } - } - - launch { // coroutine2 - repeat(100) { - println("coroutine2: Received ${channel.receive()}") - } - } - - delay(2000) - coroutineContext.cancelChildren() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt deleted file mode 100644 index 036a6a4504..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/channels/logger.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.channels - -import java.text.SimpleDateFormat -import java.util.* - -fun log(value: Any) { - println(SimpleDateFormat("HH:MM:ss").format(Date()) + " - $value") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt deleted file mode 100644 index 80ffb4077a..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.threadsvscoroutines - -class SimpleRunnable: Runnable { - - override fun run() { - println("${Thread.currentThread()} has run.") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt deleted file mode 100644 index 6647dac0ef..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.threadsvscoroutines - -class SimpleThread: Thread() { - - override fun run() { - println("${Thread.currentThread()} has run.") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt deleted file mode 100644 index 245282dafc..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/channels/ChannelsTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.channels - -import kotlinx.coroutines.async -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -class ChannelsTest { - @Test - fun should_pass_data_from_one_coroutine_to_another() { - runBlocking { - // given - val channel = Channel() - - // when - launch { // coroutine1 - channel.send("Hello World!") - } - val result = async { // coroutine 2 - channel.receive() - } - - // then - assertThat(result.await()).isEqualTo("Hello World!") - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt deleted file mode 100644 index 6b9437a8ab..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt +++ /dev/null @@ -1,178 +0,0 @@ -package com.baeldung.coroutines - -import kotlinx.coroutines.* -import org.junit.Test -import java.util.concurrent.atomic.AtomicInteger -import kotlin.system.measureTimeMillis -import kotlin.test.assertEquals -import kotlin.test.assertTrue - - -class CoroutinesTest { - - @Test - fun givenBuildSequence_whenTakeNElements_thenShouldReturnItInALazyWay() { - //given - val fibonacciSeq = sequence { - var a = 0 - var b = 1 - - yield(1) - - while (true) { - yield(a + b) - - val tmp = a + b - a = b - b = tmp - } - } - - //when - val res = fibonacciSeq.take(5).toList() - - //then - assertEquals(res, listOf(1, 1, 2, 3, 5)) - } - - @Test - fun givenLazySeq_whenTakeNElements_thenShouldReturnAllElements() { - //given - val lazySeq = sequence { - print("START ") - for (i in 1..5) { - yield(i) - print("STEP ") - } - print("END") - } - //when - val res = lazySeq.take(10).toList() - - //then - assertEquals(res, listOf(1, 2, 3, 4, 5)) - } - - @Test - fun givenAsyncCoroutine_whenStartIt_thenShouldExecuteItInTheAsyncWay() { - //given - val res = mutableListOf() - - //when - runBlocking { - val promise = launch(Dispatchers.Default) { expensiveComputation(res) } - res.add("Hello,") - promise.join() - } - - //then - assertEquals(res, listOf("Hello,", "word!")) - } - - - suspend fun expensiveComputation(res: MutableList) { - delay(1000L) - res.add("word!") - } - - @Test - fun givenHugeAmountOfCoroutines_whenStartIt_thenShouldExecuteItWithoutOutOfMemory() { - runBlocking { - //given - val counter = AtomicInteger(0) - val numberOfCoroutines = 100_000 - - //when - val jobs = List(numberOfCoroutines) { - launch(Dispatchers.Default) { - delay(1L) - counter.incrementAndGet() - } - } - jobs.forEach { it.join() } - - //then - assertEquals(counter.get(), numberOfCoroutines) - } - } - - @Test - fun givenCancellableJob_whenRequestForCancel_thenShouldQuit() { - runBlocking { - //given - val job = launch(Dispatchers.Default) { - while (isActive) { - //println("is working") - } - } - - delay(1300L) - - //when - job.cancel() - - //then cancel successfully - - } - } - - @Test(expected = CancellationException::class) - fun givenAsyncAction_whenDeclareTimeout_thenShouldFinishWhenTimedOut() { - runBlocking { - withTimeout(1300L) { - repeat(1000) { i -> - println("Some expensive computation $i ...") - delay(500L) - } - } - } - } - - @Test - fun givenHaveTwoExpensiveAction_whenExecuteThemAsync_thenTheyShouldRunConcurrently() { - runBlocking { - val delay = 1000L - val time = measureTimeMillis { - //given - val one = async(Dispatchers.Default) { someExpensiveComputation(delay) } - val two = async(Dispatchers.Default) { someExpensiveComputation(delay) } - - //when - runBlocking { - one.await() - two.await() - } - } - - //then - assertTrue(time < delay * 2) - } - } - - @Test - fun givenTwoExpensiveAction_whenExecuteThemLazy_thenTheyShouldNotConcurrently() { - runBlocking { - val delay = 1000L - val time = measureTimeMillis { - //given - val one = async(Dispatchers.Default, CoroutineStart.LAZY) { someExpensiveComputation(delay) } - val two = async(Dispatchers.Default, CoroutineStart.LAZY) { someExpensiveComputation(delay) } - - //when - runBlocking { - one.await() - two.await() - } - } - - //then - assertTrue(time > delay * 2) - } - } - - suspend fun someExpensiveComputation(delayInMilliseconds: Long) { - delay(delayInMilliseconds) - } - - -} diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt deleted file mode 100644 index ff385d0869..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.threadsvscoroutines - -import kotlinx.coroutines.* -import org.junit.jupiter.api.Test - -class CoroutineUnitTest { - - @Test - fun whenCreateCoroutineWithLaunchWithoutContext_thenRun() = runBlocking { - - val job = launch { - println("${Thread.currentThread()} has run.") - } - - } - - @Test - fun whenCreateCoroutineWithLaunchWithDefaultContext_thenRun() = runBlocking { - - val job = launch(Dispatchers.Default) { - println("${Thread.currentThread()} has run.") - } - } - - @Test - fun whenCreateCoroutineWithLaunchWithUnconfinedContext_thenRun() = runBlocking { - - val job = launch(Dispatchers.Unconfined) { - println("${Thread.currentThread()} has run.") - } - } - - @Test - fun whenCreateCoroutineWithLaunchWithDedicatedThread_thenRun() = runBlocking { - - val job = launch(newSingleThreadContext("dedicatedThread")) { - println("${Thread.currentThread()} has run.") - } - - } - - @Test - fun whenCreateAsyncCoroutine_thenRun() = runBlocking { - - val deferred = async(Dispatchers.IO) { - return@async "${Thread.currentThread()} has run." - } - - val result = deferred.await() - println(result) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt deleted file mode 100644 index 9503751fa3..0000000000 --- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.threadsvscoroutines - -import org.junit.jupiter.api.Test -import kotlin.concurrent.thread - -class ThreadUnitTest { - - @Test - fun whenCreateThread_thenRun() { - - val thread = SimpleThread() - thread.start() - } - - @Test - fun whenCreateThreadWithRunnable_thenRun() { - - val threadWithRunnable = Thread(SimpleRunnable()) - threadWithRunnable.start() - } - - @Test - fun whenCreateThreadWithSAMConversions_thenRun() { - - val thread = Thread { - println("${Thread.currentThread()} has run.") - } - thread.start() - } - - @Test - fun whenCreateThreadWithMethodExtension_thenRun() { - - thread(start = true) { - println("${Thread.currentThread()} has run.") - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-datastructures/README.md b/core-kotlin-modules/core-kotlin-datastructures/README.md deleted file mode 100644 index 3b22730a76..0000000000 --- a/core-kotlin-modules/core-kotlin-datastructures/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Core Kotlin - -This module contains articles about data structures in Kotlin - -### Relevant articles: -[Implementing a Binary Tree in Kotlin](https://www.baeldung.com/kotlin-binary-tree) diff --git a/core-kotlin-modules/core-kotlin-datastructures/pom.xml b/core-kotlin-modules/core-kotlin-datastructures/pom.xml deleted file mode 100644 index eae11c17cf..0000000000 --- a/core-kotlin-modules/core-kotlin-datastructures/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - core-kotlin-datastructures - core-kotlin-datastructures - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - - - 1.1.1 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt deleted file mode 100644 index eee10fbd8b..0000000000 --- a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.binarytree - -/** - * Example of how to use the {@link Node} class. - * - */ -fun main(args: Array) { - val tree = Node(4) - val keys = arrayOf(8, 15, 21, 3, 7, 2, 5, 10, 2, 3, 4, 6, 11) - for (key in keys) { - tree.insert(key) - } - val node = tree.find(4)!! - println("Node with value ${node.key} [left = ${node.left?.key}, right = ${node.right?.key}]") - println("Delete node with key = 3") - node.delete(3) - print("Tree content after the node elimination: ") - println(tree.visit().joinToString { it.toString() }) -} diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt deleted file mode 100644 index 77bb98f828..0000000000 --- a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt +++ /dev/null @@ -1,167 +0,0 @@ -package com.baeldung.binarytree - -/** - * An ADT for a binary search tree. - * Note that this data type is neither immutable nor thread safe. - */ -class Node( - var key: Int, - var left: Node? = null, - var right: Node? = null) { - - /** - * Return a node with given value. If no such node exists, return null. - * @param value - */ - fun find(value: Int): Node? = when { - this.key > value -> left?.find(value) - this.key < value -> right?.find(value) - else -> this - - } - - /** - * Insert a given value into the tree. - * After insertion, the tree should contain a node with the given value. - * If the tree already contains the given value, nothing is performed. - * @param value - */ - fun insert(value: Int) { - if (value > this.key) { - if (this.right == null) { - this.right = Node(value) - } else { - this.right?.insert(value) - } - } else if (value < this.key) { - if (this.left == null) { - this.left = Node(value) - } else { - this.left?.insert(value) - } - } - } - - /** - * Delete the value from the given tree. If the tree does not contain the value, the tree remains unchanged. - * @param value - */ - fun delete(value: Int) { - when { - value > key -> scan(value, this.right, this) - value < key -> scan(value, this.left, this) - else -> removeNode(this, null) - } - } - - /** - * Scan the tree in the search of the given value. - * @param value - * @param node sub-tree that potentially might contain the sought value - * @param parent node's parent - */ - private fun scan(value: Int, node: Node?, parent: Node?) { - if (node == null) { - System.out.println("value " + value - + " seems not present in the tree.") - return - } - when { - value > node.key -> scan(value, node.right, node) - value < node.key -> scan(value, node.left, node) - value == node.key -> removeNode(node, parent) - } - - } - - /** - * Remove the node. - * - * Removal process depends on how many children the node has. - * - * @param node node that is to be removed - * @param parent parent of the node to be removed - */ - private fun removeNode(node: Node, parent: Node?) { - node.left?.let { leftChild -> - run { - node.right?.let { - removeTwoChildNode(node) - } ?: removeSingleChildNode(node, leftChild) - } - } ?: run { - node.right?.let { rightChild -> removeSingleChildNode(node, rightChild) } ?: removeNoChildNode(node, parent) - } - - - } - - /** - * Remove the node without children. - * @param node - * @param parent - */ - private fun removeNoChildNode(node: Node, parent: Node?) { - parent?.let { p -> - if (node == p.left) { - p.left = null - } else if (node == p.right) { - p.right = null - } - } ?: throw IllegalStateException( - "Can not remove the root node without child nodes") - - } - - /** - * Remove a node that has two children. - * - * The process of elimination is to find the biggest key in the left sub-tree and replace the key of the - * node that is to be deleted with that key. - */ - private fun removeTwoChildNode(node: Node) { - val leftChild = node.left!! - leftChild.right?.let { - val maxParent = findParentOfMaxChild(leftChild) - maxParent.right?.let { - node.key = it.key - maxParent.right = null - } ?: throw IllegalStateException("Node with max child must have the right child!") - - } ?: run { - node.key = leftChild.key - node.left = leftChild.left - } - - } - - /** - * Return a node whose right child contains the biggest value in the given sub-tree. - * Assume that the node n has a non-null right child. - * - * @param n - */ - private fun findParentOfMaxChild(n: Node): Node { - return n.right?.let { r -> r.right?.let { findParentOfMaxChild(r) } ?: n } - ?: throw IllegalArgumentException("Right child must be non-null") - - } - - /** - * Remove a parent that has only one child. - * Removal is effectively is just coping the data from the child parent to the parent parent. - * @param parent Node to be deleted. Assume that it has just one child - * @param child Assume it is a child of the parent - */ - private fun removeSingleChildNode(parent: Node, child: Node) { - parent.key = child.key - parent.left = child.left - parent.right = child.right - } - - fun visit(): Array { - val a = left?.visit() ?: emptyArray() - val b = right?.visit() ?: emptyArray() - return a + arrayOf(key) + b - } -} diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt b/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt deleted file mode 100644 index 5a7f7fc50f..0000000000 --- a/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt +++ /dev/null @@ -1,320 +0,0 @@ -package com.binarytree - -import org.junit.After -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNull -import org.junit.Before -import org.junit.Test - -class NodeTest { - - @Before - fun setUp() { - } - - @After - fun tearDown() { - } - - /** - * Test suit for finding the node by value - * Partition the tests as follows: - * 1. tree depth: 0, 1, > 1 - * 2. pivot depth location: not present, 0, 1, 2, > 2 - */ - - /** - * Find the node by value - * 1. tree depth: 0 - * 2. pivot depth location: not present - */ - @Test - fun givenDepthZero_whenPivotNotPresent_thenNull() { - val n = Node(1) - assertNull(n.find(2)) - } - - /** - * Find the node by value - * 1. tree depth: 0 - * 2. pivot depth location: 0 - */ - @Test - fun givenDepthZero_whenPivotDepthZero_thenReturnNodeItself() { - val n = Node(1) - assertEquals(n, n.find(1)) - } - - /** - * Find the node by value - * 1. tree depth: 1 - * 2. pivot depth location: not present - */ - @Test - fun givenDepthOne_whenPivotNotPresent_thenNull() { - val n = Node(1, Node(0)) - assertNull(n.find(2)) - } - - /** - * Find the node by value - * 1. tree depth: 1 - * 2. pivot depth location: not present - */ - @Test - fun givenDepthOne_whenPivotAtDepthOne_thenSuccess() { - val n = Node(1, Node(0)) - assertEquals(n.left, n.find(0) - ) - } - - @Test - fun givenDepthTwo_whenPivotAtDepth2_then_Success() { - val left = Node(1, Node(0), Node(2)) - val right = Node(5, Node(4), Node(6)) - val n = Node(3, left, right) - assertEquals(left.left, n.find(0)) - } - - - /** - * Test suit for inserting a value - * Partition the test as follows: - * 1. tree depth: 0, 1, 2, > 2 - * 2. depth to insert: 0, 1, > 1 - * 3. is duplicate: no, yes - * 4. sub-tree: left, right - */ - /** - * Test for inserting a value - * 1. tree depth: 0 - * 2. depth to insert: 1 - * 3. is duplicate: no - * 4. sub-tree: right - */ - @Test - fun givenTreeDepthZero_whenInsertNoDuplicateToRight_thenAddNode() { - val n = Node(1) - n.insert(2) - assertEquals(1, n.key) - with(n.right!!) { - assertEquals(2, key) - assertNull(left) - assertNull(right) - } - assertNull(n.left) - } - - /** - * Test for inserting a value - * 1. tree depth: 0 - * 2. depth to insert: 1 - * 3. is duplicate: no - * 4. sub-tree: right - */ - @Test - fun givenTreeDepthZero_whenInsertNoDuplicateToLeft_thenSuccess() { - val n = Node(1) - n.insert(0) - assertEquals(1, n.key) - with(n.left!!) { - assertEquals(0, key) - assertNull(left) - assertNull(right) - } - assertNull(n.right) - } - - /** - * Test for inserting a value - * 1. tree depth: 0 - * 2. depth to insert: 1 - * 3. is duplicate: yes - */ - @Test - fun givenTreeDepthZero_whenInsertDuplicate_thenSuccess() { - val n = Node(1) - n.insert(1) - assertEquals(1, n.key) - assertNull(n.right) - assertNull(n.left) - } - - - /** - * Test suit for inserting a value - * Partition the test as follows: - * 1. tree depth: 0, 1, 2, > 2 - * 2. depth to insert: 0, 1, > 1 - * 3. is duplicate: no, yes - * 4. sub-tree: left, right - */ - /** - * Test for inserting a value - * 1. tree depth: 1 - * 2. depth to insert: 1 - * 3. is duplicate: no - * 4. sub-tree: right - */ - @Test - fun givenTreeDepthOne_whenInsertNoDuplicateToRight_thenSuccess() { - val n = Node(10, Node(3)) - n.insert(15) - assertEquals(10, n.key) - with(n.right!!) { - assertEquals(15, key) - assertNull(left) - assertNull(right) - } - with(n.left!!) { - assertEquals(3, key) - assertNull(left) - assertNull(right) - } - } - - /** - * Test for inserting a value - * 1. tree depth: 1 - * 2. depth to insert: 1 - * 3. is duplicate: no - * 4. sub-tree: left - */ - @Test - fun givenTreeDepthOne_whenInsertNoDuplicateToLeft_thenAddNode() { - val n = Node(10, null, Node(15)) - n.insert(3) - assertEquals(10, n.key) - with(n.right!!) { - assertEquals(15, key) - assertNull(left) - assertNull(right) - } - with(n.left!!) { - assertEquals(3, key) - assertNull(left) - assertNull(right) - } - } - - /** - * Test for inserting a value - * 1. tree depth: 1 - * 2. depth to insert: 1 - * 3. is duplicate: yes - */ - @Test - fun givenTreeDepthOne_whenInsertDuplicate_thenNoChange() { - val n = Node(10, null, Node(15)) - n.insert(15) - assertEquals(10, n.key) - with(n.right!!) { - assertEquals(15, key) - assertNull(left) - assertNull(right) - } - assertNull(n.left) - } - - /** - * Test suit for removal - * Partition the input as follows: - * 1. tree depth: 0, 1, 2, > 2 - * 2. value to delete: absent, present - * 3. # child nodes: 0, 1, 2 - */ - /** - * Test for removal value - * 1. tree depth: 0 - * 2. value to delete: absent - */ - @Test - fun givenTreeDepthZero_whenValueAbsent_thenNoChange() { - val n = Node(1) - n.delete(0) - assertEquals(1, n.key) - assertNull(n.left) - assertNull(n.right) - } - - /** - * Test for removal - * 1. tree depth: 1 - * 2. value to delete: absent - */ - @Test - fun givenTreeDepthOne_whenValueAbsent_thenNoChange() { - val n = Node(1, Node(0), Node(2)) - n.delete(3) - assertEquals(1, n.key) - assertEquals(2, n.right!!.key) - with(n.left!!) { - assertEquals(0, key) - assertNull(left) - assertNull(right) - } - with(n.right!!) { - assertNull(left) - assertNull(right) - } - } - - /** - * Test suit for removal - * 1. tree depth: 1 - * 2. value to delete: present - * 3. # child nodes: 0 - */ - @Test - fun givenTreeDepthOne_whenNodeToDeleteHasNoChildren_thenChangeTree() { - val n = Node(1, Node(0)) - n.delete(0) - assertEquals(1, n.key) - assertNull(n.left) - assertNull(n.right) - } - - /** - * Test suit for removal - * 1. tree depth: 2 - * 2. value to delete: present - * 3. # child nodes: 1 - */ - @Test - fun givenTreeDepthTwo_whenNodeToDeleteHasOneChild_thenChangeTree() { - val n = Node(2, Node(0, null, Node(1)), Node(3)) - n.delete(0) - assertEquals(2, n.key) - with(n.right!!) { - assertEquals(3, key) - assertNull(left) - assertNull(right) - } - with(n.left!!) { - assertEquals(1, key) - assertNull(left) - assertNull(right) - } - } - - @Test - fun givenTreeDepthThree_whenNodeToDeleteHasTwoChildren_thenChangeTree() { - val l = Node(2, Node(1), Node(5, Node(4), Node(6))) - val r = Node(10, Node(9), Node(11)) - val n = Node(8, l, r) - n.delete(8) - assertEquals(6, n.key) - with(n.left!!) { - assertEquals(2, key) - assertEquals(1, left!!.key) - assertEquals(5, right!!.key) - assertEquals(4, right!!.left!!.key) - } - with(n.right!!) { - assertEquals(10, key) - assertEquals(9, left!!.key) - assertEquals(11, right!!.key) - } - } - -} diff --git a/core-kotlin-modules/core-kotlin-date-time/README.md b/core-kotlin-modules/core-kotlin-date-time/README.md deleted file mode 100644 index a3e358d4e3..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Core Kotlin Date and Time - -This module contains articles about Kotlin core date/time features. - -### Relevant articles: -[Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates) diff --git a/core-kotlin-modules/core-kotlin-date-time/pom.xml b/core-kotlin-modules/core-kotlin-date-time/pom.xml deleted file mode 100644 index f3cacefc19..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - core-kotlin-date-time - core-kotlin-date-time - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.assertj - assertj-core - ${org.assertj.core.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - - - 1.1.1 - 3.9.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt deleted file mode 100644 index 922c3a1988..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.Duration -import java.time.LocalTime - -class UseDuration { - - fun modifyDates(localTime: LocalTime, duration: Duration): LocalTime { - return localTime.plus(duration) - } - - fun getDifferenceBetweenDates(localTime1: LocalTime, localTime2: LocalTime): Duration { - return Duration.between(localTime1, localTime2) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt deleted file mode 100644 index 81d50a70b2..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.DayOfWeek -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.temporal.ChronoUnit -import java.time.temporal.TemporalAdjusters - -class UseLocalDate { - - fun getLocalDateUsingFactoryOfMethod(year: Int, month: Int, dayOfMonth: Int): LocalDate { - return LocalDate.of(year, month, dayOfMonth) - } - - fun getLocalDateUsingParseMethod(representation: String): LocalDate { - return LocalDate.parse(representation) - } - - fun getLocalDateFromClock(): LocalDate { - return LocalDate.now() - } - - fun getNextDay(localDate: LocalDate): LocalDate { - return localDate.plusDays(1) - } - - fun getPreviousDay(localDate: LocalDate): LocalDate { - return localDate.minus(1, ChronoUnit.DAYS) - } - - fun getDayOfWeek(localDate: LocalDate): DayOfWeek { - return localDate.dayOfWeek - } - - fun getFirstDayOfMonth(): LocalDate { - return LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()) - } - - fun getStartOfDay(localDate: LocalDate): LocalDateTime { - return localDate.atStartOfDay() - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt deleted file mode 100644 index 5d0eb6a911..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.LocalDateTime - -class UseLocalDateTime { - - fun getLocalDateTimeUsingParseMethod(representation: String): LocalDateTime { - return LocalDateTime.parse(representation) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt deleted file mode 100644 index 24402467e8..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.LocalTime -import java.time.temporal.ChronoUnit - -class UseLocalTime { - - fun getLocalTimeUsingFactoryOfMethod(hour: Int, min: Int, seconds: Int): LocalTime { - return LocalTime.of(hour, min, seconds) - } - - fun getLocalTimeUsingParseMethod(timeRepresentation: String): LocalTime { - return LocalTime.parse(timeRepresentation) - } - - fun getLocalTimeFromClock(): LocalTime { - return LocalTime.now() - } - - fun addAnHour(localTime: LocalTime): LocalTime { - return localTime.plus(1, ChronoUnit.HOURS) - } - - fun getHourFromLocalTime(localTime: LocalTime): Int { - return localTime.hour - } - - fun getLocalTimeWithMinuteSetToValue(localTime: LocalTime, minute: Int): LocalTime { - return localTime.withMinute(minute) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt deleted file mode 100644 index d15e02eb37..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.LocalDate -import java.time.Period - -class UsePeriod { - - fun modifyDates(localDate: LocalDate, period: Period): LocalDate { - return localDate.plus(period) - } - - fun getDifferenceBetweenDates(localDate1: LocalDate, localDate2: LocalDate): Period { - return Period.between(localDate1, localDate2) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt deleted file mode 100644 index e2f3a207c4..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.dates.datetime - -import java.time.LocalDateTime -import java.time.ZoneId -import java.time.ZonedDateTime - -class UseZonedDateTime { - - fun getZonedDateTime(localDateTime: LocalDateTime, zoneId: ZoneId): ZonedDateTime { - return ZonedDateTime.of(localDateTime, zoneId) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt deleted file mode 100644 index af5e08ea2d..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.kotlin.dates - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import java.time.LocalDate -import java.time.format.DateTimeFormatter - -class CreateDateUnitTest { - - @Test - fun givenString_whenDefaultFormat_thenCreated() { - - var date = LocalDate.parse("2018-12-31") - - assertThat(date).isEqualTo("2018-12-31") - } - - @Test - fun givenString_whenCustomFormat_thenCreated() { - - var formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy") - var date = LocalDate.parse("31-12-2018", formatter) - - assertThat(date).isEqualTo("2018-12-31") - } - - @Test - fun givenYMD_whenUsingOf_thenCreated() { - var date = LocalDate.of(2018, 12, 31) - - assertThat(date).isEqualTo("2018-12-31") - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt deleted file mode 100644 index d297f4b6c3..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.kotlin.dates - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import java.time.DayOfWeek -import java.time.LocalDate -import java.time.Month - -class ExtractDateUnitTest { - - @Test - fun givenDate_thenExtractedYMD() { - var date = LocalDate.parse("2018-12-31") - - assertThat(date.year).isEqualTo(2018) - assertThat(date.month).isEqualTo(Month.DECEMBER) - assertThat(date.dayOfMonth).isEqualTo(31) - } - - @Test - fun givenDate_thenExtractedEraDowDoy() { - var date = LocalDate.parse("2018-12-31") - - assertThat(date.era.toString()).isEqualTo("CE") - assertThat(date.dayOfWeek).isEqualTo(DayOfWeek.MONDAY) - assertThat(date.dayOfYear).isEqualTo(365) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt deleted file mode 100644 index f7ca414aee..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.kotlin.dates - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import java.time.LocalDate -import java.time.format.DateTimeFormatter - -class FormatDateUnitTest { - - @Test - fun givenDate_whenDefaultFormat_thenFormattedString() { - - var date = LocalDate.parse("2018-12-31") - - assertThat(date.toString()).isEqualTo("2018-12-31") - } - - @Test - fun givenDate_whenCustomFormat_thenFormattedString() { - - var date = LocalDate.parse("2018-12-31") - - var formatter = DateTimeFormatter.ofPattern("dd-MMMM-yyyy") - var formattedDate = date.format(formatter) - - assertThat(formattedDate).isEqualTo("31-December-2018") - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt deleted file mode 100644 index e8ca2971e8..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.kotlin.dates - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import java.time.LocalDate -import java.time.Period - -class PeriodDateUnitTest { - - @Test - fun givenYMD_thenCreatePeriod() { - var period = Period.of(1, 2, 3) - - assertThat(period.toString()).isEqualTo("P1Y2M3D") - } - - @Test - fun givenPeriod_whenAdd_thenModifiedDate() { - var period = Period.of(1, 2, 3) - - var date = LocalDate.of(2018, 6, 25) - var modifiedDate = date.plus(period) - - assertThat(modifiedDate).isEqualTo("2019-08-28") - } - - @Test - fun givenPeriod_whenSubtracted_thenModifiedDate() { - var period = Period.of(1, 2, 3) - - var date = LocalDate.of(2018, 6, 25) - var modifiedDate = date.minus(period) - - assertThat(modifiedDate).isEqualTo("2017-04-22") - } - - @Test - fun givenTwoDate_whenUsingBetween_thenDiffOfDates() { - - var date1 = LocalDate.parse("2018-06-25") - var date2 = LocalDate.parse("2018-12-25") - - var period = Period.between(date1, date2) - - assertThat(period.toString()).isEqualTo("P6M") - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt deleted file mode 100644 index f3615a527c..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.kotlin.datetime - -import com.baeldung.dates.datetime.UseLocalDateTime -import org.junit.Assert.assertEquals -import org.junit.Test -import java.time.LocalDate -import java.time.LocalTime -import java.time.Month - -class UseLocalDateTimeUnitTest { - - var useLocalDateTime = UseLocalDateTime() - - @Test - fun givenString_whenUsingParse_thenLocalDateTime() { - assertEquals(LocalDate.of(2016, Month.MAY, 10), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30") - .toLocalDate()) - assertEquals(LocalTime.of(6, 30), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30") - .toLocalTime()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt deleted file mode 100644 index e6353c9dab..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.kotlin.datetime - -import com.baeldung.dates.datetime.UseLocalDate -import org.junit.Assert -import org.junit.Test -import java.time.DayOfWeek -import java.time.LocalDate -import java.time.LocalDateTime - -class UseLocalDateUnitTest { - - var useLocalDate = UseLocalDate() - - @Test - fun givenValues_whenUsingFactoryOf_thenLocalDate() { - Assert.assertEquals("2016-05-10", useLocalDate.getLocalDateUsingFactoryOfMethod(2016, 5, 10) - .toString()) - } - - @Test - fun givenString_whenUsingParse_thenLocalDate() { - Assert.assertEquals("2016-05-10", useLocalDate.getLocalDateUsingParseMethod("2016-05-10") - .toString()) - } - - @Test - fun whenUsingClock_thenLocalDate() { - Assert.assertEquals(LocalDate.now(), useLocalDate.getLocalDateFromClock()) - } - - @Test - fun givenDate_whenUsingPlus_thenNextDay() { - Assert.assertEquals(LocalDate.now() - .plusDays(1), useLocalDate.getNextDay(LocalDate.now())) - } - - @Test - fun givenDate_whenUsingMinus_thenPreviousDay() { - Assert.assertEquals(LocalDate.now() - .minusDays(1), useLocalDate.getPreviousDay(LocalDate.now())) - } - - @Test - fun givenToday_whenUsingGetDayOfWeek_thenDayOfWeek() { - Assert.assertEquals(DayOfWeek.SUNDAY, useLocalDate.getDayOfWeek(LocalDate.parse("2016-05-22"))) - } - - @Test - fun givenToday_whenUsingWithTemporalAdjuster_thenFirstDayOfMonth() { - Assert.assertEquals(1, useLocalDate.getFirstDayOfMonth() - .dayOfMonth.toLong()) - } - - @Test - fun givenLocalDate_whenUsingAtStartOfDay_thenReturnMidnight() { - Assert.assertEquals(LocalDateTime.parse("2016-05-22T00:00:00"), useLocalDate.getStartOfDay(LocalDate.parse("2016-05-22"))) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt deleted file mode 100644 index 1afe03ca48..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.kotlin.datetime - -import com.baeldung.dates.datetime.UseLocalTime -import org.junit.Assert -import org.junit.Test -import java.time.LocalTime - -class UseLocalTimeUnitTest { - - internal var useLocalTime = UseLocalTime() - - @Test - fun givenValues_whenUsingFactoryOf_thenLocalTime() { - Assert.assertEquals("07:07:07", useLocalTime.getLocalTimeUsingFactoryOfMethod(7, 7, 7).toString()) - } - - @Test - fun givenString_whenUsingParse_thenLocalTime() { - Assert.assertEquals("06:30", useLocalTime.getLocalTimeUsingParseMethod("06:30").toString()) - } - - @Test - fun givenTime_whenAddHour_thenLocalTime() { - Assert.assertEquals("07:30", useLocalTime.addAnHour(LocalTime.of(6, 30)).toString()) - } - - @Test - fun getHourFromLocalTime() { - Assert.assertEquals(1, useLocalTime.getHourFromLocalTime(LocalTime.of(1, 1)).toLong()) - } - - @Test - fun getLocalTimeWithMinuteSetToValue() { - Assert.assertEquals(LocalTime.of(10, 20), useLocalTime.getLocalTimeWithMinuteSetToValue(LocalTime.of(10, 10), 20)) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt deleted file mode 100644 index 36e1e5533a..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.kotlin.datetime - -import com.baeldung.dates.datetime.UsePeriod -import org.junit.Assert -import org.junit.Test -import java.time.LocalDate -import java.time.Period - -class UsePeriodUnitTest { - - var usingPeriod = UsePeriod() - - @Test - fun givenPeriodAndLocalDate_thenCalculateModifiedDate() { - val period = Period.ofDays(1) - val localDate = LocalDate.parse("2007-05-10") - Assert.assertEquals(localDate.plusDays(1), usingPeriod.modifyDates(localDate, period)) - } - - @Test - fun givenDates_thenGetPeriod() { - val localDate1 = LocalDate.parse("2007-05-10") - val localDate2 = LocalDate.parse("2007-05-15") - - Assert.assertEquals(Period.ofDays(5), usingPeriod.getDifferenceBetweenDates(localDate1, localDate2)) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt deleted file mode 100644 index aa2cdaa4f3..0000000000 --- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.kotlin.datetime - -import com.baeldung.dates.datetime.UseZonedDateTime -import org.junit.Assert -import org.junit.Test -import java.time.LocalDateTime -import java.time.ZoneId - -class UseZonedDateTimeUnitTest { - - internal var zonedDateTime = UseZonedDateTime() - - @Test - fun givenZoneId_thenZonedDateTime() { - val zoneId = ZoneId.of("Europe/Paris") - val zonedDatetime = zonedDateTime.getZonedDateTime(LocalDateTime.parse("2016-05-20T06:30"), zoneId) - Assert.assertEquals(zoneId, ZoneId.from(zonedDatetime)) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-design-patterns/README.md b/core-kotlin-modules/core-kotlin-design-patterns/README.md deleted file mode 100644 index 4bdc164a47..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Core Kotlin Design Patterns - -This module contains articles about design patterns in Kotlin - -### Relevant articles: -- [Creational Design Patterns in Kotlin: Builder](https://www.baeldung.com/kotlin-builder-pattern) diff --git a/core-kotlin-modules/core-kotlin-design-patterns/pom.xml b/core-kotlin-modules/core-kotlin-design-patterns/pom.xml deleted file mode 100644 index c112602bc2..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - core-kotlin-design-patterns - core-kotlin-design-patterns - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - - - 1.1.1 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt deleted file mode 100644 index 3a8a4b9857..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.builder - -class FoodOrder private constructor( - val bread: String?, - val condiments: String?, - val meat: String?, - val fish: String? -) { - data class Builder( - var bread: String? = null, - var condiments: String? = null, - var meat: String? = null, - var fish: String? = null) { - - fun bread(bread: String) = apply { this.bread = bread } - fun condiments(condiments: String) = apply { this.condiments = condiments } - fun meat(meat: String) = apply { this.meat = meat } - fun fish(fish: String) = apply { this.fish = fish } - fun build() = FoodOrder(bread, condiments, meat, fish) - } -} - diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt deleted file mode 100644 index 0a68832b00..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.builder - -class FoodOrderApply { - var bread: String? = null - var condiments: String? = null - var meat: String? = null - var fish: String? = null -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt deleted file mode 100644 index 0e4219b40e..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.builder - -data class FoodOrderNamed( - val bread: String? = null, - val condiments: String? = null, - val meat: String? = null, - val fish: String? = null) diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt deleted file mode 100644 index cc348e3fbf..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.builder - -fun main(args: Array) { - FoodOrder.Builder() - .bread("bread") - .condiments("condiments") - .meat("meat") - .fish("bread").let { println(it) } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt deleted file mode 100644 index a6687b6e0a..0000000000 --- a/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt +++ /dev/null @@ -1,140 +0,0 @@ -package com.baeldung.builder - -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -internal class BuilderPatternUnitTest { - - @Test - fun whenBuildingFoodOrderSettingValues_thenFieldsNotNull() { - - val foodOrder = FoodOrder.Builder() - .bread("white bread") - .meat("bacon") - .fish("salmon") - .condiments("olive oil") - .build() - - Assertions.assertNotNull(foodOrder.bread) - Assertions.assertNotNull(foodOrder.meat) - Assertions.assertNotNull(foodOrder.condiments) - Assertions.assertNotNull(foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderSettingValues_thenFieldsContainsValues() { - - val foodOrder = FoodOrder.Builder() - .bread("white bread") - .meat("bacon") - .fish("salmon") - .condiments("olive oil") - .build() - - Assertions.assertEquals("white bread", foodOrder.bread) - Assertions.assertEquals("bacon", foodOrder.meat) - Assertions.assertEquals("olive oil", foodOrder.condiments) - Assertions.assertEquals("salmon", foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderWithoutSettingValues_thenFieldsNull() { - - val foodOrder = FoodOrder.Builder() - .build() - - Assertions.assertNull(foodOrder.bread) - Assertions.assertNull(foodOrder.meat) - Assertions.assertNull(foodOrder.condiments) - Assertions.assertNull(foodOrder.fish) - } - - - @Test - fun whenBuildingFoodOrderNamedSettingValues_thenFieldsNotNull() { - - val foodOrder = FoodOrderNamed( - meat = "bacon", - fish = "salmon", - condiments = "olive oil", - bread = "white bread" - ) - - Assertions.assertNotNull(foodOrder.bread) - Assertions.assertNotNull(foodOrder.meat) - Assertions.assertNotNull(foodOrder.condiments) - Assertions.assertNotNull(foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderNamedSettingValues_thenFieldsContainsValues() { - - val foodOrder = FoodOrderNamed( - meat = "bacon", - fish = "salmon", - condiments = "olive oil", - bread = "white bread" - ) - - Assertions.assertEquals("white bread", foodOrder.bread) - Assertions.assertEquals("bacon", foodOrder.meat) - Assertions.assertEquals("olive oil", foodOrder.condiments) - Assertions.assertEquals("salmon", foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderNamedWithoutSettingValues_thenFieldsNull() { - - val foodOrder = FoodOrderNamed() - - Assertions.assertNull(foodOrder.bread) - Assertions.assertNull(foodOrder.meat) - Assertions.assertNull(foodOrder.condiments) - Assertions.assertNull(foodOrder.fish) - } - - - @Test - fun whenBuildingFoodOrderApplySettingValues_thenFieldsNotNull() { - - val foodOrder = FoodOrderApply().apply { - meat = "bacon" - fish = "salmon" - condiments = "olive oil" - bread = "white bread" - } - - Assertions.assertNotNull(foodOrder.bread) - Assertions.assertNotNull(foodOrder.meat) - Assertions.assertNotNull(foodOrder.condiments) - Assertions.assertNotNull(foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderApplySettingValues_thenFieldsContainsValues() { - - val foodOrder = FoodOrderApply().apply { - meat = "bacon" - fish = "salmon" - condiments = "olive oil" - bread = "white bread" - } - - Assertions.assertEquals("white bread", foodOrder.bread) - Assertions.assertEquals("bacon", foodOrder.meat) - Assertions.assertEquals("olive oil", foodOrder.condiments) - Assertions.assertEquals("salmon", foodOrder.fish) - } - - @Test - fun whenBuildingFoodOrderApplyWithoutSettingValues_thenFieldsNull() { - - val foodOrder = FoodOrderApply() - - Assertions.assertNull(foodOrder.bread) - Assertions.assertNull(foodOrder.meat) - Assertions.assertNull(foodOrder.condiments) - Assertions.assertNull(foodOrder.fish) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/README.md b/core-kotlin-modules/core-kotlin-io/README.md deleted file mode 100644 index 89f9534d4b..0000000000 --- a/core-kotlin-modules/core-kotlin-io/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Core Kotlin I/O - -This module contains articles about core Kotlin I/O. - -### Relevant articles: -- [InputStream to String in Kotlin](https://www.baeldung.com/kotlin-inputstream-to-string) -- [Console I/O in Kotlin](https://www.baeldung.com/kotlin-console-io) -- [Reading from a File in Kotlin](https://www.baeldung.com/kotlin-read-file) -- [Writing to a File in Kotlin](https://www.baeldung.com/kotlin-write-file) diff --git a/core-kotlin-modules/core-kotlin-io/pom.xml b/core-kotlin-modules/core-kotlin-io/pom.xml deleted file mode 100644 index 9443cd0d5b..0000000000 --- a/core-kotlin-modules/core-kotlin-io/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - core-kotlin-io - core-kotlin-io - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.mockito - mockito-core - ${mockito.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - 5.4.2 - 2.27.0 - 3.10.0 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt deleted file mode 100644 index 886a3fc51e..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.filesystem - -import java.io.File - -class FileReader { - - fun readFileLineByLineUsingForEachLine(fileName: String) = File(fileName).forEachLine { println(it) } - - fun readFileAsLinesUsingUseLines(fileName: String): List = File(fileName) - .useLines { it.toList() } - - fun readFileAsLinesUsingBufferedReader(fileName: String): List = File(fileName).bufferedReader().readLines() - - fun readFileAsLinesUsingReadLines(fileName: String): List = File(fileName).readLines() - - fun readFileAsTextUsingInputStream(fileName: String) = - File(fileName).inputStream().readBytes().toString(Charsets.UTF_8) - - fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8) - - fun readFileUsingGetResource(fileName: String) = this::class.java.getResource(fileName).readText(Charsets.UTF_8) - - fun readFileAsLinesUsingGetResourceAsStream(fileName: String) = this::class.java.getResourceAsStream(fileName).bufferedReader().readLines() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt deleted file mode 100644 index 6dc9b95f1f..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.filesystem - -import java.io.File - -class FileWriter { - - fun writeFileUsingPrintWriter(fileName: String, fileContent: String) = - File(fileName).printWriter().use { out -> out.print(fileContent) } - - fun writeFileUsingBufferedWriter(fileName: String, fileContent: String) = - File(fileName).bufferedWriter().use { out -> out.write(fileContent) } - - fun writeFileDirectly(fileName: String, fileContent: String) = - File(fileName).writeText(fileContent) - - fun writeFileDirectlyAsBytes(fileName: String, fileContent: String) = - File(fileName).writeBytes(fileContent.toByteArray()) - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt deleted file mode 100644 index e94a2e84ee..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.inputstream - -import java.io.InputStream - -fun InputStream.readUpToChar(stopChar: Char): String { - val stringBuilder = StringBuilder() - var currentChar = this.read().toChar() - while (currentChar != stopChar) { - stringBuilder.append(currentChar) - currentChar = this.read().toChar() - if (this.available() <= 0) { - stringBuilder.append(currentChar) - break - } - } - return stringBuilder.toString() -} - diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt deleted file mode 100644 index c73096fce6..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.baeldung.console - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Test -import org.mockito.Mockito.`when` -import org.mockito.Mockito.mock -import java.io.BufferedReader -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import java.io.Console -import java.io.InputStreamReader -import java.io.PrintStream -import java.util.* - - -class ConsoleIOUnitTest { - - @Test - fun givenText_whenPrint_thenPrintText() { - val expectedTest = "Hello from Kotlin" - val out = ByteArrayOutputStream() - System.setOut(PrintStream(out)) - - print(expectedTest) - out.flush() - val printedText = String(out.toByteArray()) - - assertThat(printedText).isEqualTo(expectedTest) - } - - @Test - fun givenInput_whenRead_thenReadText() { - val expectedTest = "Hello from Kotlin" - val input = ByteArrayInputStream(expectedTest.toByteArray()) - System.setIn(input) - - val readText = readLine() - - assertThat(readText).isEqualTo(expectedTest) - } - - @Test - fun givenInput_whenReadWithScanner_thenReadText() { - val expectedTest = "Hello from Kotlin" - val scanner = Scanner(ByteArrayInputStream(expectedTest.toByteArray())) - - val readText = scanner.nextLine() - - assertThat(readText).isEqualTo(expectedTest) - } - - @Test - fun givenInput_whenReadWithBufferedReader_thenReadText() { - val expectedTest = "Hello from Kotlin" - val reader = BufferedReader(InputStreamReader(ByteArrayInputStream(expectedTest.toByteArray()))) - - val readText = reader.readLine() - - assertThat(readText).isEqualTo(expectedTest) - } - - @Test - fun givenInput_whenReadWithConsole_thenReadText() { - val expectedTest = "Hello from Kotlin" - val console = mock(Console::class.java) - `when`(console.readLine()).thenReturn(expectedTest) - - val readText = console.readLine() - - assertThat(readText).isEqualTo(expectedTest) - } - - @AfterEach - fun resetIO() { - System.setOut(System.out) - System.setIn(System.`in`) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt deleted file mode 100644 index ad541c446e..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.filesystem - -import org.junit.jupiter.api.Test -import kotlin.test.assertTrue - -internal class FileReaderTest { - - private val fileName = "src/test/resources/Kotlin.in" - - private val fileReader = FileReader() - - @Test - fun whenReadFileLineByLineUsingForEachLine_thenCorrect() { - fileReader.readFileLineByLineUsingForEachLine(fileName) - } - - @Test - fun whenReadFileAsLinesUsingUseLines_thenCorrect() { - val lines = fileReader.readFileAsLinesUsingUseLines(fileName) - - assertTrue { lines.contains("1. Concise") } - } - - @Test - fun whenReadFileAsLinesUsingBufferedReader_thenCorrect() { - val lines = fileReader.readFileAsLinesUsingBufferedReader(fileName) - - assertTrue { lines.contains("2. Safe") } - } - - @Test - fun whenReadFileAsLinesUsingReadLines_thenCorrect() { - val lines = fileReader.readFileAsLinesUsingReadLines(fileName) - - assertTrue { lines.contains("3. Interoperable") } - } - - @Test - fun whenReadFileAsTextUsingInputStream_thenCorrect() { - val text = fileReader.readFileAsTextUsingInputStream(fileName) - - assertTrue { text.contains("4. Tool-friendly") } - } - - @Test - fun whenReadDirectlyAsText_thenCorrect() { - val text = fileReader.readFileDirectlyAsText(fileName) - - assertTrue { text.contains("Hello to Kotlin") } - } - - @Test - fun whenReadFileAsTextUsingGetResource_thenCorrect() { - val text = fileReader.readFileUsingGetResource("/Kotlin.in") - - assertTrue { text.contains("1. Concise") } - } - - @Test - fun whenReadFileUsingGetResourceAsStream_thenCorrect() { - val lines = fileReader.readFileAsLinesUsingGetResourceAsStream("/Kotlin.in") - - assertTrue { lines.contains("3. Interoperable") } - } - - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt deleted file mode 100644 index 91c66a4fee..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.filesystem - -import org.junit.jupiter.api.Test -import java.io.File -import kotlin.test.assertEquals - -internal class FileWriterTest { - - private val fileName = "src/test/resources/Kotlin.out" - - private val fileContent = "Kotlin\nConcise, Safe, Interoperable, Tool-friendly" - - private val fileWriter = FileWriter() - - @Test - fun whenWrittenWithPrintWriter_thenCorrect() { - fileWriter.writeFileUsingPrintWriter(fileName, fileContent) - - assertEquals(fileContent, File(fileName).readText()) - } - - @Test - fun whenWrittenWithBufferedWriter_thenCorrect() { - fileWriter.writeFileUsingBufferedWriter(fileName, fileContent) - - assertEquals(fileContent, File(fileName).readText()) - } - - @Test - fun whenWrittenDirectly_thenCorrect() { - fileWriter.writeFileDirectly(fileName, fileContent) - - assertEquals(fileContent, File(fileName).readText()) - } - - @Test - fun whenWrittenDirectlyAsBytes_thenCorrect() { - fileWriter.writeFileDirectlyAsBytes(fileName, fileContent) - - assertEquals(fileContent, File(fileName).readText()) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt deleted file mode 100644 index a0eb26b762..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.inputstream - -import kotlinx.io.core.use -import org.junit.Test -import java.io.BufferedReader -import java.io.File -import kotlin.test.assertEquals - -class InputStreamToStringTest { - - private val fileName = "src/test/resources/inputstream2string.txt" - private val endOfLine = System.lineSeparator() - private val fileFullContent = "Computer programming can be a hassle$endOfLine" + - "It's like trying to take a defended castle" - - @Test - fun whenReadFileWithBufferedReader_thenFullFileContentIsReadAsString() { - val file = File(fileName) - val inputStream = file.inputStream() - val content = inputStream.bufferedReader().use(BufferedReader::readText) - assertEquals(fileFullContent, content) - } - - @Test - fun whenReadFileWithBufferedReaderReadText_thenFullFileContentIsReadAsString() { - val file = File(fileName) - val inputStream = file.inputStream() - val reader = BufferedReader(inputStream.reader()) - var content: String - try { - content = reader.readText() - } finally { - reader.close() - } - assertEquals(fileFullContent, content) - } - - @Test - fun whenReadFileWithBufferedReaderManually_thenFullFileContentIsReadAsString() { - val file = File(fileName) - val inputStream = file.inputStream() - val reader = BufferedReader(inputStream.reader()) - val content = StringBuilder() - try { - var line = reader.readLine() - while (line != null) { - content.append(line) - line = reader.readLine() - } - } finally { - reader.close() - } - assertEquals(fileFullContent.replace(endOfLine, ""), content.toString()) - - } - - @Test - fun whenReadFileUpToStopChar_thenPartBeforeStopCharIsReadAsString() { - val file = File(fileName) - val inputStream = file.inputStream() - val content = inputStream.use { it.readUpToChar(' ') } - assertEquals("Computer", content) - } - - @Test - fun whenReadFileWithoutContainingStopChar_thenFullFileContentIsReadAsString() { - val file = File(fileName) - val inputStream = file.inputStream() - val content = inputStream.use { it.readUpToChar('-') } - assertEquals(fileFullContent, content) - } - -} - diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in b/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in deleted file mode 100644 index d140d4429e..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in +++ /dev/null @@ -1,5 +0,0 @@ -Hello to Kotlin. Its: -1. Concise -2. Safe -3. Interoperable -4. Tool-friendly \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out b/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out deleted file mode 100644 index 63d15d2528..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out +++ /dev/null @@ -1,2 +0,0 @@ -Kotlin -Concise, Safe, Interoperable, Tool-friendly \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt b/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt deleted file mode 100644 index 40ef9fc5f3..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt +++ /dev/null @@ -1,2 +0,0 @@ -Computer programming can be a hassle -It's like trying to take a defended castle \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index ca6ee9cea8..0000000000 --- a/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/README.md b/core-kotlin-modules/core-kotlin-lang-2/README.md deleted file mode 100644 index e7f232856b..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Core Kotlin Lang - -This module contains articles about core features in the Kotlin language. - -### Relevant articles: -- [Kotlin return, break, continue Keywords](https://www.baeldung.com/kotlin-return-break-continue) -- [Infix Functions in Kotlin](https://www.baeldung.com/kotlin-infix-functions) -- [Lambda Expressions in Kotlin](https://www.baeldung.com/kotlin-lambda-expressions) -- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final) -- [Lazy Initialization in Kotlin](https://www.baeldung.com/kotlin-lazy-initialization) -- [Comprehensive Guide to Null Safety in Kotlin](https://www.baeldung.com/kotlin-null-safety) -- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions) -- [If-Else Expression in Kotlin](https://www.baeldung.com/kotlin/if-else-expression) -- [Checking Whether a lateinit var Is Initialized in Kotlin](https://www.baeldung.com/kotlin/checking-lateinit) -- [Not-Null Assertion (!!) Operator in Kotlin](https://www.baeldung.com/kotlin/not-null-assertion) -- [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang) diff --git a/core-kotlin-modules/core-kotlin-lang-2/pom.xml b/core-kotlin-modules/core-kotlin-lang-2/pom.xml deleted file mode 100644 index 753147728d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - core-kotlin-lang-2 - core-kotlin-lang-2 - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java b/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java deleted file mode 100644 index 273749e17e..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.lazy; - -public class ClassWithHeavyInitialization { - private ClassWithHeavyInitialization() { - } - - private static class LazyHolder { - public static final ClassWithHeavyInitialization INSTANCE = new ClassWithHeavyInitialization(); - } - - public static ClassWithHeavyInitialization getInstance() { - return LazyHolder.INSTANCE; - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt deleted file mode 100644 index f4e42a4f4f..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.baeldung.ifelseexpression - -fun ifStatementUsage(): String { - val number = 15 - - if (number > 0) { - return "Positive number" - } - return "Positive number not found" -} - -fun ifElseStatementUsage(): String { - val number = -50 - - if (number > 0) { - return "Positive number" - } else { - return "Negative number" - } -} - -fun ifElseExpressionUsage(): String { - val number = -50 - - val result = if (number > 0) { - "Positive number" - } else { - "Negative number" - } - return result -} - -fun ifElseExpressionSingleLineUsage(): String { - val number = -50 - val result = if (number > 0) "Positive number" else "Negative number" - - return result -} - -fun ifElseMultipleExpressionUsage(): Int { - val x = 24 - val y = 73 - - val result = if (x > y) { - println("$x is greater than $y") - x - } else { - println("$x is less than or equal to $y") - y - } - return result -} - -fun ifElseLadderExpressionUsage(): String { - val number = 60 - - val result = if (number < 0) { - "Negative number" - } else if (number in 0..9) { - "Single digit number" - } else if (number in 10..99) { - "Double digit number" - } else { - "Number has more digits" - } - return result -} - -fun ifElseNestedExpressionUsage(): Int { - val x = 37 - val y = 89 - val z = 6 - - val result = if (x > y) { - if (x > z) - x - else - z - } else { - if (y > z) - y - else - z - } - return result -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt deleted file mode 100644 index f35f9cdac2..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.baeldung.lambda - -fun inferredType(input: Int): Int { - val square = { number: Int -> number * number } - - return square(input) -} - -fun intToBiggerString(argument: Int): String { - - val magnitude100String = { input: Int -> - val magnitude = input * 100 - magnitude.toString() - } - - return magnitude100String(argument) -} - -fun manyLambda(nums: Array): List { - val newList = nums.map { intToBiggerString(it) } - - return newList -} - -fun empty() { - val noReturn: (Int) -> Unit = { num -> println(num) } - - noReturn(5) -} - -fun invokeLambda(lambda: (Double) -> Boolean): Boolean { - return lambda(4.329) -} - -fun extendString(arg: String, num: Int): String { - val another: String.(Int) -> String = { this + it } - - return arg.another(num) -} - -fun getCalculationLambda(): (Int) -> Any { - val calculateGrade = { grade: Int -> - when (grade) { - in 0..40 -> "Fail" - in 41..70 -> "Pass" - in 71..100 -> "Distinction" - else -> false - } - } - - return calculateGrade -} - -fun getCalculationLambdaWithReturn(): (Int) -> String { - val calculateGrade: Int.() -> String = lambda@{ - if (this < 0 || this > 100) { - return@lambda "Error" - } else if (this < 40) { - return@lambda "Fail" - } else if (this < 70) { - return@lambda "Pass" - } - - "Distinction" - } - - return calculateGrade -} - -fun getCalculationAnonymousFunction(): (Int) -> String { - val calculateGrade = fun(grade: Int): String { - if (grade < 0 || grade > 100) { - return "Error" - } else if (grade < 40) { - return "Fail" - } else if (grade < 70) { - return "Pass" - } - - return "Distinction" - } - - return calculateGrade -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt deleted file mode 100644 index 37ad8c65e2..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.scope - -data class Student(var studentId: String = "", var name: String = "", var surname: String = "") { -} - -data class Teacher(var teacherId: Int = 0, var name: String = "", var surname: String = "") { - fun setId(anId: Int): Teacher = apply { teacherId = anId } - fun setName(aName: String): Teacher = apply { name = aName } - fun setSurname(aSurname: String): Teacher = apply { surname = aSurname } -} - -data class Headers(val headerInfo: String) - -data class Response(val headers: Headers) - -data class RestClient(val url: String) { - fun getResponse() = Response(Headers("some header info")) -} - -data class BankAccount(val id: Int) { - fun checkAuthorization(username: String) = Unit - fun addPayee(payee: String) = Unit - fun makePayment(paymentDetails: String) = Unit - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java b/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java deleted file mode 100644 index 01c87d9543..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.lazy; - -import org.junit.Test; - -import static junit.framework.TestCase.assertTrue; - -public class LazyJavaUnitTest { - - @Test - public void giveHeavyClass_whenInitLazy_thenShouldReturnInstanceOnFirstCall() { - //when - ClassWithHeavyInitialization classWithHeavyInitialization = ClassWithHeavyInitialization.getInstance(); - ClassWithHeavyInitialization classWithHeavyInitialization2 = ClassWithHeavyInitialization.getInstance(); - - //then - assertTrue(classWithHeavyInitialization == classWithHeavyInitialization2); - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt deleted file mode 100644 index d9bf433208..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.constant - -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class ConstantUnitTest { - - @Test - fun givenConstant_whenCompareWithActualValue_thenReturnTrue() { - assertEquals(10, TestKotlinConstantObject.COMPILE_TIME_CONST) - assertEquals(30, TestKotlinConstantObject.RUN_TIME_CONST) - assertEquals(20, TestKotlinConstantObject.JAVA_STATIC_FINAL_FIELD) - - assertEquals(40, TestKotlinConstantClass.COMPANION_OBJECT_NUMBER) - } -} - diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt deleted file mode 100644 index 3c4d4db220..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.constant - - -class TestKotlinConstantClass { - companion object { - const val COMPANION_OBJECT_NUMBER = 40 - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt deleted file mode 100644 index a6951b4481..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.constant - - -object TestKotlinConstantObject { - const val COMPILE_TIME_CONST = 10 - - val RUN_TIME_CONST: Int - - @JvmField - val JAVA_STATIC_FINAL_FIELD = 20 - - init { - RUN_TIME_CONST = TestKotlinConstantObject.COMPILE_TIME_CONST + 20; - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt deleted file mode 100644 index 266e41e07b..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.ifelseexpression - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals - -class IfElseExpressionExampleTest { - - @Test - fun givenNumber_whenIfStatementCalled_thenReturnsString() { - assertEquals("Positive number", ifStatementUsage()) - } - - @Test - fun givenNumber_whenIfElseStatementCalled_thenReturnsString() { - assertEquals("Negative number", ifElseStatementUsage()) - } - - @Test - fun givenNumber_whenIfElseExpressionCalled_thenReturnsString() { - assertEquals("Negative number", ifElseExpressionUsage()) - } - - @Test - fun givenNumber_whenIfElseExpressionSingleLineCalled_thenReturnsString() { - assertEquals("Negative number", ifElseExpressionSingleLineUsage()) - } - - @Test - fun givenNumber_whenIfElseMultipleExpressionCalled_thenReturnsNumber() { - assertEquals(73, ifElseMultipleExpressionUsage()) - } - - @Test - fun givenNumber_whenIfElseLadderExpressionCalled_thenReturnsString() { - assertEquals("Double digit number", ifElseLadderExpressionUsage()) - } - - @Test - fun givenNumber_whenIfElseNestedExpressionCalled_thenReturnsNumber() { - assertEquals(89, ifElseNestedExpressionUsage()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt deleted file mode 100644 index 0b09d34013..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.infixfunctions - -import org.junit.Assert -import org.junit.Test - -class InfixFunctionsTest { - @Test - fun testColours() { - val color = 0x123456 - val red = (color and 0xff0000) shr 16 - val green = (color and 0x00ff00) shr 8 - val blue = (color and 0x0000ff) shr 0 - - Assert.assertEquals(0x12, red) - Assert.assertEquals(0x34, green) - Assert.assertEquals(0x56, blue) - } - - @Test - fun testNewAssertions() { - class Assertion(private val target: T) { - infix fun isEqualTo(other: T) { - Assert.assertEquals(other, target) - } - - infix fun isDifferentFrom(other: T) { - Assert.assertNotEquals(other, target) - } - } - - val result = Assertion(5) - - result isEqualTo 5 - - // The following two lines are expected to fail - // result isEqualTo 6 - // result isDifferentFrom 5 - } - - @Test - fun testNewStringMethod() { - infix fun String.substringMatches(r: Regex) : List { - return r.findAll(this) - .map { it.value } - .toList() - } - - val matches = "a bc def" substringMatches ".*? ".toRegex() - Assert.assertEquals(listOf("a ", "bc "), matches) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java deleted file mode 100644 index 91c777c036..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.lambda; - -import kotlin.jvm.functions.Function1; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Created by Paul Jervis on 24/04/2018. - */ -class LambdaKotlinUnitTest { - - @Test - void givenJava6_whenUsingAnonnymousClass_thenReturnLambdaResult() { - assertTrue(LambdaKt.invokeLambda(new Function1() { - @Override - public Boolean invoke(Double c) { - return c >= 0; - } - })); - } - - @Test - void givenJava8_whenUsingLambda_thenReturnLambdaResult() { - assertTrue(LambdaKt.invokeLambda(c -> c >= 0)); - } - - @Test - void givenJava8_whenCallingMethodWithStringExtension_thenImplementExtension() { - String actual = LambdaKt.extendString("Word", 90); - String expected = "Word90"; - - assertEquals(expected, actual); - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt deleted file mode 100644 index bddabee462..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.baeldung.lambda - -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class LambdaTest { - - @Test - fun whenCallingALambda_thenPerformTheAction() { - assertEquals(9, inferredType(3)) - } - - @Test - fun whenCallingAMoreComplicatedLambda_thenPerformTheAction() { - assertEquals("500", intToBiggerString(5)) - } - - @Test - fun whenPassingALambdaObject_thenCallTriggerLambda() { - val lambda = { arg: Double -> - arg == 4.329 - } - - val result = invokeLambda(lambda) - - assertTrue(result) - } - - @Test - fun whenPassingALambdaLiteral_thenCallTriggerLambda() { - val result = invokeLambda({ - true - }) - - assertTrue(result) - } - - @Test - fun whenPassingALambdaLiteralOutsideBrackets_thenCallTriggerLambda() { - val result = invokeLambda { arg -> arg.isNaN() } - - assertFalse(result) - } - - @Test - fun whenPassingAnAnonymousFunction_thenCallTriggerLambda() { - val result = invokeLambda(fun(arg: Double): Boolean { - return arg >= 0 - }) - - assertTrue(result) - } - - @Test - fun whenUsingLambda_thenCalculateGrade() { - val gradeCalculation = getCalculationLambda() - - assertEquals(false, gradeCalculation(-40)) - assertEquals("Pass", gradeCalculation(50)) - } - - @Test - fun whenUsingReturnStatementLambda_thenCalculateGrade() { - val gradeCalculation: Int.() -> String = getCalculationLambdaWithReturn() - - assertEquals("Distinction", 80.gradeCalculation()) - assertEquals("Error", 244_234_324.gradeCalculation()) - } - - @Test - fun whenUsingAnonymousFunction_thenCalculateGrade() { - val gradeCalculation = getCalculationAnonymousFunction() - - assertEquals("Error", gradeCalculation(244_234_324)) - assertEquals("Pass", gradeCalculation(50)) - } - - @Test - fun whenPassingAFunctionReference_thenCallTriggerLambda() { - val reference = Double::isFinite - val result = invokeLambda(reference) - - assertTrue(result) - } - - @Test - fun givenArray_whenMappingArray_thenPerformCalculationOnAllElements() { - val expected = listOf("100", "200", "300", "400", "500") - val actual = manyLambda(arrayOf(1, 2, 3, 4, 5)) - - assertEquals(expected, actual) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt deleted file mode 100644 index c99e438742..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.late - -import org.junit.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class LateInitUnitTest { - - private lateinit var answer: String - - @Test(expected = UninitializedPropertyAccessException::class) - fun givenLateInit_WhenNotInitialized_ShouldThrowAnException() { - answer.length - } - - @Test - fun givenLateInit_TheIsInitialized_ReturnsTheInitializationStatus() { - assertFalse { this::answer.isInitialized } - answer = "42" - assertTrue { this::answer.isInitialized } - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt deleted file mode 100644 index b9b21ed4d9..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.lazy - -import org.junit.Test -import java.util.concurrent.CountDownLatch -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicInteger -import kotlin.test.assertEquals - -class LazyUnitTest { - @Test - fun givenLazyValue_whenGetIt_thenShouldInitializeItOnlyOnce() { - //given - val numberOfInitializations: AtomicInteger = AtomicInteger() - val lazyValue: ClassWithHeavyInitialization by lazy { - numberOfInitializations.incrementAndGet() - ClassWithHeavyInitialization() - } - //when - println(lazyValue) - println(lazyValue) - - //then - assertEquals(numberOfInitializations.get(), 1) - } - - @Test - fun givenLazyValue_whenGetItUsingPublication_thenCouldInitializeItMoreThanOnce() { - //given - val numberOfInitializations: AtomicInteger = AtomicInteger() - val lazyValue: ClassWithHeavyInitialization by lazy(LazyThreadSafetyMode.PUBLICATION) { - numberOfInitializations.incrementAndGet() - ClassWithHeavyInitialization() - } - val executorService = Executors.newFixedThreadPool(2) - val countDownLatch = CountDownLatch(1) - //when - executorService.submit { countDownLatch.await(); println(lazyValue) } - executorService.submit { countDownLatch.await(); println(lazyValue) } - countDownLatch.countDown() - - //then - executorService.shutdown() - executorService.awaitTermination(5, TimeUnit.SECONDS) - //assertEquals(numberOfInitializations.get(), 2) - } - - class ClassWithHeavyInitialization { - - } - - - lateinit var a: String - @Test - fun givenLateInitProperty_whenAccessItAfterInit_thenPass() { - //when - a = "it" - println(a) - - //then not throw - } - - @Test(expected = UninitializedPropertyAccessException::class) - fun givenLateInitProperty_whenAccessItWithoutInit_thenThrow() { - //when - println(a) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt deleted file mode 100644 index 66fc043581..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt +++ /dev/null @@ -1,161 +0,0 @@ -package com.baeldung.nullsafety - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith -import kotlin.test.assertNull -import kotlin.test.assertTrue - - -class NullSafetyTest { - - @Test - fun givenNonNullableField_whenAssignValueToIt_thenNotNeedToCheckAgainstNull() { - //given - var a: String = "value" - //a = null compilation error - - //then - assertEquals(a.length, 5) - } - - @Test - fun givenNullableField_whenReadValue_thenNeedToCheckAgainstNull() { - //given - var b: String? = "value" - b = null - - //when - if (b != null) { - - } else { - assertNull(b) - } - } - - @Test - fun givenComplexObject_whenUseSafeCall_thenShouldChainCallsResultingWithValue() { - //given - val p: Person? = Person(Country("ENG")) - - //when - val res = p?.country?.code - - //then - assertEquals(res, "ENG") - } - - @Test - fun givenComplexObject_whenUseSafeCall_thenShouldChainCallsResultingWithNull() { - //given - val p: Person? = Person(Country(null)) - - //when - val res = p?.country?.code - - //then - assertNull(res) - } - - @Test - fun givenCollectionOfObjects_whenUseLetOperator_thenShouldApplyActionOnlyOnNonNullValue() { - //given - val firstName = "Tom" - val secondName = "Michael" - val names: List = listOf(firstName, null, secondName) - - //when - var res = listOf() - for (item in names) { - item?.let { res = res.plus(it); it } - ?.also{it -> println("non nullable value: $it")} - } - - //then - assertEquals(2, res.size) - assertTrue { res.contains(firstName) } - assertTrue { res.contains(secondName) } - } - - @Test - fun fivenCollectionOfObject_whenUseRunOperator_thenExecuteActionOnNonNullValue(){ - //given - val firstName = "Tom" - val secondName = "Michael" - val names: List = listOf(firstName, null, secondName) - - //when - var res = listOf() - for (item in names) { - item?.run{res = res.plus(this)} - } - - //then - assertEquals(2, res.size) - assertTrue { res.contains(firstName) } - assertTrue { res.contains(secondName) } - } - - @Test - fun givenNullableReference_whenUseElvisOperator_thenShouldReturnValueIfReferenceIsNotNull() { - //given - val value: String? = "name" - - //when - val res = value?.length ?: -1 - - //then - assertEquals(res, 4) - } - - @Test - fun givenNullableReference_whenUseElvisOperator_thenShouldReturnDefaultValueIfReferenceIsNull() { - //given - val value: String? = null - - //when - val res = value?.length ?: -1 - - //then - assertEquals(res, -1) - } - - @Test - fun givenNullableField_whenUsingDoubleExclamationMarkOperatorOnNull_thenThrowNPE() { - //given - var b: String? = "value" - b = null - - //when - assertFailsWith { - b!!.length - } - } - - @Test - fun givenNullableField_whenUsingDoubleExclamationMarkOperatorOnNotNull_thenReturnValue() { - //given - val b: String? = "value" - - //then - assertEquals(b!!.length, 5) - } - - @Test - fun givenNullableList_whenUseFilterNotNullMethod_thenRemoveALlNullValues() { - //given - val list: List = listOf("a", null, "b") - - //when - val res = list.filterNotNull() - - //then - assertEquals(res.size, 2) - assertTrue { res.contains("a") } - assertTrue { res.contains("b") } - } -} - -data class Person(val country: Country?) - -data class Country(val code: String?) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt deleted file mode 100644 index cb3ed98006..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.baeldung.scope - -import org.junit.Test -import kotlin.test.assertTrue - - -class ScopeFunctionsUnitTest { - - class Logger { - - var called : Boolean = false - - fun info(message: String) { - called = true - } - - fun wasCalled() = called - } - - @Test - fun shouldTransformWhenLetFunctionUsed() { - val stringBuider = StringBuilder() - val numberOfCharacters = stringBuider.let { - it.append("This is a transformation function.") - it.append("It takes a StringBuilder instance and returns the number of characters in the generated String") - it.length - } - - assertTrue { - numberOfCharacters == 128 - } - } - - @Test - fun shouldHandleNullabilityWhenLetFunctionUsed() { - - val message: String? = "hello there!" - val charactersInMessage = message?.let { - "At this point is safe to reference the variable. Let's print the message: $it" - } ?: "default value" - - assertTrue { - charactersInMessage.equals("At this point is safe to reference the variable. Let's print the message: hello there!") - } - - val aNullMessage = null - val thisIsNull = aNullMessage?.let { - "At this point it would be safe to reference the variable. But it will not really happen because it is null. Let's reference: $it" - } ?: "default value" - - assertTrue { - thisIsNull.equals("default value") - } - } - - @Test - fun shouldInitializeObjectWhenUsingApply() { - val aStudent = Student().apply { - studentId = "1234567" - name = "Mary" - surname = "Smith" - } - - assertTrue { - aStudent.name.equals("Mary") - } - } - - @Test - fun shouldAllowBuilderStyleObjectDesignWhenApplyUsedInClassMethods() { - val teacher = Teacher() - .setId(1000) - .setName("Martha") - .setSurname("Spector") - - assertTrue { - teacher.surname.equals("Spector") - } - } - - @Test - fun shouldAllowSideEffectWhenUsingAlso() { - val restClient = RestClient("http://www.someurl.com") - - val logger = Logger() - - val headers = restClient - .getResponse() - .also { logger.info(it.toString()) } - .headers - - assertTrue { - logger.wasCalled() && headers.headerInfo.equals("some header info") - } - - } - - @Test - fun shouldInitializeFieldWhenAlsoUsed() { - val aStudent = Student().also { it.name = "John"} - - assertTrue { - aStudent.name.equals("John") - } - } - - @Test - fun shouldLogicallyGroupObjectCallsWhenUsingWith() { - val bankAccount = BankAccount(1000) - with (bankAccount) { - checkAuthorization("someone") - addPayee("some payee") - makePayment("payment information") - } - } - - @Test - fun shouldConvertObjectWhenRunUsed() { - val stringBuider = StringBuilder() - val numberOfCharacters = stringBuider.run { - append("This is a transformation function.") - append("It takes a StringBuilder instance and returns the number of characters in the generated String") - length - } - - assertTrue { - numberOfCharacters == 128 - } - } - - @Test - fun shouldHandleNullabilityWhenRunIsUsed() { - val message: String? = "hello there!" - val charactersInMessage = message?.run { - "At this point is safe to reference the variable. Let's print the message: $this" - } ?: "default value" - - assertTrue { - charactersInMessage.equals("At this point is safe to reference the variable. Let's print the message: hello there!") - } - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt deleted file mode 100644 index 88011ab396..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt +++ /dev/null @@ -1,121 +0,0 @@ -package com.baeldung.structuraljump - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse - -class StructuralJumpUnitTest { - - @Test - fun givenLoop_whenBreak_thenComplete() { - var value = "" - for (i in "hello_world") { - if (i == '_') - break - value += i.toString() - } - assertEquals("hello", value) - } - @Test - fun givenLoop_whenBreakWithLabel_thenComplete() { - var value = "" - outer_loop@ for (i in 'a'..'d') { - for (j in 1..3) { - value += "" + i + j - if (i == 'b' && j == 1) - break@outer_loop - } - } - assertEquals("a1a2a3b1", value) - } - - @Test - fun givenLoop_whenContinue_thenComplete() { - var result = "" - for (i in "hello_world") { - if (i == '_') - continue - result += i - } - assertEquals("helloworld", result) - } - @Test - fun givenLoop_whenContinueWithLabel_thenComplete() { - var result = "" - outer_loop@ for (i in 'a'..'c') { - for (j in 1..3) { - if (i == 'b') - continue@outer_loop - result += "" + i + j - } - } - assertEquals("a1a2a3c1c2c3", result) - } - - @Test - fun givenLambda_whenReturn_thenComplete() { - var result = returnInLambda(); - assertEquals("hello", result) - } - - private fun returnInLambda(): String { - var result = "" - "hello_world".forEach { - // non-local return directly to the caller - if (it == '_') return result - result += it.toString() - } - //this line won't be reached - return result; - } - - @Test - fun givenLambda_whenReturnWithExplicitLabel_thenComplete() { - var result = "" - "hello_world".forEach lit@{ - if (it == '_') { - // local return to the caller of the lambda, i.e. the forEach loop - return@lit - } - result += it.toString() - } - assertEquals("helloworld", result) - } - - @Test - fun givenLambda_whenReturnWithImplicitLabel_thenComplete() { - var result = "" - "hello_world".forEach { - if (it == '_') { - // local return to the caller of the lambda, i.e. the forEach loop - return@forEach - } - result += it.toString() - } - assertEquals("helloworld", result) - } - - @Test - fun givenAnonymousFunction_return_thenComplete() { - var result = "" - "hello_world".forEach(fun(element) { - // local return to the caller of the anonymous fun, i.e. the forEach loop - if (element == '_') return - result += element.toString() - }) - assertEquals("helloworld", result) - } - - @Test - fun givenAnonymousFunction_returnToLabel_thenComplete() { - var result = "" - run loop@{ - "hello_world".forEach { - // non-local return from the lambda passed to run - if (it == '_') return@loop - result += it.toString() - } - } - assertEquals("hello", result) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md deleted file mode 100644 index a62a25c01d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## Core Kotlin Lang OOP - -This module contains articles about Object-Oriented Programming in Kotlin - -### Relevant articles: - -- [Generics in Kotlin](https://www.baeldung.com/kotlin-generics) -- [Delegated Properties in Kotlin](https://www.baeldung.com/kotlin-delegated-properties) -- [Delegation Pattern in Kotlin](https://www.baeldung.com/kotlin-delegation-pattern) -- [Anonymous Inner Classes in Kotlin](https://www.baeldung.com/kotlin/anonymous-inner-classes) -- [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang-oop) diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml b/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml deleted file mode 100644 index f952911ae1..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - 4.0.0 - core-kotlin-lang-oop-2 - core-kotlin-lang-oop-2 - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.assertj - assertj-core - ${assertj.version} - test - - - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-stdlib-jdk7 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-stdlib-common - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-reflect - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test-common - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test-annotations-common - ${kotlin.version} - - - - - - 1.4.10 - - diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt deleted file mode 100644 index ea471f5d00..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.anonymous - -import java.io.Serializable -import java.nio.channels.Channel - -fun main() { - val channel = object : Channel { - override fun isOpen() = false - - override fun close() { - } - } - - val maxEntries = 10 - val lruCache = object : LinkedHashMap(10, 0.75f) { - - override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean { - return size > maxEntries - } - } - - val map = object : LinkedHashMap() { - // omitted - } - - val serializableChannel = object : Channel, Serializable { - override fun isOpen(): Boolean { - TODO("Not yet implemented") - } - - override fun close() { - TODO("Not yet implemented") - } - } - - val obj = object { - val question = "answer" - val answer = 42 - } - println("The ${obj.question} is ${obj.answer}") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt deleted file mode 100644 index 37a632fe41..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt +++ /dev/null @@ -1,6 +0,0 @@ -inline fun Iterable<*>.filterIsInstance() = filter { it is T } - -fun main(args: Array) { - val set = setOf("1984", 2, 3, "Brave new world", 11) - println(set.filterIsInstance()) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt deleted file mode 100644 index 9ea9f027fc..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.kotlin.delegates - -val data = arrayOf>( - mutableMapOf( - "id" to 1, - "name" to "George", - "age" to 4 - ), - mutableMapOf( - "id" to 2, - "name" to "Charlotte", - "age" to 2 - ) -) - -class NoRecordFoundException(id: Int) : Exception("No record found for id $id") { - init { - println("No record found for ID $id") - } -} - -fun queryForValue(field: String, id: Int): Any { - println("Loading record $id from the fake database") - val value = data.firstOrNull { it["id"] == id } - ?.get(field) ?: throw NoRecordFoundException(id) - println("Loaded value $value for field $field of record $id") - return value -} - -fun update(field: String, id: Int, value: Any?) { - println("Updating field $field of record $id to value $value in the fake database") - data.firstOrNull { it["id"] == id } - ?.put(field, value) - ?: throw NoRecordFoundException(id) -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt deleted file mode 100644 index c1c0f8823c..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.kotlin.delegates - -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty - -class DatabaseDelegate(private val field: String, private val id: Int) : ReadWriteProperty { - override fun getValue(thisRef: R, property: KProperty<*>): T = - queryForValue(field, id) as T - - override fun setValue(thisRef: R, property: KProperty<*>, value: T) { - update(field, id, value) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt deleted file mode 100644 index 8e261aacf2..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.kotlin.delegates - -import java.util.concurrent.locks.ReentrantLock -import kotlin.concurrent.withLock - -interface Producer { - - fun produce(): String -} - -class ProducerImpl : Producer { - - override fun produce() = "ProducerImpl" -} - -class EnhancedProducer(private val delegate: Producer) : Producer by delegate { - - override fun produce() = "${delegate.produce()} and EnhancedProducer" -} - -interface MessageService { - - fun processMessage(message: String): String -} - -class MessageServiceImpl : MessageService { - override fun processMessage(message: String): String { - return "MessageServiceImpl: $message" - } -} - -interface UserService { - - fun processUser(userId: String): String -} - -class UserServiceImpl : UserService { - - override fun processUser(userId: String): String { - return "UserServiceImpl: $userId" - } -} - -class CompositeService : UserService by UserServiceImpl(), MessageService by MessageServiceImpl() - -interface Service { - - val seed: Int - - fun serve(action: (Int) -> Unit) -} - -class ServiceImpl : Service { - - override val seed = 1 - - override fun serve(action: (Int) -> Unit) { - action(seed) - } -} - -class ServiceDecorator : Service by ServiceImpl() { - override val seed = 2 -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt deleted file mode 100644 index 7788305ea1..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.kotlin.delegates - -class User(val id: Int) { - var name: String by DatabaseDelegate("name", id) - var age: Int by DatabaseDelegate("age", id) -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt deleted file mode 100644 index b189d0f483..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.baeldung.kotlin - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class GenericsTest { - - @Test - fun givenParametrizeClass_whenInitializeItWithSpecificType_thenShouldBeParameterized() { - //given - val parameterizedClass = ParameterizedClass("string-value") - - //when - val res = parameterizedClass.getValue() - - //then - assertTrue(res is String) - } - - @Test - fun givenParametrizeClass_whenInitializeIt_thenShouldBeParameterizedByInferredType() { - //given - val parameterizedClass = ParameterizedClass("string-value") - - //when - val res = parameterizedClass.getValue() - - //then - assertTrue(res is String) - } - - @Test - fun givenParameterizedProducerByOutKeyword_whenGetValue_thenCanAssignItToSuperType() { - //given - val parameterizedProducer = ParameterizedProducer("string") - - //when - val ref: ParameterizedProducer = parameterizedProducer - - //then - assertTrue(ref is ParameterizedProducer) - } - - @Test - fun givenParameterizedConsumerByInKeyword_whenGetValue_thenCanAssignItToSubType() { - //given - val parameterizedConsumer = ParameterizedConsumer() - - //when - val ref: ParameterizedConsumer = parameterizedConsumer - - //then - assertTrue(ref is ParameterizedConsumer) - } - - @Test - fun givenTypeProjections_whenOperateOnTwoList_thenCanAcceptListOfSubtypes() { - //given - val ints: Array = arrayOf(1, 2, 3) - val any: Array = arrayOfNulls(3) - - //when - copy(ints, any) - - //then - assertEquals(any[0], 1) - assertEquals(any[1], 2) - assertEquals(any[2], 3) - - } - - fun copy(from: Array, to: Array) { - assert(from.size == to.size) - for (i in from.indices) - to[i] = from[i] - } - - @Test - fun givenTypeProjection_whenHaveArrayOfIn_thenShouldAddElementsOfSubtypesToIt() { - //given - val objects: Array = arrayOfNulls(1) - - //when - fill(objects, 1) - - //then - assertEquals(objects[0], 1) - } - - fun fill(dest: Array, value: Int) { - dest[0] = value - } - - @Test - fun givenStartProjection_whenPassAnyType_thenCompile() { - //given - val array = arrayOf(1,2,3) - - //then - printArray(array) - - } - - fun printArray(array: Array<*>) { - array.forEach { println(it) } - } - - @Test - fun givenFunctionWithDefinedGenericConstraints_whenCallWithProperType_thenCompile(){ - //given - val listOfInts = listOf(5,2,3,4,1) - - //when - val sorted = sort(listOfInts) - - //then - assertEquals(sorted, listOf(1,2,3,4,5)) - } - - fun > sort(list: List): List{ - return list.sorted() - } - - class ParameterizedClass(private val value: A) { - - fun getValue(): A { - return value - } - } - - class ParameterizedProducer(private val value: T) { - fun get(): T { - return value - } - } - - class ParameterizedConsumer { - fun toString(value: T): String { - return value.toString() - } - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt deleted file mode 100644 index fc50730dfa..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.kotlin.delegates - -import org.junit.Test -import kotlin.test.assertEquals - -class DatabaseDelegatesTest { - @Test - fun testGetKnownFields() { - val user = User(1) - assertEquals("George", user.name) - assertEquals(4, user.age) - } - - @Test - fun testSetKnownFields() { - val user = User(2) - user.age = 3 - assertEquals(3, user.age) - } - - @Test(expected = NoRecordFoundException::class) - fun testGetKnownField() { - val user = User(3) - user.name - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt deleted file mode 100644 index 2959ea0e3c..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DelegateProviderTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.kotlin.delegates - -import org.junit.Test -import kotlin.properties.PropertyDelegateProvider -import kotlin.reflect.KProperty -import kotlin.test.assertEquals - -class DelegateProvider(private val field: String, private val id: Int) - : PropertyDelegateProvider> { - override operator fun provideDelegate(thisRef: T, prop: KProperty<*>): DatabaseDelegate { - println("Providing delegate for field $field and ID $id") - prop.returnType.isMarkedNullable - return DatabaseDelegate(field, id) - } -} - -class DelegateProvidingUser(val id: Int) { - var name: String by DelegateProvider("name", id) - var age: Int by DelegateProvider("age", id) -} - -class DelegateProviderTest { - @Test - fun testGetKnownFields() { - val user = DelegateProvidingUser(1) - assertEquals("George", user.name) - assertEquals(4, user.age) - } - - @Test - fun testSetKnownFields() { - val user = DelegateProvidingUser(2) - user.age = 3 - assertEquals(3, user.age) - } - - @Test(expected = NoRecordFoundException::class) - fun testGetKnownField() { - val user = DelegateProvidingUser(3) - user.name - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt deleted file mode 100644 index e65032acd4..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.kotlin.delegates - -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test - -class InterfaceDelegationTest { - - @Test - fun `when delegated implementation is used then it works as expected`() { - val producer = EnhancedProducer(ProducerImpl()) - assertThat(producer.produce()).isEqualTo("ProducerImpl and EnhancedProducer") - } - - @Test - fun `when composite delegation is used then it works as expected`() { - val service = CompositeService() - assertThat(service.processMessage("message")).isEqualTo("MessageServiceImpl: message") - assertThat(service.processUser("user")).isEqualTo("UserServiceImpl: user") - } - - @Test - fun `when decoration is used then delegate knows nothing about it`() { - val service = ServiceDecorator() - service.serve { - assertThat(it).isEqualTo(1) - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/README.md b/core-kotlin-modules/core-kotlin-lang-oop/README.md deleted file mode 100644 index 0c1aeb7850..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/README.md +++ /dev/null @@ -1,17 +0,0 @@ -## Core Kotlin Lang OOP - -This module contains articles about Object-Oriented Programming in Kotlin - -### Relevant articles: - -- [Data Classes in Kotlin](https://www.baeldung.com/kotlin-data-classes) -- [Sealed Classes in Kotlin](https://www.baeldung.com/kotlin-sealed-classes) -- [Extension Methods in Kotlin](https://www.baeldung.com/kotlin-extension-methods) -- [Objects in Kotlin](https://www.baeldung.com/kotlin-objects) -- [Working with Enums in Kotlin](https://www.baeldung.com/kotlin-enum) -- [Kotlin Constructors](https://www.baeldung.com/kotlin-constructors) -- [Kotlin Nested and Inner Classes](https://www.baeldung.com/kotlin-inner-classes) -- [Guide to Kotlin Interfaces](https://www.baeldung.com/kotlin-interfaces) -- [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes) -- [Static Methods Behavior in Kotlin](https://www.baeldung.com/kotlin-static-methods) -- More articles: [[next -->]](/core-kotlin-modules/core-kotlin-lang-oop-2) diff --git a/core-kotlin-modules/core-kotlin-lang-oop/pom.xml b/core-kotlin-modules/core-kotlin-lang-oop/pom.xml deleted file mode 100644 index 03fc80f07d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - core-kotlin-lang-oop - core-kotlin-lang-oop - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.assertj - assertj-core - ${assertj.version} - test - - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt deleted file mode 100644 index 72b8d330e8..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.constructor - -class Car { - val id: String - val type: String - - constructor(id: String, type: String) { - this.id = id - this.type = type - } - -} - -fun main(args: Array) { - val car = Car("1", "sport") - val s= Car("2", "suv") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt deleted file mode 100644 index 4483bfcf08..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.constructor - -class Employee(name: String, val salary: Int): Person(name) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java deleted file mode 100644 index 57911b24ee..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.constructor; - -class PersonJava { - final String name; - final String surname; - final Integer age; - - public PersonJava(String name, String surname) { - this.name = name; - this.surname = surname; - this.age = null; - } - - public PersonJava(String name, String surname, Integer age) { - this.name = name; - this.surname = surname; - this.age = age; - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java deleted file mode 100644 index 7eac98fe2a..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.baeldung.dataclass; - -public class Movie { - - private String name; - private String studio; - private float rating; - - public Movie(String name, String studio, float rating) { - this.name = name; - this.studio = studio; - this.rating = rating; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getStudio() { - return studio; - } - - public void setStudio(String studio) { - this.studio = studio; - } - - public float getRating() { - return rating; - } - - public void setRating(float rating) { - this.rating = rating; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + Float.floatToIntBits(rating); - result = prime * result + ((studio == null) ? 0 : studio.hashCode()); - - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - - if (obj == null) - return false; - - if (getClass() != obj.getClass()) - return false; - - Movie other = (Movie) obj; - - if (name == null) { - if (other.name != null) - return false; - - } else if (!name.equals(other.name)) - return false; - - if (Float.floatToIntBits(rating) != Float.floatToIntBits(other.rating)) - return false; - - if (studio == null) { - if (other.studio != null) - return false; - - } else if (!studio.equals(other.studio)) - return false; - - return true; - } - - @Override - public String toString() { - return "Movie [name=" + name + ", studio=" + studio + ", rating=" + rating + "]"; - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt deleted file mode 100644 index 3779d74541..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.constructor - -open class Person( - val name: String, - val age: Int? = null -) { - val upperCaseName: String = name.toUpperCase() - - init { - println("Hello, I'm $name") - - if (age != null && age < 0) { - throw IllegalArgumentException("Age cannot be less than zero!") - } - } - - init { - println("upperCaseName is $upperCaseName") - } - -} - -fun main(args: Array) { - val person = Person("John") - val personWithAge = Person("John", 22) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt deleted file mode 100644 index c0c15b2516..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.dataclass - -data class Movie(val name: String, val studio: String, var rating: Float) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt deleted file mode 100644 index d47909bf29..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.dataclass - -fun main(args: Array) { - - val movie = Movie("Whiplash", "Sony Pictures", 8.5F) - - println(movie.name) //Whiplash - println(movie.studio) //Sony Pictures - println(movie.rating) //8.5 - - movie.rating = 9F - - println(movie.toString()) //Movie(name=Whiplash, studio=Sony Pictures, rating=9.0) - - val betterRating = movie.copy(rating = 9.5F) - println(betterRating.toString()) //Movie(name=Whiplash, studio=Sony Pictures, rating=9.5) - - movie.component1() //name - movie.component2() //studio - movie.component3() //rating - - val(name, studio, rating) = movie - - fun getMovieInfo() = movie - val(namef, studiof, ratingf) = getMovieInfo() -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt deleted file mode 100644 index 69cfce5601..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.enums - -enum class CardType(val color: String) : ICardLimit { - SILVER("gray") { - override fun getCreditLimit() = 100000 - override fun calculateCashbackPercent() = 0.25f - }, - GOLD("yellow") { - override fun getCreditLimit() = 200000 - override fun calculateCashbackPercent(): Float = 0.5f - }, - PLATINUM("black") { - override fun getCreditLimit() = 300000 - override fun calculateCashbackPercent() = 0.75f - }; - - companion object { - fun getCardTypeByColor(color: String) = values().firstOrNull { it.color == color } - fun getCardTypeByName(name: String) = valueOf(name.toUpperCase()) - } - - abstract fun calculateCashbackPercent(): Float -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt deleted file mode 100644 index 7994822a52..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.enums - -interface ICardLimit { - fun getCreditLimit(): Int -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt deleted file mode 100644 index 5b46b9570f..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.inline.classes - -interface Drawable { - fun draw() -} - -inline class CircleRadius(private val circleRadius : Double) : Drawable { - val diameterOfCircle get() = 2 * circleRadius - fun areaOfCircle() = 3.14 * circleRadius * circleRadius - - override fun draw() { - println("Draw my circle") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt deleted file mode 100644 index 430fa509da..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.inline.classes - -inline class InlineDoubleWrapper(val doubleValue : Double) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt deleted file mode 100644 index 630afbdae7..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.interfaces - -interface BaseInterface { - fun someMethod(): String -} - -interface FirstChildInterface : BaseInterface { - override fun someMethod(): String { - return("Hello, from someMethod in FirstChildInterface") - } -} - -interface SecondChildInterface : BaseInterface { - override fun someMethod(): String { - return("Hello, from someMethod in SecondChildInterface") - } -} - -class ChildClass : FirstChildInterface, SecondChildInterface { - override fun someMethod(): String { - return super.someMethod() - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt deleted file mode 100644 index 591fde0689..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.interfaces - -interface MyInterface { - fun someMethod(): String -} - -class MyClass() : MyInterface { - override fun someMethod(): String { - return("Hello, World!") - } -} - -class MyDerivedClass(myInterface: MyInterface) : MyInterface by myInterface \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt deleted file mode 100644 index 105a85cbb3..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.interfaces - -interface FirstInterface { - fun someMethod(): String - - fun anotherMethod(): String { - return("Hello, from anotherMethod in FirstInterface") - } -} - -interface SecondInterface { - fun someMethod(): String { - return("Hello, from someMethod in SecondInterface") - } - - fun anotherMethod(): String { - return("Hello, from anotherMethod in SecondInterface") - } -} - -class SomeClass: FirstInterface, SecondInterface { - override fun someMethod(): String { - return("Hello, from someMethod in SomeClass") - } - - override fun anotherMethod(): String { - return("Hello, from anotherMethod in SomeClass") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt deleted file mode 100644 index 0758549dde..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.interfaces - -interface SimpleInterface { - val firstProp: String - val secondProp: String - get() = "Second Property" - fun firstMethod(): String - fun secondMethod(): String { - println("Hello, from: " + secondProp) - return "" - } -} - -class SimpleClass: SimpleInterface { - override val firstProp: String = "First Property" - override val secondProp: String - get() = "Second Property, Overridden!" - override fun firstMethod(): String { - return("Hello, from: " + firstProp) - } - override fun secondMethod(): String { - return("Hello, from: " + secondProp + firstProp) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt deleted file mode 100644 index 96e54716b3..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.kotlin - -sealed class Result { - abstract fun map(func: (S) -> R) : Result - abstract fun mapFailure(func: (F) -> R) : Result - abstract fun get() : S? -} - -data class Success(val success: S) : Result() { - override fun map(func: (S) -> R) : Result = Success(func(success)) - override fun mapFailure(func: (F) -> R): Result = Success(success) - override fun get(): S? = success -} - -data class Failure(val failure: F) : Result() { - override fun map(func: (S) -> R) : Result = Failure(failure) - override fun mapFailure(func: (F) -> R): Result = Failure(func(failure)) - override fun get(): S? = null -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt deleted file mode 100644 index ca57b2965e..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt +++ /dev/null @@ -1,9 +0,0 @@ -@file:JvmName("Strings") -package com.baeldung.kotlin - -fun String.escapeForXml() : String { - return this - .replace("&", "&") - .replace("<", "<") - .replace(">", ">") -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt deleted file mode 100644 index ee01c06646..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.nested - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -class Computer(val model: String) { - - companion object { - const val originCountry = "China" - fun getBuiltDate(): String { - return "2018-05-23" - } - - val log: Logger = LoggerFactory.getLogger(Computer::class.java) - } - - //Nested class - class MotherBoard(val manufacturer: String) { - fun getInfo() = "Made by $manufacturer installed in $originCountry - ${getBuiltDate()}" - } - - //Inner class - inner class HardDisk(val sizeInGb: Int) { - fun getInfo() = "Installed on ${this@Computer} with $sizeInGb GB" - } - - interface Switcher { - fun on(): String - } - - interface Protector { - fun smart() - } - - fun powerOn(): String { - //Local class - var defaultColor = "Blue" - - class Led(val color: String) { - fun blink(): String { - return "blinking $color" - } - - fun changeDefaultPowerOnColor() { - defaultColor = "Violet" - } - } - - val powerLed = Led("Green") - log.debug("defaultColor is $defaultColor") - powerLed.changeDefaultPowerOnColor() - log.debug("defaultColor changed inside Led class to $defaultColor") - //Anonymous object - val powerSwitch = object : Switcher, Protector { - override fun on(): String { - return powerLed.blink() - } - - override fun smart() { - log.debug("Smart protection is implemented") - } - - fun changeDefaultPowerOnColor() { - defaultColor = "Yellow" - } - } - powerSwitch.changeDefaultPowerOnColor() - log.debug("defaultColor changed inside powerSwitch anonymous object to $defaultColor") - return powerSwitch.on() - } - - override fun toString(): String { - return "Computer(model=$model)" - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt deleted file mode 100644 index 23c7cfb11a..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.static - -class ConsoleUtils { - companion object { - @JvmStatic - fun debug(debugMessage : String) { - println("[DEBUG] $debugMessage") - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt deleted file mode 100644 index e67addc9ea..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.static - -fun debug(debugMessage : String) { - println("[DEBUG] $debugMessage") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java b/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java deleted file mode 100644 index c7ef18b879..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.kotlin; - -import kotlin.text.StringsKt; -import org.junit.Assert; -import org.junit.Test; - -import static com.baeldung.kotlin.Strings.*; - - -public class StringUtilUnitTest { - - @Test - public void shouldEscapeXmlTagsInString() { - String xml = "hi"; - - String escapedXml = escapeForXml(xml); - - Assert.assertEquals("<a>hi</a>", escapedXml); - } - - @Test - public void callingBuiltInKotlinExtensionMethod() { - String name = "john"; - - String capitalizedName = StringsKt.capitalize(name); - - Assert.assertEquals("John", capitalizedName); - } - -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt deleted file mode 100644 index 525faebd55..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.baeldung.enums - -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -internal class CardTypeUnitTest { - - @Test - fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { - assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent()) - } - - @Test - fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { - assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent()) - } - - @Test - fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() { - assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent()) - } - - @Test - fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() { - assertEquals(100000, CardType.SILVER.getCreditLimit()) - } - - @Test - fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() { - assertEquals(200000, CardType.GOLD.getCreditLimit()) - } - - @Test - fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() { - assertEquals(300000, CardType.PLATINUM.getCreditLimit()) - } - - @Test - fun givenSilverCardType_whenCheckColor_thenReturnColor() { - assertEquals("gray", CardType.SILVER.color) - } - - @Test - fun givenGoldCardType_whenCheckColor_thenReturnColor() { - assertEquals("yellow", CardType.GOLD.color) - } - - @Test - fun givenPlatinumCardType_whenCheckColor_thenReturnColor() { - assertEquals("black", CardType.PLATINUM.color) - } - - @Test - fun whenGetCardTypeByColor_thenSilverCardType() { - Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByColor("gray")) - } - - @Test - fun whenGetCardTypeByColor_thenGoldCardType() { - Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByColor("yellow")) - } - - @Test - fun whenGetCardTypeByColor_thenPlatinumCardType() { - Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByColor("black")) - } - - @Test - fun whenGetCardTypeByName_thenSilverCardType() { - Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByName("silver")) - } - - @Test - fun whenGetCardTypeByName_thenGoldCardType() { - Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByName("gold")) - } - - @Test - fun whenGetCardTypeByName_thenPlatinumCardType() { - Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByName("platinum")) - } - -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt deleted file mode 100644 index 8de378b6dd..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.inline.classes - -import org.junit.Test -import kotlin.test.assertEquals - -class CircleRadiusTest { - - @Test - fun givenRadius_ThenDiameterIsCorrectlyCalculated() { - val radius = CircleRadius(5.0) - assertEquals(10.0, radius.diameterOfCircle) - } - - @Test - fun givenRadius_ThenAreaIsCorrectlyCalculated() { - val radius = CircleRadius(5.0) - assertEquals(78.5, radius.areaOfCircle()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt deleted file mode 100644 index 349c90d6f4..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.inline.classes - -import org.junit.Test -import kotlin.test.assertEquals - -class InlineDoubleWrapperTest { - - @Test - fun whenInclineClassIsUsed_ThenPropertyIsReadCorrectly() { - val piDoubleValue = InlineDoubleWrapper(3.14) - assertEquals(3.14, piDoubleValue.doubleValue) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt deleted file mode 100644 index 96b99948b7..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.interfaces - -import org.junit.Test -import kotlin.test.assertEquals - -class InterfaceExamplesUnitTest { - @Test - fun givenAnInterface_whenImplemented_thenBehavesAsOverridden() { - val simpleClass = SimpleClass() - assertEquals("Hello, from: First Property", simpleClass.firstMethod()) - assertEquals("Hello, from: Second Property, Overridden!First Property", simpleClass.secondMethod()) - } - - @Test - fun givenMultipleInterfaces_whenImplemented_thenBehavesAsOverridden() { - val someClass = SomeClass() - assertEquals("Hello, from someMethod in SomeClass", someClass.someMethod()) - assertEquals("Hello, from anotherMethod in SomeClass", someClass.anotherMethod()) - } - - @Test - fun givenConflictingInterfaces_whenImplemented_thenBehavesAsOverridden() { - val childClass = ChildClass() - assertEquals("Hello, from someMethod in SecondChildInterface", childClass.someMethod()) - } - - @Test - fun givenAnInterface_whenImplemented_thenBehavesAsDelegated() { - val myClass = MyClass() - assertEquals("Hello, World!", MyDerivedClass(myClass).someMethod()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt deleted file mode 100644 index 44c5cd0ece..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.kotlin - -import org.junit.Assert -import org.junit.Test - -class ExtensionMethods { - @Test - fun simpleExtensionMethod() { - Assert.assertEquals("Nothing", "Nothing".escapeForXml()) - Assert.assertEquals("<Tag>", "".escapeForXml()) - Assert.assertEquals("a&b", "a&b".escapeForXml()) - } - - @Test - fun genericExtensionMethod() { - fun T.concatAsString(b: T) : String { - return this.toString() + b.toString() - } - - Assert.assertEquals("12", "1".concatAsString("2")) - Assert.assertEquals("12", 1.concatAsString(2)) - // This doesn't compile - // Assert.assertEquals("12", 1.concatAsString(2.0)) - } - - @Test - fun infixExtensionMethod() { - infix fun Number.toPowerOf(exponent: Number): Double { - return Math.pow(this.toDouble(), exponent.toDouble()) - } - - Assert.assertEquals(9.0, 3 toPowerOf 2, 0.1) - Assert.assertEquals(3.0, 9 toPowerOf 0.5, 0.1) - } - - @Test - fun operatorExtensionMethod() { - operator fun List.times(by: Int): List { - return this.map { it * by } - } - - Assert.assertEquals(listOf(2, 4, 6), listOf(1, 2, 3) * 2) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt deleted file mode 100644 index 8c7509f653..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.baeldung.kotlin - -import org.junit.Assert -import org.junit.Test - -class SealedTest { - fun divide(a: Int, b: Int) : Result = when (b) { - 0 -> Failure("Division by zero") - else -> Success(a.toFloat() / b) - } - - @Test - fun testSuccess() { - val result = divide(10, 5) - Assert.assertEquals(Success(2.0f), result) - } - - @Test - fun testError() { - val result = divide(10, 0) - Assert.assertEquals(Failure("Division by zero"), result) - } - - @Test - fun testMatchOnSuccess() { - val result = divide(10, 5) - when (result) { - is Success -> { - // Expected - } - is Failure -> Assert.fail("Expected Success") - } - } - - @Test - fun testMatchOnError() { - val result = divide(10, 0) - when (result) { - is Failure -> { - // Expected - } - } - } - - @Test - fun testGetSuccess() { - val result = divide(10, 5) - Assert.assertEquals(2.0f, result.get()) - } - - @Test - fun testGetError() { - val result = divide(10, 0) - Assert.assertNull(result.get()) - } - - @Test - fun testMapOnSuccess() { - val result = divide(10, 5) - .map { "Result: $it" } - Assert.assertEquals(Success("Result: 2.0"), result) - } - - @Test - fun testMapOnError() { - val result = divide(10, 0) - .map { "Result: $it" } - Assert.assertEquals(Failure("Division by zero"), result) - } - - @Test - fun testMapFailureOnSuccess() { - val result = divide(10, 5) - .mapFailure { "Failure: $it" } - Assert.assertEquals(Success(2.0f), result) - } - - @Test - fun testMapFailureOnError() { - val result = divide(10, 0) - .mapFailure { "Failure: $it" } - Assert.assertEquals(Failure("Failure: Division by zero"), result) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt deleted file mode 100644 index 46ba42e1e5..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.kotlin.objects - -object Counter { - private var count: Int = 0 - - fun currentCount() = count - - fun increment() { - ++count - } - - fun decrement() { - --count - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt deleted file mode 100644 index 0bbb1c741d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.kotlin.objects - -import org.junit.Assert -import org.junit.Test - -class ObjectsTest { - @Test - fun singleton() { - - Assert.assertEquals(42, SimpleSingleton.answer) - Assert.assertEquals("Hello, world!", SimpleSingleton.greet("world")) - } - - @Test - fun counter() { - Assert.assertEquals(0, Counter.currentCount()) - Counter.increment() - Assert.assertEquals(1, Counter.currentCount()) - Counter.decrement() - Assert.assertEquals(0, Counter.currentCount()) - } - - @Test - fun comparator() { - val strings = listOf("Hello", "World") - val sortedStrings = strings.sortedWith(ReverseStringComparator) - - Assert.assertEquals(listOf("World", "Hello"), sortedStrings) - } - - @Test - fun companion() { - Assert.assertEquals("You can see me", OuterClass.public) - // Assert.assertEquals("You can't see me", OuterClass.secret) // Cannot access 'secret' - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt deleted file mode 100644 index 4abb7a668d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.kotlin.objects - -class OuterClass { - companion object { - private val secret = "You can't see me" - val public = "You can see me" - } - - fun getSecretValue() = secret -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt deleted file mode 100644 index 20dc2d8c5b..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.kotlin.objects - -object ReverseStringComparator : Comparator { - override fun compare(o1: String, o2: String) = o1.reversed().compareTo(o2.reversed()) -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt deleted file mode 100644 index bfafd8183f..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.kotlin.objects - -object SimpleSingleton { - val answer = 42; - - fun greet(name: String) = "Hello, $name!" -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt deleted file mode 100644 index 36cd476110..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.kotlin.objects - -class StaticClass { - companion object { - @JvmStatic - val staticField = 42 - } -} diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt deleted file mode 100644 index 7882d85b3c..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.nested - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -class ComputerUnitTest { - - @Test - fun givenComputer_whenPowerOn_thenBlink() { - val computer = Computer("Desktop") - - assertThat(computer.powerOn()).isEqualTo("blinking Green") - } - - @Test - fun givenMotherboard_whenGetInfo_thenGetInstalledAndBuiltDetails() { - val motherBoard = Computer.MotherBoard("MotherBoard Inc.") - - assertThat(motherBoard.getInfo()).isEqualTo("Made by MotherBoard Inc. installed in China - 2018-05-23") - } - - @Test - fun givenHardDisk_whenGetInfo_thenGetComputerModelAndDiskSizeInGb() { - val hardDisk = Computer("Desktop").HardDisk(1000) - - assertThat(hardDisk.getInfo()).isEqualTo("Installed on Computer(model=Desktop) with 1000 GB") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt deleted file mode 100644 index 8abed144eb..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.static - -import org.junit.Test - -class ConsoleUtilsUnitTest { - @Test - fun givenAStaticMethod_whenCalled_thenNoErrorIsThrown() { - ConsoleUtils.debug("test message") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt deleted file mode 100644 index 59587ff009..0000000000 --- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.static - -import org.junit.Test - -class LoggingUtilsUnitTest { - @Test - fun givenAPackageMethod_whenCalled_thenNoErrorIsThrown() { - debug("test message") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/README.md b/core-kotlin-modules/core-kotlin-lang/README.md deleted file mode 100644 index eaeae76854..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Core Kotlin Lang - -This module contains articles about core features in the Kotlin language. - -### Relevant articles: -- [Guide to the “when{}” Block in Kotlin](https://www.baeldung.com/kotlin-when) -- [Difference Between “==” and “===” Operators in Kotlin](https://www.baeldung.com/kotlin-equality-operators) -- [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach) -- [Destructuring Declarations in Kotlin](https://www.baeldung.com/kotlin-destructuring-declarations) -- [Try-with-resources in Kotlin](https://www.baeldung.com/kotlin-try-with-resources) -- [Operator Overloading in Kotlin](https://www.baeldung.com/kotlin-operator-overloading) -- [Inline Functions in Kotlin](https://www.baeldung.com/kotlin-inline-functions) -- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type) -- [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges) -- [Creating a Kotlin Range Iterator on a Custom Object](https://www.baeldung.com/kotlin-custom-range-iterator) -- [[More --> ]](/core-kotlin-modules/core-kotlin-lang-2) diff --git a/core-kotlin-modules/core-kotlin-lang/pom.xml b/core-kotlin-modules/core-kotlin-lang/pom.xml deleted file mode 100644 index d3ac7f690c..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - core-kotlin-lang - core-kotlin-lang - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt deleted file mode 100644 index d3167ce033..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.destructuringdeclarations - -data class Person(var id: Int, var name: String, var age: Int) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt deleted file mode 100644 index e3da9b46a4..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.destructuringdeclarations - -data class Result(val result: Int, val status: String) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt deleted file mode 100644 index f845d01539..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.destructuringdeclarations - -fun main(args: Array) { - - //2.1. Objects - val person = Person(1, "Jon Snow", 20) - val(id, name, age) = person - - println(id) //1 - println(name) //Jon Snow - println(age) //20 - - //2.2. Functions - fun getPersonInfo() = Person(2, "Ned Stark", 45) - val(idf, namef, agef) = getPersonInfo() - - fun twoValuesReturn(): Pair { - - // needed code - - return Pair(1, "success") - } - - // Now, to use this function: - val (result, status) = twoValuesReturn() - - //2.3. Collections and For-loops - var map: HashMap = HashMap() - map.put(1, person) - - for((key, value) in map){ - println("Key: $key, Value: $value") - } - - //2.4. Underscore and Destructuring in Lambdas - val (_, name2, age2) = person - val (id3, name3) = person - - map.mapValues { entry -> "${entry.value}!" } - map.mapValues { (key, value) -> "$value!" } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt deleted file mode 100644 index 030169bb8a..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.equalityoperators - -data class User(val name: String, val age: Int, val hobbies: List) diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt deleted file mode 100644 index 20eda4e64f..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.forEach - - -class Country(val name : String, val cities : List) - -class City(val name : String, val streets : List) - -fun City.getStreetsWithCityName() : List { - return streets.map { "$name, $it" }.toList() -} - -fun Country.getCitiesWithCountryName() : List { - return cities.flatMap { it.getStreetsWithCityName() } - .map { "$name, $it" } -} - -class World { - - private val streetsOfAmsterdam = listOf("Herengracht", "Prinsengracht") - private val streetsOfBerlin = listOf("Unter den Linden","Tiergarten") - private val streetsOfMaastricht = listOf("Grote Gracht", "Vrijthof") - private val countries = listOf( - Country("Netherlands", listOf(City("Maastricht", streetsOfMaastricht), - City("Amsterdam", streetsOfAmsterdam))), - Country("Germany", listOf(City("Berlin", streetsOfBerlin)))) - - fun allCountriesIt() { - countries.forEach { println(it.name) } - } - - fun allCountriesItExplicit() { - countries.forEach { it -> println(it.name) } - } - - //here we cannot refer to 'it' anymore inside the forEach - fun allCountriesExplicit() { - countries.forEach { c -> println(c.name) } - } - - fun allNested() { - countries.forEach { - println(it.name) - it.cities.forEach { - println(" ${it.name}") - it.streets.forEach { println(" $it") } - } - } - } - - fun allTable() { - countries.forEach { c -> - c.cities.forEach { p -> - p.streets.forEach { println("${c.name} ${p.name} $it") } - } - } - } - - fun allStreetsFlatMap() { - - countries.flatMap { it.cities} - .flatMap { it.streets} - .forEach { println(it) } - } - - fun allFlatMapTable() { - - countries.flatMap { it.getCitiesWithCountryName() } - .forEach { println(it) } - } -} - -fun main(args : Array) { - - val world = World() - - world.allCountriesExplicit() - - world.allNested() - - world.allTable() - - world.allStreetsFlatMap() - - world.allFlatMapTable() -} - - diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt deleted file mode 100644 index 3b179642ba..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.inline - -import kotlin.random.Random - -/** - * An extension function on all collections to apply a function to all collection - * elements. - */ -fun Collection.each(block: (T) -> Unit) { - for (e in this) block(e) -} - -/** - * In order to see the the JVM bytecode: - * 1. Compile the Kotlin file using `kotlinc Inline.kt` - * 2. Take a peek at the bytecode using the `javap -c InlineKt` - */ -fun main() { - val numbers = listOf(1, 2, 3, 4, 5) - val random = random() - - numbers.each { println(random * it) } // capturing the random variable -} - -/** - * Generates a random number. - */ -private fun random(): Int = Random.nextInt() \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt deleted file mode 100644 index 93eb78c5b6..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.operators - -import java.math.BigDecimal - -enum class Currency { - DOLLARS, EURO -} - -class Money(val amount: BigDecimal, val currency: Currency) : Comparable { - - override fun compareTo(other: Money): Int = - convert(Currency.DOLLARS).compareTo(other.convert(Currency.DOLLARS)) - - fun convert(currency: Currency): BigDecimal = TODO() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Money) return false - - if (amount != other.amount) return false - if (currency != other.currency) return false - - return true - } - - override fun hashCode(): Int { - var result = amount.hashCode() - result = 31 * result + currency.hashCode() - return result - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt deleted file mode 100644 index 8a0ee48a36..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.operators - -interface Page { - fun pageNumber(): Int - fun pageSize(): Int - fun elements(): MutableList -} - -operator fun Page.invoke(index: Int): T = elements()[index] -operator fun Page.get(index: Int): T = elements()[index] -operator fun Page.get(start: Int, endExclusive: Int): List = elements().subList(start, endExclusive) -operator fun Page.set(index: Int, value: T) { - elements()[index] = value -} - -operator fun Page.contains(element: T): Boolean = element in elements() -operator fun Page.iterator() = elements().iterator() \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Point.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Point.kt deleted file mode 100644 index e3282e64cc..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Point.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.operators - -data class Point(val x: Int, val y: Int) - -operator fun Point.unaryMinus() = Point(-x, -y) -operator fun Point.not() = Point(y, x) -operator fun Point.inc() = Point(x + 1, y + 1) -operator fun Point.dec() = Point(x - 1, y - 1) - -operator fun Point.plus(other: Point): Point = Point(x + other.x, y + other.y) -operator fun Point.minus(other: Point): Point = Point(x - other.x, y - other.y) -operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y) -operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y) -operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y) -operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor) -operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) - -class Shape { - val points = mutableListOf() - - operator fun Point.unaryPlus() { - points.add(this) - } -} - -fun shape(init: Shape.() -> Unit): Shape { - val shape = Shape() - shape.init() - - return shape -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Utils.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Utils.kt deleted file mode 100644 index 0f16544f38..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Utils.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.operators - -import java.math.BigInteger - -operator fun MutableCollection.plusAssign(element: T) { - add(element) -} -operator fun BigInteger.plus(other: Int): BigInteger = add(BigInteger("$other")) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/CharRange.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/CharRange.kt deleted file mode 100644 index 3151674d61..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/CharRange.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - for (ch in 'a'..'f') { - print(ch) - } - println() - - for (ch in 'f' downTo 'a') { - print(ch) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Color.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Color.kt deleted file mode 100644 index ef7adf06b5..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Color.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.range - -enum class Color(val rgb: Int) { - BLUE(0x0000FF), - GREEN(0x008000), - RED(0xFF0000), - MAGENTA(0xFF00FF), - YELLOW(0xFFFF00); -} - -fun main(args: Array) { - - println(Color.values().toList()); - val red = Color.RED - val yellow = Color.YELLOW - val range = red..yellow - - println(range.contains(Color.MAGENTA)) - println(range.contains(Color.BLUE)) - println(range.contains(Color.GREEN)) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Filter.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Filter.kt deleted file mode 100644 index 0e611b14cf..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Filter.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - val r = 1..10 - - //Apply filter - val f = r.filter { it -> it % 2 == 0 } - println(f) - - //Map - val m = r.map { it -> it * it } - println(m) - - //Reduce - val rdc = r.reduce { a, b -> a + b } - println(rdc) - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/FirstLast.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/FirstLast.kt deleted file mode 100644 index b82f5a8b9b..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/FirstLast.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - println((1..9).first) - println((1..9 step 2).step) - println((3..9).reversed().last) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/OtherRangeFunctions.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/OtherRangeFunctions.kt deleted file mode 100644 index 19dcab89b2..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/OtherRangeFunctions.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - val r = 1..20 - println(r.min()) - println(r.max()) - println(r.sum()) - println(r.average()) - println(r.count()) - - val repeated = listOf(1, 1, 2, 4, 4, 6, 10) - println(repeated.distinct()) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Range.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Range.kt deleted file mode 100644 index c313181599..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Range.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - for (i in 1..9) { - print(i) - } - println() - - for (i in 9 downTo 1) { - print(i) - } - println() - - for (i in 1.rangeTo(9)) { - print(i) - } - println() - - for (i in 9.downTo(1)) { - print(i) - } - println() - - for (i in 1 until 9) { - print(i) - } -} diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/ReverseRange.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/ReverseRange.kt deleted file mode 100644 index 875cf62200..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/ReverseRange.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - (1..9).reversed().forEach { - print(it) - } - - println() - - (1..9).reversed().step(3).forEach { - print(it) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Step.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Step.kt deleted file mode 100644 index b9c5d48588..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/Step.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - for(i in 1..9 step 2){ - print(i) - } - - println() - - for (i in 9 downTo 1 step 2){ - print(i) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/UntilRange.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/UntilRange.kt deleted file mode 100644 index 2c116a286f..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/range/UntilRange.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.range - -fun main(args: Array) { - - for (i in 1 until 9) { - print(i) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/rangeiterator/CustomColor.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/rangeiterator/CustomColor.kt deleted file mode 100644 index c1ab8e1610..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/rangeiterator/CustomColor.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.rangeiterator - -import java.lang.IllegalStateException - -class CustomColor(val rgb: Int): Comparable { - - override fun compareTo(other: CustomColor): Int { - return this.rgb.compareTo(other.rgb) - } - - operator fun rangeTo(that: CustomColor) = ColorRange(this, that) - - operator fun inc(): CustomColor { - return CustomColor(rgb + 1) - } - - init { - if(rgb < 0x000000 || rgb > 0xFFFFFF){ - throw IllegalStateException("RGB must be between 0 and 16777215") - } - } - - override fun toString(): String { - return "CustomColor(rgb=$rgb)" - } -} -class ColorRange(override val start: CustomColor, - override val endInclusive: CustomColor) : ClosedRange, Iterable{ - - override fun iterator(): Iterator { - return ColorIterator(start, endInclusive) - } -} - -class ColorIterator(val start: CustomColor, val endInclusive: CustomColor) : Iterator { - - var initValue = start - - override fun hasNext(): Boolean { - return initValue <= endInclusive - } - - override fun next(): CustomColor { - return initValue++ - } -} - -fun main(args: Array) { - val a = CustomColor(0xABCDEF) - val b = CustomColor(-1) - val c = CustomColor(0xABCDFF) - - for(color in a..c){ - println(color) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/whenblock/WhenBlockTypes.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/whenblock/WhenBlockTypes.kt deleted file mode 100644 index a4cd7b98f0..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/whenblock/WhenBlockTypes.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.whenblock - -enum class UnixFileType { - D, HYPHEN_MINUS, L -} - -sealed class UnixFile { - - abstract fun getFileType(): UnixFileType - - class RegularFile(val content: String) : UnixFile() { - override fun getFileType(): UnixFileType { - return UnixFileType.HYPHEN_MINUS - } - } - - class Directory(val children: List) : UnixFile() { - override fun getFileType(): UnixFileType { - return UnixFileType.D - } - } - - class SymbolicLink(val originalFile: UnixFile) : UnixFile() { - override fun getFileType(): UnixFileType { - return UnixFileType.L - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/equalityoperators/EqualityTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/equalityoperators/EqualityTest.kt deleted file mode 100644 index 0728d55b73..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/equalityoperators/EqualityTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.equalityoperators - -import org.junit.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class EqualityTest { - - // Checks referential equality - @Test - fun givenTwoIntegers_whenCheckReference_thenEqualReference() { - val a = Integer(10) - val b = Integer(10) - - assertFalse(a === b) - } - - // Checks structural equality - @Test - fun givenTwoIntegers_whenCheckValue_thenStructurallyEqual() { - val a = Integer(10) - val b = Integer(10) - - assertTrue(a == b) - } - - @Test - fun givenUser_whenCheckReference_thenEqualReference() { - val user = User("John", 30, listOf("Hiking, Chess")) - val user2 = User("Sarah", 28, listOf("Shopping, Gymnastics")) - - assertFalse(user === user2) - } - - @Test - fun givenUser_whenCheckValue_thenStructurallyEqual() { - val user = User("John", 30, listOf("Hiking, Chess")) - val user2 = User("John", 30, listOf("Hiking, Chess")) - - assertTrue(user == user2) - } - - @Test - fun givenArray_whenCheckReference_thenEqualReference() { - val hobbies = arrayOf("Riding motorcycle, Video games") - val hobbies2 = arrayOf("Riding motorcycle, Video games") - - assertFalse(hobbies === hobbies2) - } - - @Test - fun givenArray_whenCheckContent_thenStructurallyEqual() { - val hobbies = arrayOf("Hiking, Chess") - val hobbies2 = arrayOf("Hiking, Chess") - - assertTrue(hobbies contentEquals hobbies2) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt deleted file mode 100644 index fa6e1773bd..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.operators - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class PageTest { - - private val page = PageImpl(1, 10, "Java", "Kotlin", "Scala") - - @Test - fun `Get convention should work as expected`() { - assertEquals(page[1], "Kotlin") - assertEquals(page[1, 3], listOf("Kotlin", "Scala")) - } - - @Test - fun `Invoke convention should work as expected`() { - assertEquals(page(1), "Kotlin") - } - - @Test - fun `In convention should work on a page as expected`() { - assertTrue("Kotlin" in page) - } - -} - -private class PageImpl(val page: Int, val size: Int, vararg val elements: T) : Page { - override fun pageNumber(): Int = page - override fun pageSize(): Int = size - override fun elements(): MutableList = mutableListOf(*elements) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PointTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PointTest.kt deleted file mode 100644 index 168ab6431d..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PointTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.operators - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class PointTest { - - private val p1 = Point(1, 2) - private val p2 = Point(2, 3) - - @Test - fun `We should be able to add two points together using +`() { - assertEquals(p1 + p2, Point(3, 5)) - } - - @Test - fun `We shoud be able to subtract one point from another using -`() { - assertEquals(p1 - p2, Point(-1, -1)) - } - - @Test - fun `We should be able to multiply two points together with *`() { - assertEquals(p1 * p2, Point(2, 6)) - } - - @Test - fun `We should be able to divide one point by another`() { - assertEquals(p1 / p2, Point(0, 0)) - } - - @Test - fun `We should be able to scale a point by an integral factor`() { - assertEquals(p1 * 2, Point(2, 4)) - assertEquals(2 * p1, Point(2, 4)) - } - - @Test - fun `We should be able to add points to an empty shape`() { - val line = shape { - +Point(0, 0) - +Point(1, 3) - } - - assertTrue(Point(0, 0) in line.points) - assertTrue(Point(1, 3) in line.points) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/UtilsTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/UtilsTest.kt deleted file mode 100644 index 4abe962cb5..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/UtilsTest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.operators - -import java.math.BigInteger -import org.junit.Test -import kotlin.test.assertEquals - -class UtilsTest { - - @Test - fun `We should be able to add an int value to an existing BigInteger using +`() { - assertEquals(BigInteger.ZERO + 1, BigInteger.ONE) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/CharRangeTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/CharRangeTest.kt deleted file mode 100644 index 0e23f508b6..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/CharRangeTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class CharRangeTest { - - @Test - fun testCharRange() { - assertEquals(listOf('a', 'b', 'c'), ('a'..'c').toList()) - } - - @Test - fun testCharDownRange() { - assertEquals(listOf('c', 'b', 'a'), ('c'.downTo('a')).toList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ColorTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ColorTest.kt deleted file mode 100644 index 4ac3270fcc..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ColorTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class ColorTest { - - @Test - fun testEnumRange() { - - println(Color.values().toList()); - val red = Color.RED - val yellow = Color.YELLOW - val range = red..yellow - - assertTrue { range.contains(Color.MAGENTA) } - assertFalse { range.contains(Color.BLUE) } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FilterTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FilterTest.kt deleted file mode 100644 index d0e2df8860..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FilterTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class FilterTest { - - val r = 1..10 - - @Test - fun filterTest() { - assertEquals(listOf(2, 4, 6, 8, 10), r.filter { it -> it % 2 == 0 }.toList()) - } - - @Test - fun mapTest() { - assertEquals(listOf(1, 4, 9, 16, 25, 36, 49, 64, 81, 100), r.map { it -> it * it }.toList()) - } - - @Test - fun reduceTest() { - assertEquals(55, r.reduce { a, b -> a + b }) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FirstLastTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FirstLastTest.kt deleted file mode 100644 index ca797e9c9b..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/FirstLastTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class FirstLastTest { - - @Test - fun testFirst() { - assertEquals(1, (1..9).first) - } - - @Test - fun testLast() { - assertEquals(9, (1..9).last) - } - - @Test - fun testStep() { - assertEquals(2, (1..9 step 2).step) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/OtherRangeFunctionsTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/OtherRangeFunctionsTest.kt deleted file mode 100644 index d2d36bbfae..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/OtherRangeFunctionsTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class OtherRangeFunctionsTest { - - val r = 1..20 - val repeated = listOf(1, 1, 2, 4, 4, 6, 10) - - @Test - fun testMin() { - assertEquals(1, r.min()) - } - - @Test - fun testMax() { - assertEquals(20, r.max()) - } - - @Test - fun testSum() { - assertEquals(210, r.sum()) - } - - @Test - fun testAverage() { - assertEquals(10.5, r.average()) - } - - @Test - fun testCount() { - assertEquals(20, r.count()) - } - - @Test - fun testDistinct() { - assertEquals(listOf(1, 2, 4, 6, 10), repeated.distinct()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/RangeTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/RangeTest.kt deleted file mode 100644 index 48fa483924..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/RangeTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class RangeTest { - - @Test - fun testRange() { - assertEquals(listOf(1,2,3), (1.rangeTo(3).toList())) - } - - @Test - fun testDownTo(){ - assertEquals(listOf(3,2,1), (3.downTo(1).toList())) - } - - @Test - fun testUntil(){ - assertEquals(listOf(1,2), (1.until(3).toList())) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ReverseRangeTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ReverseRangeTest.kt deleted file mode 100644 index 7e1c7badb7..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/ReverseRangeTest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class ReverseRangeTest { - - @Test - fun reversedTest() { - assertEquals(listOf(9, 6, 3), (1..9).reversed().step(3).toList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/StepTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/StepTest.kt deleted file mode 100644 index 4570ceeb0a..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/StepTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class StepTest { - - @Test - fun testStep() { - assertEquals(listOf(1, 3, 5, 7, 9), (1..9 step 2).toList()) - } - - @Test - fun testStepDown() { - assertEquals(listOf(9, 7, 5, 3, 1), (9 downTo 1 step 2).toList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/UntilRangeTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/UntilRangeTest.kt deleted file mode 100644 index f941c7f1e6..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/range/UntilRangeTest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.range - -import org.junit.Test -import kotlin.test.assertEquals - -class UntilRangeTest { - - @Test - fun testUntil() { - assertEquals(listOf(1, 2, 3, 4), (1 until 5).toList()) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/rangeiterator/CustomColorTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/rangeiterator/CustomColorTest.kt deleted file mode 100644 index 676b47ae7a..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/rangeiterator/CustomColorTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.rangeiterator - -import org.junit.Test -import java.lang.IllegalStateException -import kotlin.test.assertFailsWith -import kotlin.test.assertTrue - -class CustomColorTest { - - @Test - fun testInvalidConstructor(){ - assertFailsWith(IllegalStateException::class){ - CustomColor(-1) - } - } - - @Test - fun assertHas10Colors(){ - assertTrue { - val a = CustomColor(1) - val b = CustomColor(10) - val range = a..b - for(cc in range){ - println(cc) - } - range.toList().size == 10 - } - } - - @Test - fun assertContains0xCCCCCC(){ - assertTrue { - val a = CustomColor(0xBBBBBB) - val b = CustomColor(0xDDDDDD) - val range = a..b - range.contains(CustomColor(0xCCCCCC)) - } - } - -} - diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/trywithresource/UseTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/trywithresource/UseTest.kt deleted file mode 100644 index d17832b380..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/trywithresource/UseTest.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.trywithresource - -import org.junit.Test -import java.beans.ExceptionListener -import java.beans.XMLEncoder -import java.io.* -import java.lang.Exception -import kotlin.test.assertEquals -import kotlin.test.assertTrue -import kotlin.test.fail - -class UseTest { - - @Test - fun givenCloseable_whenUseIsCalled_thenItIsClosed() { - val stringWriter = StringWriter() - val writer = BufferedWriter(stringWriter) //Using a BufferedWriter because after close() it throws. - writer.use { - assertEquals(writer, it) - - it.write("something") - } - try { - writer.write("something else") - - fail("write() should have thrown an exception because the writer is closed.") - } catch (e: IOException) { - //Ok - } - - assertEquals("something", stringWriter.toString()) - } - - @Test - fun givenAutoCloseable_whenUseIsCalled_thenItIsClosed() { - val baos = ByteArrayOutputStream() - val encoder = XMLEncoder(PrintStream(baos)) //XMLEncoder is AutoCloseable but not Closeable. - //Here, we use a PrintStream because after close() it throws. - encoder.exceptionListener = ThrowingExceptionListener() - encoder.use { - assertEquals(encoder, it) - - it.writeObject("something") - } - try { - encoder.writeObject("something else") - encoder.flush() - - fail("write() should have thrown an exception because the encoder is closed.") - } catch (e: IOException) { - //Ok - } - } - - @Test - fun whenSimpleFormIsUsed_thenItWorks() { - StringWriter().use { it.write("something") } - } -} - -class ThrowingExceptionListener : ExceptionListener { - override fun exceptionThrown(e: Exception?) { - if(e != null) { - throw e - } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/voidtypes/VoidTypesUnitTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/voidtypes/VoidTypesUnitTest.kt deleted file mode 100644 index 468352dbed..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/voidtypes/VoidTypesUnitTest.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.voidtypes - -import org.junit.jupiter.api.Test -import kotlin.test.assertNull -import kotlin.test.assertTrue - -class VoidTypesUnitTest { - - // Un-commenting below methods will result into compilation error - // as the syntax used is incorrect and is used for explanation in tutorial. - - // fun returnTypeAsVoidAttempt1(): Void { - // println("Trying with Void as return type") - // } - - // fun returnTypeAsVoidAttempt2(): Void { - // println("Trying with Void as return type") - // return null - // } - - fun returnTypeAsVoidSuccess(): Void? { - println("Function can have Void as return type") - return null - } - - fun unitReturnTypeForNonMeaningfulReturns(): Unit { - println("No meaningful return") - } - - fun unitReturnTypeIsImplicit() { - println("Unit Return type is implicit") - } - - fun alwaysThrowException(): Nothing { - throw IllegalArgumentException() - } - - fun invokeANothingOnlyFunction() { - alwaysThrowException() - - var name = "Tom" - } - - @Test - fun givenJavaVoidFunction_thenMappedToKotlinUnit() { - assertTrue(System.out.println() is Unit) - } - - @Test - fun givenVoidReturnType_thenReturnsNullOnly() { - assertNull(returnTypeAsVoidSuccess()) - } - - @Test - fun givenUnitReturnTypeDeclared_thenReturnsOfTypeUnit() { - assertTrue(unitReturnTypeForNonMeaningfulReturns() is Unit) - } - - @Test - fun givenUnitReturnTypeNotDeclared_thenReturnsOfTypeUnit() { - assertTrue(unitReturnTypeIsImplicit() is Unit) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/whenblock/WhenBlockUnitTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/whenblock/WhenBlockUnitTest.kt deleted file mode 100644 index 31b6ad69f5..0000000000 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/whenblock/WhenBlockUnitTest.kt +++ /dev/null @@ -1,136 +0,0 @@ -package com.baeldung.whenblock - -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class WhenBlockUnitTest { - - @Test - fun testWhenExpression() { - val directoryType = UnixFileType.D - - val objectType = when (directoryType) { - UnixFileType.D -> "d" - UnixFileType.HYPHEN_MINUS -> "-" - UnixFileType.L -> "l" - } - - assertEquals("d", objectType) - } - - @Test - fun testWhenExpressionWithDefaultCase() { - val fileType = UnixFileType.L - - val result = when (fileType) { - UnixFileType.L -> "linking to another file" - else -> "not a link" - } - - assertEquals("linking to another file", result) - } - - @Test(expected = IllegalArgumentException::class) - fun testWhenExpressionWithThrowException() { - val fileType = UnixFileType.L - - val result: Boolean = when (fileType) { - UnixFileType.HYPHEN_MINUS -> true - else -> throw IllegalArgumentException("Wrong type of file") - } - } - - @Test - fun testWhenStatement() { - val fileType = UnixFileType.HYPHEN_MINUS - - when (fileType) { - UnixFileType.HYPHEN_MINUS -> println("Regular file type") - UnixFileType.D -> println("Directory file type") - } - } - - @Test - fun testCaseCombination() { - val fileType = UnixFileType.D - - val frequentFileType: Boolean = when (fileType) { - UnixFileType.HYPHEN_MINUS, UnixFileType.D -> true - else -> false - } - - assertTrue(frequentFileType) - } - - @Test - fun testWhenWithoutArgument() { - val fileType = UnixFileType.L - - val objectType = when { - fileType === UnixFileType.L -> "l" - fileType === UnixFileType.HYPHEN_MINUS -> "-" - fileType === UnixFileType.D -> "d" - else -> "unknown file type" - } - - assertEquals("l", objectType) - } - - @Test - fun testDynamicCaseExpression() { - val unixFile = UnixFile.SymbolicLink(UnixFile.RegularFile("Content")) - - when { - unixFile.getFileType() == UnixFileType.D -> println("It's a directory!") - unixFile.getFileType() == UnixFileType.HYPHEN_MINUS -> println("It's a regular file!") - unixFile.getFileType() == UnixFileType.L -> println("It's a soft link!") - } - } - - @Test - fun testCollectionCaseExpressions() { - val regularFile = UnixFile.RegularFile("Test Content") - val symbolicLink = UnixFile.SymbolicLink(regularFile) - val directory = UnixFile.Directory(listOf(regularFile, symbolicLink)) - - val isRegularFileInDirectory = when (regularFile) { - in directory.children -> true - else -> false - } - - val isSymbolicLinkInDirectory = when { - symbolicLink in directory.children -> true - else -> false - } - - assertTrue(isRegularFileInDirectory) - assertTrue(isSymbolicLinkInDirectory) - } - - @Test - fun testRangeCaseExpressions() { - val fileType = UnixFileType.HYPHEN_MINUS - - val isCorrectType = when (fileType) { - in UnixFileType.D..UnixFileType.L -> true - else -> false - } - - assertTrue(isCorrectType) - } - - @Test - fun testWhenWithIsOperatorWithSmartCase() { - val unixFile: UnixFile = UnixFile.RegularFile("Test Content") - - val result = when (unixFile) { - is UnixFile.RegularFile -> unixFile.content - is UnixFile.Directory -> unixFile.children.map { it.getFileType() }.joinToString(", ") - is UnixFile.SymbolicLink -> unixFile.originalFile.getFileType() - } - - assertEquals("Test Content", result) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-strings/README.md b/core-kotlin-modules/core-kotlin-strings/README.md deleted file mode 100644 index 0e3d8ea57f..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Core Kotlin Strings - -This module contains articles about core Kotlin strings. - -### Relevant articles: -- [Generate a Random Alphanumeric String in Kotlin](https://www.baeldung.com/kotlin-random-alphanumeric-string) -- [String Comparison in Kotlin](https://www.baeldung.com/kotlin-string-comparison) -- [Concatenate Strings in Kotlin](https://www.baeldung.com/kotlin-concatenate-strings) -- [Kotlin String Templates](https://www.baeldung.com/kotlin-string-template) diff --git a/core-kotlin-modules/core-kotlin-strings/pom.xml b/core-kotlin-modules/core-kotlin-strings/pom.xml deleted file mode 100644 index fb2998e9e1..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - core-kotlin-strings - core-kotlin-strings - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-strings/src/main/kotlin/com/baeldung/stringtemplates/Templates.kt b/core-kotlin-modules/core-kotlin-strings/src/main/kotlin/com/baeldung/stringtemplates/Templates.kt deleted file mode 100644 index 4b2d863618..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/src/main/kotlin/com/baeldung/stringtemplates/Templates.kt +++ /dev/null @@ -1,115 +0,0 @@ -package com.baeldung.stringtemplates - -/** - * Example of a useful function defined in Kotlin String class - */ -fun padExample(): String { - return "Hello".padEnd(10, '!') -} - -/** - * Example of a simple string template usage - */ -fun simpleTemplate(n: Int): String { - val message = "n = $n" - return message -} - -/** - * Example of a string template with a simple expression - */ -fun templateWithExpression(n: Int): String { - val message = "n + 1 = ${n + 1}" - return message -} - -/** - * Example of a string template with expression containing some logic - */ -fun templateWithLogic(n: Int): String { - val message = "$n is ${if (n > 0) "positive" else "not positive"}" - return message -} - -/** - * Example of nested string templates - */ -fun nestedTemplates(n: Int): String { - val message = "$n is ${if (n > 0) "positive" else if (n < 0) "negative and ${if (n % 2 == 0) "even" else "odd"}" else "zero"}" - return message -} - -/** - * Example of joining array's element into a string with a default separator - */ -fun templateJoinArray(): String { - val numbers = listOf(1, 1, 2, 3, 5, 8) - val message = "first Fibonacci numbers: ${numbers.joinToString()}" - return message -} - -/** - * Example of escaping the dollar sign - */ -fun notAStringTemplate(): String { - val message = "n = \$n" - return message -} - -/** - * Example of a simple triple quoted string - */ -fun showFilePath(): String { - val path = """C:\Repository\read.me""" - return path -} - -/** - * Example of a multiline string - */ -fun showMultiline(): String { - val receipt = """Item 1: $1.00 -Item 2: $0.50""" - return receipt -} - -/** - * Example of a multiline string with indentation - */ -fun showMultilineIndent(): String { - val receipt = """Item 1: $1.00 - >Item 2: $0.50""".trimMargin(">") - return receipt -} - -/** - * Example of a triple quoted string with a not-working escape sequence - */ -fun showTripleQuotedWrongEscape(): String { - val receipt = """Item 1: $1.00\nItem 2: $0.50""" - return receipt -} - -/** - * Example of a triple quoted string with a correctly working escape sequence - */ - -fun showTripleQuotedCorrectEscape(): String { - val receipt = """Item 1: $1.00${"\n"}Item 2: $0.50""" - return receipt -} - -fun main(args: Array) { - println(padExample()) - println(simpleTemplate(10)) - println(templateWithExpression(5)) - println(templateWithLogic(7)) - println(nestedTemplates(-5)) - println(templateJoinArray()) - println(notAStringTemplate()) - println(showFilePath()) - println(showMultiline()) - println(showMultilineIndent()) - println(showTripleQuotedWrongEscape()) - println(showTripleQuotedCorrectEscape()) -} diff --git a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt b/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt deleted file mode 100644 index 20e635a579..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/randomstring/RandomStringUnitTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.randomstring - -import org.apache.commons.lang3.RandomStringUtils -import org.junit.Before -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import java.security.SecureRandom -import java.util.concurrent.ThreadLocalRandom -import kotlin.experimental.and -import kotlin.streams.asSequence -import kotlin.test.assertEquals - -const val STRING_LENGTH = 10 -const val ALPHANUMERIC_REGEX = "[a-zA-Z0-9]+" - -class RandomStringUnitTest { - private val charPool : List = ('a'..'z') + ('A'..'Z') + ('0'..'9') - - @Test - fun givenAStringLength_whenUsingJava_thenReturnAlphanumericString() { - var randomString = ThreadLocalRandom.current() - .ints(STRING_LENGTH.toLong(), 0, charPool.size) - .asSequence() - .map(charPool::get) - .joinToString("") - - assert(randomString.matches(Regex(ALPHANUMERIC_REGEX))) - assertEquals(STRING_LENGTH, randomString.length) - } - - @Test - fun givenAStringLength_whenUsingKotlin_thenReturnAlphanumericString() { - var randomString = (1..STRING_LENGTH).map { i -> kotlin.random.Random.nextInt(0, charPool.size) } - .map(charPool::get) - .joinToString("") - - assert(randomString.matches(Regex(ALPHANUMERIC_REGEX))) - assertEquals(STRING_LENGTH, randomString.length) - } - - @Test - fun givenAStringLength_whenUsingApacheCommon_thenReturnAlphanumericString() { - var randomString = RandomStringUtils.randomAlphanumeric(STRING_LENGTH) - - assert(randomString.matches(Regex(ALPHANUMERIC_REGEX))) - assertEquals(STRING_LENGTH, randomString.length) - } - - @Test - fun givenAStringLength_whenUsingRandomForBytes_thenReturnAlphanumericString() { - val random = SecureRandom() - val bytes = ByteArray(STRING_LENGTH) - random.nextBytes(bytes) - - var randomString = (0..bytes.size - 1).map { i -> - charPool[random.nextInt(charPool.size)] - }.joinToString("") - - assert(randomString.matches(Regex(ALPHANUMERIC_REGEX))) - assertEquals(STRING_LENGTH, randomString.length) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt b/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt deleted file mode 100644 index 49ff798faa..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.stringcomparison - -import org.junit.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class StringComparisonUnitTest { - - @Test - fun `compare using equals operator`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first == second } - assertFalse { first == firstCapitalized } - } - - @Test - fun `compare using referential equals operator`() { - val first = "kotlin" - val second = "kotlin" - val third = String("kotlin".toCharArray()) - assertTrue { first === second } - assertFalse { first === third } - } - - @Test - fun `compare using equals method`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first.equals(second) } - assertFalse { first.equals(firstCapitalized) } - assertTrue { first.equals(firstCapitalized, true) } - } - - @Test - fun `compare using compare method`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first.compareTo(second) == 0 } - assertTrue { first.compareTo(firstCapitalized) == 32 } - assertTrue { firstCapitalized.compareTo(first) == -32 } - assertTrue { first.compareTo(firstCapitalized, true) == 0 } - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringconcatenation/StringConcatenationTest.kt b/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringconcatenation/StringConcatenationTest.kt deleted file mode 100644 index 9ac011f7d2..0000000000 --- a/core-kotlin-modules/core-kotlin-strings/src/test/kotlin/com/baeldung/stringconcatenation/StringConcatenationTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.stringconcatenation - -import org.junit.Test -import kotlin.test.assertEquals - -class StringConcatenationTest { - - @Test - fun givenTwoStrings_concatenateWithTemplates_thenEquals() { - val a = "Hello" - val b = "Baeldung" - val c = "$a $b" - - assertEquals("Hello Baeldung", c) - } - - @Test - fun givenTwoStrings_concatenateWithPlusOperator_thenEquals() { - val a = "Hello" - val b = "Baeldung" - val c = a + " " + b - - assertEquals("Hello Baeldung", c) - } - - @Test - fun givenTwoStrings_concatenateWithStringBuilder_thenEquals() { - val a = "Hello" - val b = "Baeldung" - - val builder = StringBuilder() - builder.append(a).append(" ").append(b) - - val c = builder.toString() - - assertEquals("Hello Baeldung", c) - } - - @Test - fun givenTwoStrings_concatenateWithPlusMethod_thenEquals() { - val a = "Hello" - val b = "Baeldung" - val c = a.plus(" ").plus(b) - - assertEquals("Hello Baeldung", c) - } - -} diff --git a/core-kotlin-modules/core-kotlin-testing/README.md b/core-kotlin-modules/core-kotlin-testing/README.md deleted file mode 100644 index f4d89593a7..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Core Kotlin Testing - -This module contains articles about testing in Kotlin - -### Relevant articles: -- [JUnit 5 for Kotlin Developers](https://www.baeldung.com/junit-5-kotlin) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-testing/pom.xml b/core-kotlin-modules/core-kotlin-testing/pom.xml deleted file mode 100644 index d38bc62409..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - core-kotlin-testing - core-kotlin-testing - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - - - 1.1.1 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt deleted file mode 100644 index 9f6e3ab2b9..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.junit5 - -class Calculator { - fun add(a: Int, b: Int) = a + b - - fun divide(a: Int, b: Int) = if (b == 0) { - throw DivideByZeroException(a) - } else { - a / b - } - - fun square(a: Int) = a * a - - fun squareRoot(a: Int) = Math.sqrt(a.toDouble()) - - fun log(base: Int, value: Int) = Math.log(value.toDouble()) / Math.log(base.toDouble()) -} diff --git a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt deleted file mode 100644 index 07cab3b76e..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.junit5 - -import org.junit.jupiter.api.* -import org.junit.jupiter.api.function.Executable - -class CalculatorUnitTest { - private val calculator = Calculator() - - @Test - fun `Adding 1 and 3 should be equal to 4`() { - Assertions.assertEquals(4, calculator.add(1, 3)) - } - - @Test - fun `Dividing by zero should throw the DivideByZeroException`() { - val exception = Assertions.assertThrows(DivideByZeroException::class.java) { - calculator.divide(5, 0) - } - - Assertions.assertEquals(5, exception.numerator) - } - - @Test - fun `The square of a number should be equal to that number multiplied in itself`() { - Assertions.assertAll( - Executable { Assertions.assertEquals(1, calculator.square(1)) }, - Executable { Assertions.assertEquals(4, calculator.square(2)) }, - Executable { Assertions.assertEquals(9, calculator.square(3)) } - ) - } - - @TestFactory - fun testSquaresFactory() = listOf( - DynamicTest.dynamicTest("when I calculate 1^2 then I get 1") { Assertions.assertEquals(1,calculator.square(1))}, - DynamicTest.dynamicTest("when I calculate 2^2 then I get 4") { Assertions.assertEquals(4,calculator.square(2))}, - DynamicTest.dynamicTest("when I calculate 3^2 then I get 9") { Assertions.assertEquals(9,calculator.square(3))} - ) - - @TestFactory - fun testSquaresFactory2() = listOf( - 1 to 1, - 2 to 4, - 3 to 9, - 4 to 16, - 5 to 25) - .map { (input, expected) -> - DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") { - Assertions.assertEquals(expected, calculator.square(input)) - } - } - - private val squaresTestData = listOf( - 1 to 1, - 2 to 4, - 3 to 9, - 4 to 16, - 5 to 25) - - @TestFactory - fun testSquaresFactory3() = squaresTestData - .map { (input, expected) -> - DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") { - Assertions.assertEquals(expected, calculator.square(input)) - } - } - @TestFactory - fun testSquareRootsFactory3() = squaresTestData - .map { (expected, input) -> - DynamicTest.dynamicTest("I calculate the square root of $input then I get $expected") { - Assertions.assertEquals(expected.toDouble(), calculator.squareRoot(input)) - } - } - - @Tags( - Tag("slow"), - Tag("logarithms") - ) - @Test - fun `Log to base 2 of 8 should be equal to 3`() { - Assertions.assertEquals(3.0, calculator.log(2, 8)) - } -} diff --git a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt deleted file mode 100644 index 5675367fd5..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.junit5 - -class DivideByZeroException(val numerator: Int) : Exception() diff --git a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt deleted file mode 100644 index e3fe998efd..0000000000 --- a/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.junit5 - -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test - -class SimpleUnitTest { - - @Test - fun `isEmpty should return true for empty lists`() { - val list = listOf() - Assertions.assertTrue(list::isEmpty) - } - - @Test - @Disabled - fun `3 is equal to 4`() { - Assertions.assertEquals(3, 4) { - "Three does not equal four" - } - } -} diff --git a/core-kotlin-modules/core-kotlin/README.md b/core-kotlin-modules/core-kotlin/README.md deleted file mode 100644 index a890658e95..0000000000 --- a/core-kotlin-modules/core-kotlin/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## Core Kotlin - -This module contains articles about Kotlin core features. - -### Relevant articles: - -- [Introduction to the Kotlin Language](https://www.baeldung.com/kotlin-intro) -- [Kotlin Java Interoperability](https://www.baeldung.com/kotlin-java-interoperability) -- [Get a Random Number in Kotlin](https://www.baeldung.com/kotlin-random-number) -- [Create a Java and Kotlin Project with Maven](https://www.baeldung.com/kotlin-maven-java-project) -- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-operator) -- [Sequences in Kotlin](https://www.baeldung.com/kotlin/sequences) -- [Converting Kotlin Data Class from JSON using GSON](https://www.baeldung.com/kotlin-json-convert-data-class) -- [Exception Handling in Kotlin](https://www.baeldung.com/kotlin/exception-handling) -- [Quick Guide to Kotlin Default and Named Arguments](https://www.baeldung.com/kotlin/default-named-arguments) diff --git a/core-kotlin-modules/core-kotlin/pom.xml b/core-kotlin-modules/core-kotlin/pom.xml deleted file mode 100644 index 6e36b7c8ef..0000000000 --- a/core-kotlin-modules/core-kotlin/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - core-kotlin - core-kotlin - jar - - - com.baeldung.core-kotlin-modules - core-kotlin-modules - 1.0.0-SNAPSHOT - - - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - - - 1.1.1 - - - \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/ArrayExample.java b/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/ArrayExample.java deleted file mode 100644 index 93b9a3984a..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/ArrayExample.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.interoperability; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -public class ArrayExample { - - public int sumValues(int[] nums) { - int res = 0; - - for (int x:nums) { - res += x; - } - - return res; - } - - public void writeList() throws IOException { - File file = new File("E://file.txt"); - FileReader fr = new FileReader(file); - fr.close(); - } -} diff --git a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/Customer.java b/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/Customer.java deleted file mode 100644 index 4a070a0f97..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/interoperability/Customer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.interoperability; - -public class Customer { - - private String firstName; - private String lastName; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - -} diff --git a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/introduction/StringUtils.java b/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/introduction/StringUtils.java deleted file mode 100644 index 1c477ce039..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/introduction/StringUtils.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.introduction; - -public class StringUtils { - public static String toUpperCase(String name) { - return name.toUpperCase(); - } -} diff --git a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/Application.java b/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/Application.java deleted file mode 100644 index ac933d6228..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/Application.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.mavenjavakotlin; - -import com.baeldung.mavenjavakotlin.services.JavaService; - -public class Application { - - private static final String JAVA = "java"; - private static final String KOTLIN = "kotlin"; - - public static void main(String[] args) { - String language = args[0]; - switch (language) { - case JAVA: - new JavaService().sayHello(); - break; - case KOTLIN: - new KotlinService().sayHello(); - break; - default: - // Do nothing - break; - } - } - -} diff --git a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/services/JavaService.java b/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/services/JavaService.java deleted file mode 100644 index b767e761af..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/java/com/baeldung/mavenjavakotlin/services/JavaService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.mavenjavakotlin.services; - -public class JavaService { - - public void sayHello() { - System.out.println("Java says 'Hello World!'"); - } - -} diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/DefaultArguments.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/DefaultArguments.kt deleted file mode 100644 index 691b3475b4..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/DefaultArguments.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.arguments - -fun main() { - - // Skip both the connectTimeout and enableRetry arguments - connect("http://www.baeldung.com") - - // Skip only the enableRetry argument: - connect("http://www.baeldung.com", 5000) - - // Skip only the middle argument connectTimeout - // connect("http://www.baeldung.com", false) // This results in a compiler error - - // Because we skipped the connectTimeout argument, we must pass the enableRetry as a named argument - connect("http://www.baeldung.com", enableRetry = false) - - // Overriding Functions and Default Arguments - val realConnector = RealConnector() - realConnector.connect("www.baeldung.com") - realConnector.connect() -} - -fun connect(url: String, connectTimeout: Int = 1000, enableRetry: Boolean = true) { - println("The parameters are url = $url, connectTimeout = $connectTimeout, enableRetry = $enableRetry") -} - -open class AbstractConnector { - open fun connect(url: String = "localhost") { - // function implementation - } -} - -class RealConnector : AbstractConnector() { - override fun connect(url: String) { - println("The parameter is url = $url") - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/NamedArguments.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/NamedArguments.kt deleted file mode 100644 index 0cbf6f158a..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/arguments/NamedArguments.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.arguments - -fun main() { - resizePane(newSize = 10, forceResize = true, noAnimation = false) - - // Swap the order of last two named arguments - resizePane(newSize = 11, noAnimation = false, forceResize = true) - - // Named arguments can be passed in any order - resizePane(forceResize = true, newSize = 12, noAnimation = false) - - // Mixing Named and Positional Arguments - // Kotlin 1.3 would allow us to name only the arguments after the positional ones - resizePane(20, true, noAnimation = false) - - // Using a positional argument in the middle of named arguments (supported from Kotlin 1.4.0) - // resizePane(newSize = 20, true, noAnimation = false) - - // Only the last argument as a positional argument (supported from Kotlin 1.4.0) - // resizePane(newSize = 30, forceResize = true, false) - - // Use a named argument in the middle of positional arguments (supported from Kotlin 1.4.0) - // resizePane(40, forceResize = true, false) -} - -fun resizePane(newSize: Int, forceResize: Boolean, noAnimation: Boolean) { - println("The parameters are newSize = $newSize, forceResize = $forceResize, noAnimation = $noAnimation") -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt deleted file mode 100644 index 6689ab43e4..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.baeldung.exceptionhandling - -import java.io.IOException - -class ExceptionHandling { - - fun tryCatchBlock(): Int? { - try { - val message = "Welcome to Kotlin Tutorials" - return message.toInt() - } catch (exception: NumberFormatException) { - println("NumberFormatException in the code") - return null - } - } - - fun tryCatchExpression(): Int? { - val number = try { - val message = "Welcome to Kotlin Tutorials" - message.toInt() - } catch (exception: NumberFormatException) { - println("NumberFormatException in the code") - null - } - return number - } - - fun multipleCatchBlock(): Int? { - return try { - val result = 25 / 0 - result - } catch (exception: NumberFormatException) { - println("NumberFormatException in the code") - null - } catch (exception: ArithmeticException) { - println("ArithmeticException in the code") - null - } catch (exception: Exception) { - println("Exception in the code") - null - } - } - - fun nestedTryCatchBlock(): Int? { - return try { - val firstNumber = 50 / 2 * 0 - try { - val secondNumber = 100 / firstNumber - secondNumber - } catch (exception: ArithmeticException) { - println("ArithmeticException in the code") - null - } - } catch (exception: NumberFormatException) { - println("NumberFormatException in the code") - null - } - } - - fun finallyBlock(): Int? { - return try { - val message = "Welcome to Kotlin Tutorials" - message.toInt() - } catch (exception: NumberFormatException) { - println("NumberFormatException in the code") - null - } finally { - println("In the Finally block") - } - } - - fun throwKeyword(): Int { - val message = "Welcome to Kotlin Tutorials" - if (message.length > 10) throw IllegalArgumentException("String is invalid") - else return message.length - } - - fun throwExpression(): Int? { - val message: String? = null - return message?.length ?: throw IllegalArgumentException("String is null") - } - - @Throws(IOException::class) - fun throwsAnnotation(): String?{ - val filePath = null - return filePath ?: throw IOException("File path is invalid") - } -} diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Example1.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Example1.kt deleted file mode 100644 index aacd8f7915..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Example1.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.introduction - -fun main(args: Array){ - println("hello word") -} diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Item.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Item.kt deleted file mode 100644 index bb91dd1eae..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/Item.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.introduction - -open class Item(val id: String, val name: String = "unknown_name") { - open fun getIdOfItem(): String { - return id - } -} - -class ItemWithCategory(id: String, name: String, val categoryId: String) : Item(id, name) { - override fun getIdOfItem(): String { - return id + name - } -} - diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ItemService.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ItemService.kt deleted file mode 100644 index dfcf17df7c..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ItemService.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.baeldung.introduction - -import java.util.* - -class ItemService { - fun findItemNameForId(id: String): Item? { - val itemId = UUID.randomUUID().toString() - return Item(itemId, "name-$itemId") - } -} - -class ItemManager(val categoryId: String, val dbConnection: String) { - var email = "" - - constructor(categoryId: String, dbConnection: String, email: String) - : this(categoryId, dbConnection) { - this.email = email - } - - fun isFromSpecificCategory(catId: String): Boolean { - return categoryId == catId - } - - fun makeAnalyisOfCategory(catId: String): Unit { - val result = if (catId == "100") "Yes" else "No" - println(result) - `object`() - } - - fun sum(a: Int, b: Int): Int { - return a + b - } - - fun `object`(): String { - return "this is object" - } - -} - -fun main(args: Array) { - val numbers = arrayOf("first", "second", "third", "fourth") - - for (n in numbers) { - println(n) - } - - for (i in 2..9 step 2) { - println(i) - } - - val res = 1.rangeTo(10).map { it * 2 } - println(res) - - val firstName = "Tom" - val secondName = "Mary" - val concatOfNames = "$firstName + $secondName" - println("Names: $concatOfNames") - val sum = "four: ${2 + 2}" - - val itemManager = ItemManager("cat_id", "db://connection") - ItemManager(categoryId = "catId", dbConnection = "db://Connection") - val result = "function result: ${itemManager.isFromSpecificCategory("1")}" - println(result) - - val number = 2 - if (number < 10) { - println("number less that 10") - } else if (number > 10) { - println("number is greater that 10") - } - - val name = "John" - when (name) { - "John" -> println("Hi man") - "Alice" -> println("Hi lady") - } - - val items = listOf(1, 2, 3, 4) - - - val rwList = mutableListOf(1, 2, 3) - rwList.add(5) -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ListExtension.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ListExtension.kt deleted file mode 100644 index e71292c60a..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/ListExtension.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.introduction - -import java.util.concurrent.ThreadLocalRandom - -class ListExtension { - fun List.random(): T? { - if (this.isEmpty()) return null - return get(ThreadLocalRandom.current().nextInt(count())) - } - - fun getRandomElementOfList(list: List): T? { - return list.random() - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/MathematicsOperations.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/MathematicsOperations.kt deleted file mode 100644 index 0ed30ed5b4..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/introduction/MathematicsOperations.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.introduction - -class MathematicsOperations { - fun addTwoNumbers(a: Int, b: Int): Int { - return a + b - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/mavenjavakotlin/KotlinService.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/mavenjavakotlin/KotlinService.kt deleted file mode 100644 index 10d6a792d8..0000000000 --- a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/mavenjavakotlin/KotlinService.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.mavenjavakotlin - -class KotlinService { - - fun sayHello() { - System.out.println("Kotlin says 'Hello World!'") - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/java/com/baeldung/introduction/JavaCallToKotlinUnitTest.java b/core-kotlin-modules/core-kotlin/src/test/java/com/baeldung/introduction/JavaCallToKotlinUnitTest.java deleted file mode 100644 index 2c386eaad3..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/java/com/baeldung/introduction/JavaCallToKotlinUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.introduction; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class JavaCallToKotlinUnitTest { - @Test - public void givenKotlinClass_whenCallFromJava_shouldProduceResults() { - //when - int res = new MathematicsOperations().addTwoNumbers(2, 4); - - //then - assertEquals(6, res); - - } -} diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt deleted file mode 100644 index af7aa4406f..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.exceptionhandling - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import java.io.IOException -import kotlin.test.assertNull - -class ExceptionHandlingUnitTest { - - private val classUnderTest: ExceptionHandling = ExceptionHandling() - - @Test - fun givenInvalidConversion_whenTryCatchUsed_thenReturnsCatchBlockValue(){ - assertNull(classUnderTest.tryCatchBlock()) - } - - @Test - fun givenInvalidConversion_whenTryCatchExpressionUsed_thenReturnsCatchBlockValue(){ - assertNull(classUnderTest.tryCatchExpression()) - } - - @Test - fun givenDivisionByZero_whenMultipleCatchUsed_thenReturnsCatchBlockValue(){ - assertNull(classUnderTest.multipleCatchBlock()) - } - - @Test - fun givenDivisionByZero_whenNestedTryCatchUsed_thenReturnsNestedCatchBlockValue(){ - assertNull(classUnderTest.nestedTryCatchBlock()) - } - - @Test - fun givenInvalidConversion_whenTryCatchFinallyUsed_thenReturnsCatchAndFinallyBlock(){ - assertNull(classUnderTest.finallyBlock()) - } - - @Test - fun givenIllegalArgument_whenThrowKeywordUsed_thenThrowsException(){ - assertThrows { classUnderTest.throwKeyword() } - } - - @Test - fun givenIllegalArgument_whenElvisExpressionUsed_thenThrowsException(){ - assertThrows { classUnderTest.throwExpression() } - } - - @Test - fun whenAnnotationUsed_thenThrowsException(){ - assertThrows { classUnderTest.throwsAnnotation() } - } -} diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/ArrayTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/ArrayTest.kt deleted file mode 100644 index 8e9467f92a..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/ArrayTest.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.interoperability - -import org.junit.Test -import kotlin.test.assertEquals - -class ArrayTest { - - @Test - fun givenArray_whenValidateArrayType_thenComplete () { - val ex = ArrayExample() - val numArray = intArrayOf(1, 2, 3) - - assertEquals(ex.sumValues(numArray), 6) - } - - @Test - fun givenCustomer_whenGetSuperType_thenComplete() { - val instance = Customer::class - val supertypes = instance.supertypes - - assertEquals(supertypes[0].toString(), "kotlin.Any") - } - - @Test - fun givenCustomer_whenGetConstructor_thenComplete() { - val instance = Customer::class.java - val constructors = instance.constructors - - assertEquals(constructors.size, 1) - assertEquals(constructors[0].name, "com.baeldung.interoperability.Customer") - } - - fun makeReadFile() { - val ax = ArrayExample() - ax.writeList() - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/CustomerTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/CustomerTest.kt deleted file mode 100644 index c1b09cd0c1..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/interoperability/CustomerTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.interoperability - -import org.junit.Test -import kotlin.test.assertEquals - -class CustomerTest { - - @Test - fun givenCustomer_whenNameAndLastNameAreAssigned_thenComplete() { - val customer = Customer() - - // Setter method is being called - customer.firstName = "Frodo" - customer.lastName = "Baggins" - - // Getter method is being called - assertEquals(customer.firstName, "Frodo") - assertEquals(customer.lastName, "Baggins") - } - -} - diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ItemServiceTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ItemServiceTest.kt deleted file mode 100644 index 2ba14a7462..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ItemServiceTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.introduction - -import org.junit.Test -import kotlin.test.assertNotNull - -class ItemServiceTest { - - @Test - fun givenItemId_whenGetForOptionalItem_shouldMakeActionOnNonNullValue() { - //given - val id = "item_id" - val itemService = ItemService() - - //when - val result = itemService.findItemNameForId(id) - - //then - assertNotNull(result?.let { it -> it.id }) - assertNotNull(result!!.id) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/KotlinJavaInteroperabilityTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/KotlinJavaInteroperabilityTest.kt deleted file mode 100644 index 5dddf9bfc9..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/KotlinJavaInteroperabilityTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.introduction - -import org.junit.Test -import kotlin.test.assertEquals - - -class KotlinJavaInteroperabilityTest { - - @Test - fun givenLowercaseString_whenExecuteMethodFromJavaStringUtils_shouldReturnStringUppercase() { - //given - val name = "tom" - - //whene - val res = StringUtils.toUpperCase(name) - - //then - assertEquals(res, "TOM") - } -} diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/LambdaTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/LambdaTest.kt deleted file mode 100644 index 5e5166074e..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/LambdaTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.introduction - -import org.junit.Test -import kotlin.test.assertEquals - - -class LambdaTest { - - @Test - fun givenListOfNumber_whenDoingOperationsUsingLambda_shouldReturnProperResult() { - //given - val listOfNumbers = listOf(1, 2, 3) - - //when - val sum = listOfNumbers.reduce { a, b -> a + b } - - //then - assertEquals(6, sum) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ListExtensionTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ListExtensionTest.kt deleted file mode 100644 index 38f244297b..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/introduction/ListExtensionTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.introduction - -import org.junit.Test -import kotlin.test.assertTrue - -class ListExtensionTest { - - @Test - fun givenList_whenExecuteExtensionFunctionOnList_shouldReturnRandomElementOfList() { - //given - val elements = listOf("a", "b", "c") - - //when - val result = ListExtension().getRandomElementOfList(elements) - - //then - assertTrue(elements.contains(result)) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt deleted file mode 100644 index 434f177927..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.nullassertion - -import org.junit.Test -import kotlin.test.assertEquals - -class NotNullAssertionUnitTest { - - @Test - fun givenNullableValue_WhenNotNull_ShouldExtractTheValue() { - val answer: String? = "42" - - assertEquals(42, answer!!.toInt()) - } - - @Test(expected = KotlinNullPointerException::class) - fun givenNullableValue_WhenIsNull_ThenShouldThrow() { - val noAnswer: String? = null - noAnswer!! - } -} diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/random/RandomNumberTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/random/RandomNumberTest.kt deleted file mode 100644 index 2956a35f8a..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/random/RandomNumberTest.kt +++ /dev/null @@ -1,55 +0,0 @@ - -import org.junit.jupiter.api.Test -import java.util.concurrent.ThreadLocalRandom -import kotlin.test.assertTrue - -class RandomNumberTest { - - @Test - fun whenRandomNumberWithJavaUtilMath_thenResultIsBetween0And1() { - val randomNumber = Math.random() - assertTrue { randomNumber >=0 } - assertTrue { randomNumber <= 1 } - } - - @Test - fun whenRandomNumberWithJavaThreadLocalRandom_thenResultsInDefaultRanges() { - val randomDouble = ThreadLocalRandom.current().nextDouble() - val randomInteger = ThreadLocalRandom.current().nextInt() - val randomLong = ThreadLocalRandom.current().nextLong() - assertTrue { randomDouble >= 0 } - assertTrue { randomDouble <= 1 } - assertTrue { randomInteger >= Integer.MIN_VALUE } - assertTrue { randomInteger <= Integer.MAX_VALUE } - assertTrue { randomLong >= Long.MIN_VALUE } - assertTrue { randomLong <= Long.MAX_VALUE } - } - - @Test - fun whenRandomNumberWithKotlinJSMath_thenResultIsBetween0And1() { - val randomDouble = Math.random() - assertTrue { randomDouble >=0 } - assertTrue { randomDouble <= 1 } - } - - @Test - fun whenRandomNumberWithKotlinNumberRange_thenResultInGivenRange() { - val randomInteger = (1..12).shuffled().first() - assertTrue { randomInteger >= 1 } - assertTrue { randomInteger <= 12 } - } - - @Test - fun whenRandomNumberWithJavaThreadLocalRandom_thenResultsInGivenRanges() { - val randomDouble = ThreadLocalRandom.current().nextDouble(1.0, 10.0) - val randomInteger = ThreadLocalRandom.current().nextInt(1, 10) - val randomLong = ThreadLocalRandom.current().nextLong(1, 10) - assertTrue { randomDouble >= 1 } - assertTrue { randomDouble <= 10 } - assertTrue { randomInteger >= 1 } - assertTrue { randomInteger <= 10 } - assertTrue { randomLong >= 1 } - assertTrue { randomLong <= 10 } - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt deleted file mode 100644 index a41e213c44..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.sequeces - -import org.junit.Test -import kotlin.test.assertEquals -import java.time.Instant - -class SequencesTest { - - @Test - fun shouldBuildSequenceWhenUsingFromElements() { - val seqOfElements = sequenceOf("first" ,"second", "third") - .toList() - assertEquals(3, seqOfElements.count()) - } - - @Test - fun shouldBuildSequenceWhenUsingFromFunction() { - val seqFromFunction = generateSequence(Instant.now()) {it.plusSeconds(1)} - .take(3) - .toList() - assertEquals(3, seqFromFunction.count()) - } - - @Test - fun shouldBuildSequenceWhenUsingFromChunks() { - val seqFromChunks = sequence { - yield(1) - yieldAll((2..5).toList()) - }.toList() - assertEquals(5, seqFromChunks.count()) - } - - @Test - fun shouldBuildSequenceWhenUsingFromCollection() { - val seqFromIterable = (1..10) - .asSequence() - .toList() - assertEquals(10, seqFromIterable.count()) - } - - @Test - fun shouldShowNoCountDiffWhenUsingWithAndWithoutSequence() { - val withSequence = (1..10).asSequence() - .filter{it % 2 == 1} - .map { it * 2 } - .toList() - val withoutSequence = (1..10) - .filter{it % 2 == 1} - .map { it * 2 } - .toList() - assertEquals(withSequence.count(), withoutSequence.count()) - } - -} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt deleted file mode 100644 index 347290de72..0000000000 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.ternary - -import org.junit.Test -import kotlin.test.assertEquals - -class TernaryOperatorTest { - - @Test - fun `using If`() { - val a = true - val result = if (a) "yes" else "no" - assertEquals("yes", result) - } - - @Test - fun `using When`() { - val a = true - val result = when(a) { - true -> "yes" - false -> "no" - } - assertEquals("yes", result) - } - - @Test - fun `using elvis`() { - val a: String? = null - val result = a ?: "Default" - - assertEquals("Default", result) - } -} \ No newline at end of file diff --git a/core-kotlin-modules/pom.xml b/core-kotlin-modules/pom.xml deleted file mode 100644 index 67520a7dee..0000000000 --- a/core-kotlin-modules/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - com.baeldung.core-kotlin-modules - core-kotlin-modules - core-kotlin-modules - pom - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../parent-kotlin - - - - core-kotlin - core-kotlin-advanced - core-kotlin-annotations - core-kotlin-collections - core-kotlin-collections-2 - core-kotlin-concurrency - core-kotlin-date-time - core-kotlin-design-patterns - core-kotlin-io - core-kotlin-lang - core-kotlin-lang-2 - core-kotlin-lang-oop - core-kotlin-lang-oop-2 - core-kotlin-strings - core-kotlin-testing - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - 1.8 - - - - - - - 1.3.30 - - - diff --git a/jee-kotlin/README.md b/jee-kotlin/README.md deleted file mode 100644 index e8975a7f62..0000000000 --- a/jee-kotlin/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## JEE in Kotlin - -This module contains articles about Java EE with Kotlin. - -### Relevant Articles: -- [Jakarta EE Application with Kotlin](https://www.baeldung.com/java-ee-kotlin-app) diff --git a/jee-kotlin/pom.xml b/jee-kotlin/pom.xml deleted file mode 100644 index 45d5d8ece1..0000000000 --- a/jee-kotlin/pom.xml +++ /dev/null @@ -1,288 +0,0 @@ - - - 4.0.0 - jee-kotlin - jee-kotlin - war - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - - org.jboss.arquillian - arquillian-bom - ${arquillian_core.version} - import - pom - - - org.jboss.arquillian.extension - arquillian-drone-bom - ${arquillian-drone-bom.version} - pom - import - - - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - test - - - junit - junit - ${junit.version} - test - - - javax - javaee-api - ${javaee-api.version} - jar - provided - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - test - - - org.jboss.arquillian.junit - arquillian-junit-container - ${arquillian_core.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-depchain - ${shrinkwrap.version} - pom - test - - - org.jboss.arquillian.extension - arquillian-rest-client-impl-jersey - ${arquillian-rest-client.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - - - src/main/kotlin - src/test/kotlin - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - 1.8 - - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - webapp - kotlin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - default-compile - none - - - default-testCompile - none - - - compile - compile - - compile - - - - testCompile - test-compile - - testCompile - - - - - - - - - - wildfly-managed-arquillian - - true - - - - org.wildfly - wildfly-arquillian-container-embedded - ${wildfly.version} - - - org.wildfly - wildfly-embedded - ${wildfly.version} - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - unpack - process-test-classes - - unpack - - - - - org.wildfly - wildfly-dist - ${wildfly.version} - zip - false - target - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - always - - org.jboss.logmanager.LogManager - ${project.basedir}/target/wildfly-${wildfly.version} - 8756 - ${project.basedir}/target/wildfly-${wildfly.version}/modules - - false - - - - - - - wildfly-remote-arquillian-disabled - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly.arquillian - wildfly-arquillian-container-remote - ${wildfly.arquillian.version} - test - - - - - - - 2.2.0.Final - UTF-8 - false - 8.0 - - 1.3.41 - official - true - - 8.2.1.Final - 2.21.0 - 3.1.1 - - 1.4.1.Final - 2.0.1.Final - 1.0.0.Alpha4 - - 1.1.7 - - 3.8.0.Final - 3.1.3 - - - diff --git a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/entity/Student.kt b/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/entity/Student.kt deleted file mode 100644 index 07f54a39d1..0000000000 --- a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/entity/Student.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.jeekotlin.entity - -import com.fasterxml.jackson.annotation.JsonProperty -import javax.persistence.* - -@Entity -data class Student constructor ( - - @SequenceGenerator(name = "student_id_seq", sequenceName = "student_id_seq", allocationSize = 1) - @GeneratedValue(generator = "student_id_seq", strategy = GenerationType.SEQUENCE) - @Id - var id: Long?, - - var firstName: String, - - var lastName: String - -) { - constructor() : this(null, "", "") - - constructor(firstName: String, lastName: String) : this(null, firstName, lastName) -} diff --git a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/ApplicationConfig.kt b/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/ApplicationConfig.kt deleted file mode 100644 index 12511ed320..0000000000 --- a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/ApplicationConfig.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.jeekotlin.rest - -import javax.ws.rs.ApplicationPath -import javax.ws.rs.core.Application - -@ApplicationPath("/") -class ApplicationConfig : Application() { - override fun getClasses() = setOf(StudentResource::class.java) -} diff --git a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/StudentResource.kt b/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/StudentResource.kt deleted file mode 100644 index 91fa3ff62b..0000000000 --- a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/rest/StudentResource.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.jeekotlin.rest - -import com.baeldung.jeekotlin.entity.Student -import com.baeldung.jeekotlin.service.StudentService -import javax.inject.Inject -import javax.ws.rs.* -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response - -@Path("/student") -open class StudentResource { - - @Inject - private lateinit var service: StudentService - - @POST - open fun create(student: Student): Response { - service.create(student) - return Response.ok().build() - } - - @GET - @Path("/{id}") - open fun read(@PathParam("id") id: Long): Response { - val student = service.read(id) - return Response.ok(student, MediaType.APPLICATION_JSON_TYPE).build() - } - - @PUT - open fun update(student: Student): Response { - service.update(student) - return Response.ok(student, MediaType.APPLICATION_JSON_TYPE).build() - } - - @DELETE - @Path("/{id}") - open fun delete(@PathParam("id") id: Long): Response { - service.delete(id) - return Response.noContent().build() - } - -} \ No newline at end of file diff --git a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/service/StudentService.kt b/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/service/StudentService.kt deleted file mode 100644 index 3977a45e96..0000000000 --- a/jee-kotlin/src/main/kotlin/com/baeldung/jeekotlin/service/StudentService.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.jeekotlin.service - -import com.baeldung.jeekotlin.entity.Student -import javax.ejb.Stateless -import javax.persistence.EntityManager -import javax.persistence.PersistenceContext - -@Stateless -open class StudentService { - - @PersistenceContext - private lateinit var entityManager: EntityManager - - open fun create(student: Student) = entityManager.persist(student) - - open fun read(id: Long): Student? = entityManager.find(Student::class.java, id) - - open fun update(student: Student) = entityManager.merge(student) - - open fun delete(id: Long) = entityManager.remove(read(id)) -} \ No newline at end of file diff --git a/jee-kotlin/src/main/resources/META-INF/persistence.xml b/jee-kotlin/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index 0093792810..0000000000 --- a/jee-kotlin/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - org.hibernate.jpa.HibernatePersistenceProvider - - java:jboss/datasources/ExampleDS - - com.baeldung.jeekotlin.entity.Student - - - - - - - - diff --git a/jee-kotlin/src/main/webapp/WEB-INF/beans.xml b/jee-kotlin/src/main/webapp/WEB-INF/beans.xml deleted file mode 100644 index ae0f4bf2ee..0000000000 --- a/jee-kotlin/src/main/webapp/WEB-INF/beans.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - \ No newline at end of file diff --git a/jee-kotlin/src/test/kotlin/com/baeldung/jeekotlin/StudentResourceIntegrationTest.java b/jee-kotlin/src/test/kotlin/com/baeldung/jeekotlin/StudentResourceIntegrationTest.java deleted file mode 100644 index d48a3a96da..0000000000 --- a/jee-kotlin/src/test/kotlin/com/baeldung/jeekotlin/StudentResourceIntegrationTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.baeldung.jeekotlin; - -import com.baeldung.jeekotlin.entity.Student; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.Filters; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.shrinkwrap.resolver.api.maven.Maven; -import org.junit.Test; -import org.junit.runner.RunWith; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.net.URISyntaxException; -import java.net.URL; - -import static org.junit.Assert.assertEquals; - -@RunWith(Arquillian.class) -public class StudentResourceIntegrationTest { - - @Deployment - public static WebArchive createDeployment() { - JavaArchive[] kotlinRuntime = Maven.configureResolver() - .workOffline() - .withMavenCentralRepo(true) - .withClassPathResolution(true) - .loadPomFromFile("pom.xml") - .resolve("org.jetbrains.kotlin:kotlin-stdlib:1.3.41") - .withTransitivity() - .as(JavaArchive.class); - - return ShrinkWrap.create(WebArchive.class, "kotlin.war") - .addPackages(true, Filters.exclude(".*Test*"), - "com.baeldung.jeekotlin" - ) - .addAsLibraries(kotlinRuntime) - .addAsResource("META-INF/persistence.xml") - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @RunAsClient - public void when_post__then_return_ok(@ArquillianResource URL url) throws URISyntaxException, JsonProcessingException { - String student = new ObjectMapper().writeValueAsString(new Student("firstName", "lastName")); - WebTarget webTarget = ClientBuilder.newClient().target(url.toURI()); - - Response response = webTarget - .path("/student") - .request(MediaType.APPLICATION_JSON) - .post(Entity.json(student)); - - assertEquals(200, response.getStatus()); - } - - @Test - @RunAsClient - public void when_get__then_return_ok(@ArquillianResource URL url) throws URISyntaxException, JsonProcessingException { - WebTarget webTarget = ClientBuilder.newClient().target(url.toURI()); - - Response response = webTarget - .path("/student/1") - .request(MediaType.APPLICATION_JSON) - .get(); - - assertEquals(200, response.getStatus()); - } - - @Test - @RunAsClient - public void when_put__then_return_ok(@ArquillianResource URL url) throws URISyntaxException, JsonProcessingException { - Student student = new Student("firstName", "lastName"); - student.setId(1L); - String studentJson = new ObjectMapper().writeValueAsString(student); - WebTarget webTarget = ClientBuilder.newClient().target(url.toURI()); - - Response response = webTarget - .path("/student") - .request(MediaType.APPLICATION_JSON) - .put(Entity.json(studentJson)); - - assertEquals(200, response.getStatus()); - } - - @Test - @RunAsClient - public void when_delete__then_return_ok(@ArquillianResource URL url) throws URISyntaxException, JsonProcessingException { - WebTarget webTarget = ClientBuilder.newClient().target(url.toURI()); - - Response response = webTarget - .path("/student/1") - .request() - .delete(); - - assertEquals(204, response.getStatus()); - } - -} \ No newline at end of file diff --git a/jee-kotlin/src/test/resources/arquillian.xml b/jee-kotlin/src/test/resources/arquillian.xml deleted file mode 100644 index 5e6d7c54e8..0000000000 --- a/jee-kotlin/src/test/resources/arquillian.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - target/wildfly-8.2.1.Final - standalone.xml - true - 9990 - - - - - - 127.0.0.1 - 9990 - admin - pass - true - - - - \ No newline at end of file diff --git a/kotlin-js/.gitignore b/kotlin-js/.gitignore deleted file mode 100644 index 1db5e66882..0000000000 --- a/kotlin-js/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/bin/ - -#ignore gradle -.gradle/ - - -#ignore build and generated files -build/ -node/ - -#ignore installed node modules and package lock file -node_modules/ -package-lock.json diff --git a/kotlin-js/README.md b/kotlin-js/README.md deleted file mode 100644 index 2ec50bad78..0000000000 --- a/kotlin-js/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## JavaScript in Kotlin - -This module contains articles about JavaScript in Kotlin. - -### Relevant Articles: - -- [Kotlin and Javascript](https://www.baeldung.com/kotlin-javascript) diff --git a/kotlin-js/build.gradle b/kotlin-js/build.gradle deleted file mode 100644 index ede6f51448..0000000000 --- a/kotlin-js/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -buildscript { - ext.kotlin_version = '1.4.10' - repositories { - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -group 'com.baeldung' -version '1.0-SNAPSHOT' -apply plugin: 'kotlin2js' - -repositories { - mavenCentral() -} - -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" -} - -compileKotlin2Js.kotlinOptions { - moduleKind = "commonjs" - outputFile = "node/crypto.js" -} diff --git a/kotlin-js/gradle/wrapper/gradle-wrapper.jar b/kotlin-js/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 490fda8577df6c95960ba7077c43220e5bb2c0d9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 58694 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 diff --git a/kotlin-js/gradle/wrapper/gradle-wrapper.properties b/kotlin-js/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index a4b4429748..0000000000 --- a/kotlin-js/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/kotlin-js/gradlew b/kotlin-js/gradlew deleted file mode 100755 index 2fe81a7d95..0000000000 --- a/kotlin-js/gradlew +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/kotlin-js/gradlew.bat b/kotlin-js/gradlew.bat deleted file mode 100644 index 9109989e3c..0000000000 --- a/kotlin-js/gradlew.bat +++ /dev/null @@ -1,103 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/kotlin-js/package.json b/kotlin-js/package.json deleted file mode 100644 index 915b9d41ea..0000000000 --- a/kotlin-js/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "kotlin-node", - "version": "1.0.0", - "description": "Example of using NodeJS in Kotlin", - "main": "crypto.js", - "scripts": { - "start": "node node/crypto.js" - }, - "author": "", - "license": "ISC", - "dependencies": { - "express": "^4.17.1", - "kotlin": "^1.4.10" - } -} diff --git a/kotlin-js/settings.gradle b/kotlin-js/settings.gradle deleted file mode 100755 index 30c62d39ef..0000000000 --- a/kotlin-js/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'kotlin-node' diff --git a/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt b/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt deleted file mode 100755 index 92ef4a7356..0000000000 --- a/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.kotlinjs - -external fun require(module: String): dynamic - -data class CryptoCurrency(var name: String, var price: Float) - -fun main(args: Array) { - println("Crypto Currency price API!") - val express = require("express") - val app = express() - - app.get("/crypto", { _, res -> - res.send(generateCryptoRates()) - }) - - app.listen(3000, { - println("Listening on port 3000") - }) -} -fun generateCryptoRates(): Array{ - val cryptoCurrency = arrayOf( - CryptoCurrency("Bitcoin", 90000F), - CryptoCurrency("ETH",1000F), - CryptoCurrency("TRX",10F) - ); - return cryptoCurrency -} \ No newline at end of file diff --git a/kotlin-js/src/main/resources/logback.xml b/kotlin-js/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/kotlin-js/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/kotlin-libraries-2/.gitignore b/kotlin-libraries-2/.gitignore deleted file mode 100644 index 0c017e8f8c..0000000000 --- a/kotlin-libraries-2/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -/bin/ - -#ignore gradle -.gradle/ - - -#ignore build and generated files -build/ -node/ -out/ - -#ignore installed node modules and package lock file -node_modules/ -package-lock.json diff --git a/kotlin-libraries-2/README.md b/kotlin-libraries-2/README.md deleted file mode 100644 index f725048acd..0000000000 --- a/kotlin-libraries-2/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Kotlin Libraries - -This module contains articles about Kotlin Libraries. - -### Relevant articles: - -- [Jackson Support for Kotlin](https://www.baeldung.com/jackson-kotlin) -- [Introduction to RxKotlin](https://www.baeldung.com/rxkotlin) -- [MockK: A Mocking Library for Kotlin](https://www.baeldung.com/kotlin-mockk) -- [Kotlin Immutable Collections](https://www.baeldung.com/kotlin-immutable-collections) -- [Dependency Injection for Kotlin with Injekt](https://www.baeldung.com/kotlin-dependency-injection-with-injekt) -- [Fuel HTTP Library with Kotlin](https://www.baeldung.com/kotlin-fuel) -- [Introduction to Kovenant Library for Kotlin](https://www.baeldung.com/kotlin-kovenant) -- More articles: [[<-- prev]](/kotlin-libraries) diff --git a/kotlin-libraries-2/pom.xml b/kotlin-libraries-2/pom.xml deleted file mode 100644 index 254f2c6907..0000000000 --- a/kotlin-libraries-2/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - kotlin-libraries-2 - kotlin-libraries-2 - jar - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../parent-kotlin - - - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - io.reactivex.rxjava2 - rxkotlin - ${rxkotlin.version} - - - junit - junit - test - - - com.google.guava - guava - ${guava.version} - - - - org.jetbrains.kotlinx - kotlinx-collections-immutable - ${kotlinx-collections-immutable.version} - - - uy.kohesive.injekt - injekt-core - ${injekt-core.version} - - - com.github.kittinunf.fuel - fuel - ${fuel.version} - - - com.github.kittinunf.fuel - fuel-gson - ${fuel.version} - - - com.github.kittinunf.fuel - fuel-rxjava - ${fuel.version} - - - com.github.kittinunf.fuel - fuel-coroutines - ${fuel.version} - - - nl.komponents.kovenant - kovenant - ${kovenant.version} - pom - - - - io.mockk - mockk - ${mockk.version} - test - - - - - 1.16.1 - 1.15.0 - 3.3.0 - 27.1-jre - 1.9.3 - 0.1 - 2.3.0 - - - diff --git a/kotlin-libraries-2/resources/logback.xml b/kotlin-libraries-2/resources/logback.xml deleted file mode 100644 index 9452207268..0000000000 --- a/kotlin-libraries-2/resources/logback.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Interceptors.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Interceptors.kt deleted file mode 100644 index 377ef979dc..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Interceptors.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.fuel - -import com.github.kittinunf.fuel.core.Request - -fun tokenInterceptor() = { - next: (Request) -> Request -> - { req: Request -> - req.header(mapOf("Authorization" to "Bearer AbCdEf123456")) - next(req) - } -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Post.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Post.kt deleted file mode 100644 index 035dfe7aa0..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/Post.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.fuel - -import com.github.kittinunf.fuel.core.ResponseDeserializable -import com.google.gson.Gson - -data class Post(var userId:Int, - var id:Int, - var title:String, - var body:String){ - - - class Deserializer : ResponseDeserializable> { - override fun deserialize(content: String): Array = Gson().fromJson(content, Array::class.java) - } -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/PostRoutingAPI.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/PostRoutingAPI.kt deleted file mode 100644 index 8238c41e56..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/fuel/PostRoutingAPI.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.fuel - -import com.github.kittinunf.fuel.core.Method -import com.github.kittinunf.fuel.util.FuelRouting - -sealed class PostRoutingAPI : FuelRouting { - - override val basePath = "https://jsonplaceholder.typicode.com" - - class posts(val id: String, override val body: String?): PostRoutingAPI() - - class comments(val postId: String, override val body: String?): PostRoutingAPI() - - override val method: Method - get() { - return when(this) { - is PostRoutingAPI.posts -> Method.GET - is PostRoutingAPI.comments -> Method.GET - } - } - - override val path: String - get() { - return when(this) { - is PostRoutingAPI.posts -> "/posts" - is PostRoutingAPI.comments -> "/comments" - } - } - - override val params: List>? - get() { - return when(this) { - is PostRoutingAPI.posts -> listOf("id" to this.id) - is PostRoutingAPI.comments -> listOf("postId" to this.postId) - } - } - - override val headers: Map? - get() { - return null - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/DelegateInjectionApplication.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/DelegateInjectionApplication.kt deleted file mode 100644 index fb9beda621..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/DelegateInjectionApplication.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.injekt - -import org.slf4j.LoggerFactory -import uy.kohesive.injekt.* -import uy.kohesive.injekt.api.* -import java.util.* - -class DelegateInjectionApplication { - companion object : InjektMain() { - private val LOG = LoggerFactory.getLogger(DelegateInjectionApplication::class.java) - @JvmStatic fun main(args: Array) { - DelegateInjectionApplication().run() - } - - override fun InjektRegistrar.registerInjectables() { - addFactory { - val value = FactoryInstance("Factory" + UUID.randomUUID().toString()) - LOG.info("Constructing instance: {}", value) - value - } - - addSingletonFactory { - val value = SingletonInstance("Singleton" + UUID.randomUUID().toString()) - LOG.info("Constructing singleton instance: {}", value) - value - } - - addSingletonFactory { App() } - } - } - - data class FactoryInstance(val value: String) - data class SingletonInstance(val value: String) - - class App { - private val instance: FactoryInstance by injectValue() - private val lazyInstance: FactoryInstance by injectLazy() - private val singleton: SingletonInstance by injectValue() - private val lazySingleton: SingletonInstance by injectLazy() - - fun run() { - for (i in 1..5) { - LOG.info("Instance {}: {}", i, instance) - } - for (i in 1..5) { - LOG.info("Lazy Instance {}: {}", i, lazyInstance) - } - for (i in 1..5) { - LOG.info("Singleton {}: {}", i, singleton) - } - for (i in 1..5) { - LOG.info("Lazy Singleton {}: {}", i, lazySingleton) - } - } - } - - fun run() { - Injekt.get().run() - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/KeyedApplication.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/KeyedApplication.kt deleted file mode 100644 index 4205678981..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/KeyedApplication.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.injekt - -import org.slf4j.LoggerFactory -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.InjektMain -import uy.kohesive.injekt.api.InjektRegistrar -import uy.kohesive.injekt.api.addPerKeyFactory -import uy.kohesive.injekt.api.addSingletonFactory -import uy.kohesive.injekt.api.get - -class KeyedApplication { - companion object : InjektMain() { - private val LOG = LoggerFactory.getLogger(KeyedApplication::class.java) - @JvmStatic fun main(args: Array) { - KeyedApplication().run() - } - - override fun InjektRegistrar.registerInjectables() { - val configs = mapOf( - "google" to Config("googleClientId", "googleClientSecret"), - "twitter" to Config("twitterClientId", "twitterClientSecret") - ) - addPerKeyFactory {key -> configs[key]!! } - - addSingletonFactory { App() } - } - } - - data class Config(val clientId: String, val clientSecret: String) - - class App { - fun run() { - LOG.info("Google config: {}", Injekt.get("google")) - LOG.info("Twitter config: {}", Injekt.get("twitter")) - } - } - - fun run() { - Injekt.get().run() - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/ModularApplication.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/ModularApplication.kt deleted file mode 100644 index 96a0c9556a..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/ModularApplication.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.injekt - -import org.slf4j.LoggerFactory -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.InjektMain -import uy.kohesive.injekt.api.* - -class ModularApplication { - class ConfigModule(private val port: Int) : InjektModule { - override fun InjektRegistrar.registerInjectables() { - addSingleton(Config(port)) - } - } - - object ServerModule : InjektModule { - override fun InjektRegistrar.registerInjectables() { - addSingletonFactory { Server(Injekt.get()) } - } - } - - companion object : InjektMain() { - private val LOG = LoggerFactory.getLogger(Server::class.java) - @JvmStatic fun main(args: Array) { - ModularApplication().run() - } - - override fun InjektRegistrar.registerInjectables() { - importModule(ConfigModule(12345)) - importModule(ServerModule) - } - } - - data class Config( - val port: Int - ) - - class Server(private val config: Config) { - - fun start() { - LOG.info("Starting server on ${config.port}") - } - } - - fun run() { - Injekt.get().start() - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/PerThreadApplication.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/PerThreadApplication.kt deleted file mode 100644 index f3167bc223..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/PerThreadApplication.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.injekt - -import org.slf4j.LoggerFactory -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.InjektMain -import uy.kohesive.injekt.api.InjektRegistrar -import uy.kohesive.injekt.api.addPerThreadFactory -import uy.kohesive.injekt.api.addSingletonFactory -import uy.kohesive.injekt.api.get -import java.util.* -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit - -class PerThreadApplication { - companion object : InjektMain() { - private val LOG = LoggerFactory.getLogger(PerThreadApplication::class.java) - @JvmStatic fun main(args: Array) { - PerThreadApplication().run() - } - - override fun InjektRegistrar.registerInjectables() { - addPerThreadFactory { - val value = FactoryInstance(UUID.randomUUID().toString()) - LOG.info("Constructing instance: {}", value) - value - } - - addSingletonFactory { App() } - } - } - - data class FactoryInstance(val value: String) - - class App { - fun run() { - val threadPool = Executors.newFixedThreadPool(5) - - for (i in 1..20) { - threadPool.submit { - val instance = Injekt.get() - LOG.info("Value for thread {}: {}", Thread.currentThread().id, instance) - TimeUnit.MILLISECONDS.sleep(100) - } - } - threadPool.awaitTermination(10, TimeUnit.SECONDS) - } - } - - fun run() { - Injekt.get().run() - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/SimpleApplication.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/SimpleApplication.kt deleted file mode 100644 index 5c2dc28ba5..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/injekt/SimpleApplication.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.injekt - -import org.slf4j.LoggerFactory -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.InjektMain -import uy.kohesive.injekt.api.InjektRegistrar -import uy.kohesive.injekt.api.addSingleton -import uy.kohesive.injekt.api.addSingletonFactory -import uy.kohesive.injekt.api.get - -class SimpleApplication { - companion object : InjektMain() { - private val LOG = LoggerFactory.getLogger(Server::class.java) - @JvmStatic fun main(args: Array) { - SimpleApplication().run() - } - - override fun InjektRegistrar.registerInjectables() { - addSingleton(Config(12345)) - addSingletonFactory { Server(Injekt.get()) } - } - } - - data class Config( - val port: Int - ) - - class Server(private val config: Config) { - - fun start() { - LOG.info("Starting server on ${config.port}") - } - } - - fun run() { - Injekt.get().start() - } -} diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt deleted file mode 100644 index 4ff47ea987..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.kotlin.jackson - -import com.fasterxml.jackson.annotation.* - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -data class Book(var title: String, @JsonProperty("author") var authorName: String) { - var genres: List? = emptyList() -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt deleted file mode 100644 index 445b6013d5..0000000000 --- a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.jackson - -data class Movie(var name: String, var studio: String, var rating: Float? = 1f) \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt deleted file mode 100644 index 69b6ae88c6..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt +++ /dev/null @@ -1,280 +0,0 @@ -package com.baeldung.fuel - -import com.github.kittinunf.fuel.Fuel -import com.github.kittinunf.fuel.core.FuelManager -import com.github.kittinunf.fuel.core.interceptors.cUrlLoggingRequestInterceptor -import com.github.kittinunf.fuel.gson.responseObject -import com.github.kittinunf.fuel.httpGet -import com.github.kittinunf.fuel.rx.rx_object -import com.google.gson.Gson -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test -import java.io.File -import java.util.concurrent.CountDownLatch - -/** - * These live tests make connections to the external systems: http://httpbin.org, https://jsonplaceholder.typicode.com - * Make sure these hosts are up and your internet connection is on before running the tests. - */ -internal class FuelHttpLiveTest { - - @Test - fun whenMakingAsyncHttpGetRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val latch = CountDownLatch(1) - - "http://httpbin.org/get".httpGet().response{ - request, response, result -> - - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - - latch.countDown() - } - - latch.await() - - } - - @Test - fun whenMakingSyncHttpGetRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val (request, response, result) = "http://httpbin.org/get".httpGet().response() - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - - } - - @Test - fun whenMakingSyncHttpGetURLEncodedRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val (request, response, result) = - "https://jsonplaceholder.typicode.com/posts" - .httpGet(listOf("id" to "1")).response() - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - - } - - @Test - fun whenMakingAsyncHttpPostRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val latch = CountDownLatch(1) - - Fuel.post("http://httpbin.org/post").response{ - request, response, result -> - - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - - latch.countDown() - } - - latch.await() - - } - - @Test - fun whenMakingSyncHttpPostRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val (request, response, result) = Fuel.post("http://httpbin.org/post").response() - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - } - - @Test - fun whenMakingSyncHttpPostRequestwithBody_thenResponseNotNullAndErrorNullAndStatusCode200() { - - val (request, response, result) = Fuel.post("https://jsonplaceholder.typicode.com/posts") - .body("{ \"title\" : \"foo\",\"body\" : \"bar\",\"id\" : \"1\"}") - .response() - - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(201,response.statusCode) - } - - @Test - fun givenFuelInstance_whenMakingSyncHttpGetRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - FuelManager.instance.basePath = "http://httpbin.org" - FuelManager.instance.baseHeaders = mapOf("OS" to "macOS High Sierra") - - FuelManager.instance.addRequestInterceptor(cUrlLoggingRequestInterceptor()) - FuelManager.instance.addRequestInterceptor(tokenInterceptor()) - - - val (request, response, result) = "/get" - .httpGet().response() - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - } - - @Test - fun givenInterceptors_whenMakingSyncHttpGetRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { - - FuelManager.instance.basePath = "http://httpbin.org" - FuelManager.instance.addRequestInterceptor(cUrlLoggingRequestInterceptor()) - FuelManager.instance.addRequestInterceptor(tokenInterceptor()) - - val (request, response, result) = "/get" - .httpGet().response() - val (data, error) = result - - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - } - - @Test - fun whenDownloadFile_thenCreateFileResponseNotNullAndErrorNullAndStatusCode200() { - - Fuel.download("http://httpbin.org/bytes/32768").destination { response, url -> - File.createTempFile("temp", ".tmp") - }.response{ - request, response, result -> - - val (data, error) = result - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - } - } - - @Test - fun whenDownloadFilewithProgressHandler_thenCreateFileResponseNotNullAndErrorNullAndStatusCode200() { - - val (request, response, result) = Fuel.download("http://httpbin.org/bytes/327680") - .destination { response, url -> File.createTempFile("temp", ".tmp") - }.progress { readBytes, totalBytes -> - val progress = readBytes.toFloat() / totalBytes.toFloat() - }.response () - - val (data, error) = result - Assertions.assertNull(error) - Assertions.assertNotNull(data) - Assertions.assertEquals(200,response.statusCode) - - - } - - @Test - fun whenMakeGetRequest_thenDeserializePostwithGson() { - - val latch = CountDownLatch(1) - - "https://jsonplaceholder.typicode.com/posts/1".httpGet().responseObject { _,_, result -> - val post = result.component1() - Assertions.assertEquals(1, post?.userId) - latch.countDown() - } - - latch.await() - - } - - @Test - fun whenMakePOSTRequest_thenSerializePostwithGson() { - - val post = Post(1,1, "Lorem", "Lorem Ipse dolor sit amet") - - val (request, response, result) = Fuel.post("https://jsonplaceholder.typicode.com/posts") - .header("Content-Type" to "application/json") - .body(Gson().toJson(post).toString()) - .response() - - Assertions.assertEquals(201,response.statusCode) - - } - - @Test - fun whenMakeGETRequestWithRxJava_thenDeserializePostwithGson() { - - val latch = CountDownLatch(1) - - - "https://jsonplaceholder.typicode.com/posts?id=1" - .httpGet().rx_object(Post.Deserializer()).subscribe{ - res, throwable -> - - val post = res.component1() - Assertions.assertEquals(1, post?.get(0)?.userId) - latch.countDown() - } - - latch.await() - - } - - -// The new 1.3 coroutine APIs, aren't implemented yet in Fuel Library -// @Test -// fun whenMakeGETRequestUsingCoroutines_thenResponseStatusCode200() = runBlocking { -// val (request, response, result) = Fuel.get("http://httpbin.org/get").awaitStringResponse() -// -// result.fold({ data -> -// Assertions.assertEquals(200, response.statusCode) -// -// }, { error -> }) -// } - -// The new 1.3 coroutine APIs, aren't implemented yet in Fuel Library -// @Test -// fun whenMakeGETRequestUsingCoroutines_thenDeserializeResponse() = runBlocking { -// Fuel.get("https://jsonplaceholder.typicode.com/posts?id=1").awaitObjectResult(Post.Deserializer()) -// .fold({ data -> -// Assertions.assertEquals(1, data.get(0).userId) -// }, { error -> }) -// } - - @Test - fun whenMakeGETPostRequestUsingRoutingAPI_thenDeserializeResponse() { - - val latch = CountDownLatch(1) - - Fuel.request(PostRoutingAPI.posts("1",null)) - .responseObject(Post.Deserializer()) { - request, response, result -> - Assertions.assertEquals(1, result.component1()?.get(0)?.userId) - latch.countDown() - } - - latch.await() - } - - @Test - fun whenMakeGETCommentRequestUsingRoutingAPI_thenResponseStausCode200() { - - val latch = CountDownLatch(1) - - Fuel.request(PostRoutingAPI.comments("1",null)) - .responseString { request, response, result -> - Assertions.assertEquals(200, response.statusCode) - latch.countDown() - } - - latch.await() - } - - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt deleted file mode 100644 index 9159be96be..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.gson - -import com.google.gson.Gson - -import org.junit.Assert -import org.junit.Test - -class GsonUnitTest { - - var gson = Gson() - - @Test - fun givenObject_thenGetJSONString() { - var jsonString = gson.toJson(TestModel(1, "Test")) - Assert.assertEquals(jsonString, "{\"id\":1,\"description\":\"Test\"}") - } - - @Test - fun givenJSONString_thenGetObject() { - var jsonString = "{\"id\":1,\"description\":\"Test\"}"; - var testModel = gson.fromJson(jsonString, TestModel::class.java) - Assert.assertEquals(testModel.id, 1) - Assert.assertEquals(testModel.description, "Test") - } - - data class TestModel( - val id: Int, - val description: String - ) -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/KotlinxImmutablesUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/KotlinxImmutablesUnitTest.kt deleted file mode 100644 index 971f2de4c2..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/KotlinxImmutablesUnitTest.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.kotlin.immutable - -import junit.framework.Assert.assertEquals -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.immutableListOf -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException - -class KotlinxImmutablesUnitTest{ - - - @Rule - @JvmField - var ee : ExpectedException = ExpectedException.none() - - @Test - fun givenKICLList_whenAddTried_checkExceptionThrown(){ - - val list: ImmutableList = immutableListOf("I", "am", "immutable") - - list.add("My new item") - - assertEquals(listOf("I", "am", "immutable"), list) - - } -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/ReadOnlyUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/ReadOnlyUnitTest.kt deleted file mode 100644 index 62c4a4eb88..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/immutable/ReadOnlyUnitTest.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.kotlin.immutable - -import com.google.common.collect.ImmutableList -import com.google.common.collect.ImmutableSet -import junit.framework.Assert.assertEquals -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException - -class ReadOnlyUnitTest{ - - @Test - fun givenReadOnlyList_whenCastToMutableList_checkNewElementsAdded(){ - - val list: List = listOf("This", "Is", "Totally", "Immutable") - - (list as MutableList)[2] = "Not" - - assertEquals(listOf("This", "Is", "Not", "Immutable"), list) - - } - - @Rule - @JvmField - var ee : ExpectedException = ExpectedException.none() - - @Test - fun givenImmutableList_whenAddTried_checkExceptionThrown(){ - - val list: List = ImmutableList.of("I", "am", "actually", "immutable") - - ee.expect(UnsupportedOperationException::class.java) - - (list as MutableList).add("Oops") - - } - - @Test - fun givenMutableList_whenCopiedAndAddTried_checkExceptionThrown(){ - - val mutableList : List = listOf("I", "Am", "Definitely", "Immutable") - - (mutableList as MutableList)[2] = "100% Not" - - assertEquals(listOf("I", "Am", "100% Not", "Immutable"), mutableList) - - val list: List = ImmutableList.copyOf(mutableList) - - ee.expect(UnsupportedOperationException::class.java) - - (list as MutableList)[2] = "Really?" - - } - - @Test - fun givenImmutableSetBuilder_whenAddTried_checkExceptionThrown(){ - - val mutableList : List = listOf("Hello", "Baeldung") - val set: ImmutableSet = ImmutableSet.builder() - .add("I","am","immutable") - .addAll(mutableList) - .build() - - assertEquals(setOf("Hello", "Baeldung", "I", "am", "immutable"), set) - - ee.expect(UnsupportedOperationException::class.java) - - (set as MutableSet).add("Oops") - - } - - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt deleted file mode 100644 index 0c72edc2fd..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.baeldung.kotlin.jackson - -import org.junit.Test -import kotlin.test.assertTrue -import kotlin.test.assertFalse -import kotlin.test.assertEquals -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.KotlinModule - -class JacksonUnitTest { - //val mapper = jacksonObjectMapper() - val mapper = ObjectMapper().registerModule(KotlinModule()) - - - @Test - fun whenSerializeMovie_thenSuccess() { - val movie = Movie("Endgame", "Marvel", 9.2f) - val serialized = mapper.writeValueAsString(movie) - - val json = """{"name":"Endgame","studio":"Marvel","rating":9.2}""" - assertEquals(serialized, json) - } - - @Test - fun whenDeserializeMovie_thenSuccess() { - val json = """{"name":"Endgame","studio":"Marvel","rating":9.2}""" - // val movie: Movie = mapper.readValue(json) - val movie = mapper.readValue(json) - - assertEquals(movie.name, "Endgame") - assertEquals(movie.studio, "Marvel") - assertEquals(movie.rating, 9.2f) - } - - @Test - fun whenDeserializeMovieWithMissingValue_thenUseDefaultValue() { - val json = """{"name":"Endgame","studio":"Marvel"}""" - val movie: Movie = mapper.readValue(json) - - assertEquals(movie.name, "Endgame") - assertEquals(movie.studio, "Marvel") - assertEquals(movie.rating, 1f) - } - - @Test - fun whenSerializeMap_thenSuccess() { - val map = mapOf(1 to "one", 2 to "two") - val serialized = mapper.writeValueAsString(map) - - val json = """{"1":"one","2":"two"}""" - assertEquals(serialized, json) - } - - @Test - fun whenDeserializeMap_thenSuccess() { - val json = """{"1":"one","2":"two"}""" - val aMap: Map = mapper.readValue(json) - - assertEquals(aMap[1], "one") - assertEquals(aMap[2], "two") - - val sameMap = mapper.readValue>(json) - assertEquals(sameMap[1], "one") - assertEquals(sameMap[2], "two") - } - - @Test - fun whenSerializeList_thenSuccess() { - val movie1 = Movie("Endgame", "Marvel", 9.2f) - val movie2 = Movie("Shazam", "Warner Bros", 7.6f) - val movieList = listOf(movie1, movie2) - val serialized = mapper.writeValueAsString(movieList) - - val json = """[{"name":"Endgame","studio":"Marvel","rating":9.2},{"name":"Shazam","studio":"Warner Bros","rating":7.6}]""" - assertEquals(serialized, json) - } - - @Test - fun whenDeserializeList_thenSuccess() { - val json = """[{"name":"Endgame","studio":"Marvel","rating":9.2},{"name":"Shazam","studio":"Warner Bros","rating":7.6}]""" - val movieList: List = mapper.readValue(json) - - val movie1 = Movie("Endgame", "Marvel", 9.2f) - val movie2 = Movie("Shazam", "Warner Bros", 7.6f) - assertTrue(movieList.contains(movie1)) - assertTrue(movieList.contains(movie2)) - - val sameList = mapper.readValue>(json) - assertTrue(sameList.contains(movie1)) - assertTrue(sameList.contains(movie2)) - } - - @Test - fun whenSerializeBook_thenSuccess() { - val book = Book("Oliver Twist", "Charles Dickens") - val serialized = mapper.writeValueAsString(book) - - val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" - assertEquals(serialized, json) - } - - @Test - fun whenDeserializeBook_thenSuccess() { - val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" - val book: Book = mapper.readValue(json) - - assertEquals(book.title, "Oliver Twist") - assertEquals(book.authorName, "Charles Dickens") - } - - @Test - fun givenJsonInclude_whenSerializeBook_thenEmptyFieldExcluded() { - val book = Book("Oliver Twist", "Charles Dickens") - val serialized = mapper.writeValueAsString(book) - - val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" - assertEquals(serialized, json) - } - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt deleted file mode 100644 index 979ed3f809..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt +++ /dev/null @@ -1,157 +0,0 @@ -package com.baeldung.kotlin.rxkotlin - -import io.reactivex.Maybe -import io.reactivex.Observable -import io.reactivex.functions.BiFunction -import io.reactivex.rxkotlin.* -import io.reactivex.subjects.PublishSubject -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse - -class RxKotlinTest { - - @Test - fun whenBooleanArrayToObserver_thenBooleanObserver() { - val observable = listOf(true, false, false).toObservable() - observable.test().assertValues(true, false, false) - } - - @Test - fun whenBooleanArrayToFlowable_thenBooleanFlowable() { - val flowable = listOf(true, false, false).toFlowable() - flowable.buffer(2).test().assertValues(listOf(true, false), listOf(false)) - } - - @Test - fun whenIntArrayToObserver_thenIntObserver() { - val observable = listOf(1, 1, 2, 3).toObservable() - observable.test().assertValues(1, 1, 2, 3) - } - - @Test - fun whenIntArrayToFlowable_thenIntFlowable() { - val flowable = listOf(1, 1, 2, 3).toFlowable() - flowable.buffer(2).test().assertValues(listOf(1, 1), listOf(2, 3)) - } - - @Test - fun whenObservablePairToMap_thenSingleNoDuplicates() { - val list = listOf(Pair("a", 1), Pair("b", 2), Pair("c", 3), Pair("a", 4)) - val observable = list.toObservable() - val map = observable.toMap() - assertEquals(mapOf(Pair("a", 4), Pair("b", 2), Pair("c", 3)), map.blockingGet()) - } - - @Test - fun whenObservablePairToMap_thenSingleWithDuplicates() { - val list = listOf(Pair("a", 1), Pair("b", 2), Pair("c", 3), Pair("a", 4)) - val observable = list.toObservable() - val map = observable.toMultimap() - assertEquals( - mapOf(Pair("a", listOf(1, 4)), Pair("b", listOf(2)), Pair("c", listOf(3))), - map.blockingGet()) - } - - @Test - fun whenMergeAll_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.mergeAll() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenConcatAll_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.concatAll() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenSwitchLatest_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.switchLatest() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenMergeAllMaybes_thenObservable() { - val subject = PublishSubject.create>() - val observable = subject.mergeAllMaybes() - val testObserver = observable.test() - subject.onNext(Maybe.just(1)) - subject.onNext(Maybe.just(2)) - subject.onNext(Maybe.empty()) - testObserver.assertValues(1, 2) - subject.onNext(Maybe.error(Exception(""))) - subject.onNext(Maybe.just(3)) - testObserver.assertValues(1, 2).assertError(Exception::class.java) - } - - @Test - fun whenMerge_thenStream() { - val observables = mutableListOf(Observable.just("first", "second")) - val observable = observables.merge() - observables.add(Observable.just("third", "fourth")) - observables.add(Observable.error(Exception("e"))) - observables.add(Observable.just("fifth")) - - observable.test().assertValues("first", "second", "third", "fourth").assertError(Exception::class.java) - } - - @Test - fun whenMergeDelayError_thenStream() { - val observables = mutableListOf>(Observable.error(Exception("e1"))) - val observable = observables.mergeDelayError() - observables.add(Observable.just("1", "2")) - observables.add(Observable.error(Exception("e2"))) - observables.add(Observable.just("3")) - - observable.test().assertValues("1", "2", "3").assertError(Exception::class.java) - } - - @Test - fun whenCast_thenUniformType() { - val observable = Observable.just(1, 1, 2, 3) - observable.cast().test().assertValues(1, 1, 2, 3) - } - - @Test - fun whenOfType_thenFilter() { - val observable = Observable.just(1, "and", 2, "and") - observable.ofType().test().assertValues(1, 2) - } - - @Test - fun whenFunction_thenCompletable() { - var value = 0 - val completable = { value = 3 }.toCompletable() - assertFalse(completable.test().isCancelled) - assertEquals(3, value) - } - - @Test - fun whenHelper_thenMoreIdiomaticKotlin() { - val zipWith = Observable.just(1).zipWith(Observable.just(2)) { a, b -> a + b } - zipWith.subscribeBy(onNext = { println(it) }) - val zip = Observables.zip(Observable.just(1), Observable.just(2)) { a, b -> a + b } - zip.subscribeBy(onNext = { println(it) }) - val zipOrig = Observable.zip(Observable.just(1), Observable.just(2), BiFunction { a, b -> a + b }) - zipOrig.subscribeBy(onNext = { println(it) }) - } -} diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTest.kt deleted file mode 100644 index 046b7380f7..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTest.kt +++ /dev/null @@ -1,192 +0,0 @@ -package com.baeldung.kovenant - -import nl.komponents.kovenant.* -import nl.komponents.kovenant.Kovenant.deferred -import nl.komponents.kovenant.combine.and -import nl.komponents.kovenant.combine.combine -import org.junit.Assert -import org.junit.Before -import org.junit.Test -import java.io.IOException -import java.util.* -import java.util.concurrent.TimeUnit - -class KovenantTest { - - @Before - fun setupTestMode() { - Kovenant.testMode { error -> - println("An unexpected error occurred") - Assert.fail(error.message) - } - } - - @Test - fun testSuccessfulDeferred() { - val def = deferred() - Assert.assertFalse(def.promise.isDone()) - - def.resolve(1L) - Assert.assertTrue(def.promise.isDone()) - Assert.assertTrue(def.promise.isSuccess()) - Assert.assertFalse(def.promise.isFailure()) - } - - @Test - fun testFailedDeferred() { - val def = deferred() - Assert.assertFalse(def.promise.isDone()) - - def.reject(RuntimeException()) - Assert.assertTrue(def.promise.isDone()) - Assert.assertFalse(def.promise.isSuccess()) - Assert.assertTrue(def.promise.isFailure()) - } - - @Test - fun testResolveDeferredTwice() { - val def = deferred() - def.resolve(1L) - try { - def.resolve(1L) - } catch (e: AssertionError) { - // Expected. - // This is slightly unusual. The AssertionError comes from Assert.fail() from setupTestMode() - } - } - - @Test - fun testSuccessfulTask() { - val promise = task { 1L } - Assert.assertTrue(promise.isDone()) - Assert.assertTrue(promise.isSuccess()) - Assert.assertFalse(promise.isFailure()) - } - - @Test - fun testFailedTask() { - val promise = task { throw RuntimeException() } - Assert.assertTrue(promise.isDone()) - Assert.assertFalse(promise.isSuccess()) - Assert.assertTrue(promise.isFailure()) - } - - @Test - fun testCallbacks() { - val promise = task { 1L } - - promise.success { - println("This was a success") - Assert.assertEquals(1L, it) - } - - promise.fail { - println(it) - Assert.fail("This shouldn't happen") - } - - promise.always { - println("This always happens") - } - } - - @Test - fun testGetValues() { - val promise = task { 1L } - Assert.assertEquals(1L, promise.get()) - } - - @Test - fun testAllSucceed() { - val numbers = all( - task { 1L }, - task { 2L }, - task { 3L } - ) - - Assert.assertEquals(listOf(1L, 2L, 3L), numbers.get()) - } - - @Test - fun testOneFails() { - val runtimeException = RuntimeException() - - val numbers = all( - task { 1L }, - task { 2L }, - task { throw runtimeException } - ) - - Assert.assertEquals(runtimeException, numbers.getError()) - } - - @Test - fun testAnySucceeds() { - val promise = any( - task { - TimeUnit.SECONDS.sleep(3) - 1L - }, - task { - TimeUnit.SECONDS.sleep(2) - 2L - }, - task { - TimeUnit.SECONDS.sleep(1) - 3L - } - ) - - Assert.assertTrue(promise.isDone()) - Assert.assertTrue(promise.isSuccess()) - Assert.assertFalse(promise.isFailure()) - } - - @Test - fun testAllFails() { - val runtimeException = RuntimeException() - val ioException = IOException() - val illegalStateException = IllegalStateException() - val promise = any( - task { - TimeUnit.SECONDS.sleep(3) - throw runtimeException - }, - task { - TimeUnit.SECONDS.sleep(2) - throw ioException - }, - task { - TimeUnit.SECONDS.sleep(1) - throw illegalStateException - } - ) - - Assert.assertTrue(promise.isDone()) - Assert.assertFalse(promise.isSuccess()) - Assert.assertTrue(promise.isFailure()) - } - - @Test - fun testSimpleCombine() { - val promise = task { 1L } and task { "Hello" } - val result = promise.get() - - Assert.assertEquals(1L, result.first) - Assert.assertEquals("Hello", result.second) - } - - @Test - fun testLongerCombine() { - val promise = combine( - task { 1L }, - task { "Hello" }, - task { Currency.getInstance("USD") } - ) - val result = promise.get() - - Assert.assertEquals(1L, result.first) - Assert.assertEquals("Hello", result.second) - Assert.assertEquals(Currency.getInstance("USD"), result.third) - } -} diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTimeoutTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTimeoutTest.kt deleted file mode 100644 index d98f9c538f..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kovenant/KovenantTimeoutTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.kovenant - -import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.any -import nl.komponents.kovenant.task -import org.junit.Assert -import org.junit.Ignore -import org.junit.Test - -@Ignore -// Note that this can not run in the same test run if KovenantTest has already been executed -class KovenantTimeoutTest { - @Test - fun testTimeout() { - val promise = timedTask(1000) { "Hello" } - val result = promise.get() - Assert.assertEquals("Hello", result) - } - - @Test - fun testTimeoutExpired() { - val promise = timedTask(1000) { - Thread.sleep(3000) - "Hello" - } - val result = promise.get() - Assert.assertNull(result) - } - - fun timedTask(millis: Long, body: () -> T) : Promise> { - val timeoutTask = task { - Thread.sleep(millis) - null - } - val activeTask = task(body = body) - return any(activeTask, timeoutTask) - } -} diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/AnnotationMockKUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/AnnotationMockKUnitTest.kt deleted file mode 100644 index 56cd8b43eb..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/AnnotationMockKUnitTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.mockk - -import io.mockk.MockKAnnotations -import io.mockk.every -import io.mockk.impl.annotations.InjectMockKs -import io.mockk.impl.annotations.MockK -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class InjectTestService { - lateinit var service1: TestableService - lateinit var service2: TestableService - - fun invokeService1(): String { - return service1.getDataFromDb("Test Param") - } -} - -class AnnotationMockKUnitTest { - - @MockK - lateinit var service1: TestableService - - @MockK - lateinit var service2: TestableService - - @InjectMockKs - var objectUnderTest = InjectTestService() - - @BeforeEach - fun setUp() = MockKAnnotations.init(this) - - @Test - fun givenServiceMock_whenCallingMockedMethod_thenCorrectlyVerified() { - // given - every { service1.getDataFromDb("Test Param") } returns "No" - // when - val result = objectUnderTest.invokeService1() - // then - assertEquals("No", result) - } - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/BasicMockKUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/BasicMockKUnitTest.kt deleted file mode 100644 index df4c03be09..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/BasicMockKUnitTest.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.baeldung.mockk - -import io.mockk.* -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - - -class BasicMockKUnitTest { - - @Test - fun givenServiceMock_whenCallingMockedMethod_thenCorrectlyVerified() { - // given - val service = mockk() - every { service.getDataFromDb("Expected Param") } returns "Expected Output" - // when - val result = service.getDataFromDb("Expected Param") - // then - verify { service.getDataFromDb("Expected Param") } - assertEquals("Expected Output", result) - } - - @Test - fun givenServiceSpy_whenMockingOnlyOneMethod_thenOtherMethodsShouldBehaveAsOriginalObject() { - // given - val service = spyk() - every { service.getDataFromDb(any()) } returns "Mocked Output" - // when checking mocked method - val firstResult = service.getDataFromDb("Any Param") - // then - assertEquals("Mocked Output", firstResult) - // when checking not mocked method - val secondResult = service.doSomethingElse("Any Param") - // then - assertEquals("I don't want to!", secondResult) - } - - @Test - fun givenRelaxedMock_whenCallingNotMockedMethod_thenReturnDefaultValue() { - // given - val service = mockk(relaxed = true) - // when - val result = service.getDataFromDb("Any Param") - // then - assertEquals("", result) - } - - @Test - fun givenObject_whenMockingIt_thenMockedMethodShouldReturnProperValue() { - // given - val service = TestableService() - mockkObject(service) - // when calling not mocked method - val firstResult = service.getDataFromDb("Any Param") - // then return real response - assertEquals("Value from DB", firstResult) - - // when calling mocked method - every { service.getDataFromDb(any()) } returns "Mocked Output" - val secondResult = service.getDataFromDb("Any Param") - // then return mocked response - assertEquals("Mocked Output", secondResult) - } - - @Test - fun givenMock_whenCapturingParamValue_thenProperValueShouldBeCaptured() { - // given - val service = mockk() - val slot = slot() - every { service.getDataFromDb(capture(slot)) } returns "Expected Output" - // when - service.getDataFromDb("Expected Param") - // then - assertEquals("Expected Param", slot.captured) - } - - @Test - fun givenMock_whenCapturingParamsValues_thenProperValuesShouldBeCaptured() { - // given - val service = mockk() - val list = mutableListOf() - every { service.getDataFromDb(capture(list)) } returns "Expected Output" - // when - service.getDataFromDb("Expected Param 1") - service.getDataFromDb("Expected Param 2") - // then - assertEquals(2, list.size) - assertEquals("Expected Param 1", list[0]) - assertEquals("Expected Param 2", list[1]) - } - - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/HierarchicalMockKUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/HierarchicalMockKUnitTest.kt deleted file mode 100644 index e9ef133663..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/HierarchicalMockKUnitTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.mockk - -import io.mockk.* -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class Foo { - lateinit var name: String - lateinit var bar: Bar -} - -class Bar { - lateinit var nickname: String -} - -class HierarchicalMockKUnitTest { - - @Test - fun givenHierarchicalClass_whenMockingIt_thenReturnProperValue() { - // given - val foo = mockk { - every { name } returns "Karol" - every { bar } returns mockk { - every { nickname } returns "Tomato" - } - } - // when - val result = foo.bar.nickname - // then - assertEquals("Tomato", result) - } - -} \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/TestableService.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/TestableService.kt deleted file mode 100644 index d6f57e5fb0..0000000000 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/mockk/TestableService.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.mockk - -class TestableService { - fun getDataFromDb(testParameter: String): String { - // query database and return matching value - return "Value from DB" - } - - fun doSomethingElse(testParameter: String): String { - return "I don't want to!" - } -} \ No newline at end of file diff --git a/kotlin-libraries/.gitignore b/kotlin-libraries/.gitignore deleted file mode 100644 index 0c017e8f8c..0000000000 --- a/kotlin-libraries/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -/bin/ - -#ignore gradle -.gradle/ - - -#ignore build and generated files -build/ -node/ -out/ - -#ignore installed node modules and package lock file -node_modules/ -package-lock.json diff --git a/kotlin-libraries/README.md b/kotlin-libraries/README.md deleted file mode 100644 index 570bf9b1e5..0000000000 --- a/kotlin-libraries/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Kotlin Libraries - -This module contains articles about Kotlin Libraries. - -### Relevant articles: - -- [Kotlin with Mockito](https://www.baeldung.com/kotlin-mockito) -- [HTTP Requests with Kotlin and khttp](https://www.baeldung.com/kotlin-khttp) -- [Kotlin Dependency Injection with Kodein](https://www.baeldung.com/kotlin-kodein-dependency-injection) -- [Writing Specifications with Kotlin and Spek](https://www.baeldung.com/kotlin-spek) -- [Processing JSON with Kotlin and Klaxson](https://www.baeldung.com/kotlin-json-klaxson) -- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence) -- [Introduction to Arrow in Kotlin](https://www.baeldung.com/kotlin-arrow) -- [Kotlin with Ktor](https://www.baeldung.com/kotlin-ktor) -- [REST API With Kotlin and Kovert](https://www.baeldung.com/kotlin-kovert) -- More articles: [[next -->]](/kotlin-libraries-2) diff --git a/kotlin-libraries/build.gradle b/kotlin-libraries/build.gradle deleted file mode 100644 index db23a438a0..0000000000 --- a/kotlin-libraries/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ - - -group 'com.baeldung.ktor' -version '1.0-SNAPSHOT' - - -buildscript { - ext.kotlin_version = '1.2.41' - ext.ktor_version = '0.9.2' - ext.khttp_version = '0.1.0' - - repositories { - mavenCentral() - } - dependencies { - - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'application' - -mainClassName = 'APIServer.kt' - -sourceCompatibility = 1.8 -compileKotlin { kotlinOptions.jvmTarget = "1.8" } -compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } - -kotlin { experimental { coroutines "enable" } } - -repositories { - mavenCentral() - jcenter() - maven { url "https://dl.bintray.com/kotlin/ktor" } -} -sourceSets { - main{ - kotlin{ - srcDirs 'com/baeldung/ktor' - } - } - -} - -dependencies { - compile "io.ktor:ktor-server-netty:$ktor_version" - compile "ch.qos.logback:logback-classic:1.2.1" - compile "io.ktor:ktor-gson:$ktor_version" - compile "khttp:khttp:$khttp_version" - testCompile group: 'junit', name: 'junit', version: '4.12' - testCompile group: 'org.jetbrains.spek', name: 'spek-api', version: '1.1.5' - testCompile group: 'org.jetbrains.spek', name: 'spek-subject-extension', version: '1.1.5' - testCompile group: 'org.jetbrains.spek', name: 'spek-junit-platform-engine', version: '1.1.5' - implementation 'com.beust:klaxon:3.0.1' -} - -task runServer(type: JavaExec) { - main = 'APIServer' - classpath = sourceSets.main.runtimeClasspath -} diff --git a/kotlin-libraries/gradle/wrapper/gradle-wrapper.jar b/kotlin-libraries/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 01b8bf6b1f99cad9213fc495b33ad5bbab8efd20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54329 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

<5G2M1WZP5 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 \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/kotlin-libraries/gradlew.bat b/kotlin-libraries/gradlew.bat deleted file mode 100644 index f9553162f1..0000000000 --- a/kotlin-libraries/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/kotlin-libraries/pom.xml b/kotlin-libraries/pom.xml deleted file mode 100644 index 908a545ae3..0000000000 --- a/kotlin-libraries/pom.xml +++ /dev/null @@ -1,171 +0,0 @@ - - - 4.0.0 - kotlin-libraries - kotlin-libraries - jar - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../parent-kotlin - - - - - exposed - exposed - https://dl.bintray.com/kotlin/exposed - - - - false - - kotlinx - bintray - https://dl.bintray.com/kotlin/kotlinx - - - - - - org.jetbrains.spek - spek-api - ${spek.version} - test - - - org.jetbrains.spek - spek-subject-extension - ${spek.version} - test - - - org.jetbrains.spek - spek-junit-platform-engine - ${spek.version} - test - - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - org.junit.platform - junit-platform-runner - test - - - khttp - khttp - ${khttp.version} - - - com.nhaarman - mockito-kotlin - ${mockito-kotlin.version} - test - - - com.github.salomonbrys.kodein - kodein - ${kodein.version} - - - org.assertj - assertj-core - test - - - com.beust - klaxon - ${klaxon.version} - - - org.jetbrains.exposed - exposed - ${exposed.version} - - - com.h2database - h2 - - - - io.arrow-kt - arrow-core - ${arrow-core.version} - - - - uy.kohesive.kovert - kovert-vertx - [1.5.0,1.6.0) - - - nl.komponents.kovenant - kovenant - - - - - nl.komponents.kovenant - kovenant - ${kovenant.version} - pom - - - - - junit - junit - test - - - - - net.bytebuddy - byte-buddy - compile - - - net.bytebuddy - byte-buddy-agent - compile - - - org.objenesis - objenesis - ${objenesis.version} - compile - - - - io.reactivex.rxjava2 - rxkotlin - ${rxkotlin.version} - - - - - 1.5.0 - 4.1.0 - 3.0.4 - 0.1.0 - 3.6.1 - 1.1.1 - 5.2.0 - 3.10.0 - 0.10.4 - 3.3.0 - 1.8.13 - 2.6 - 2.3.0 - 0.7.3 - 1.1.5 - - - diff --git a/kotlin-libraries/resources/logback.xml b/kotlin-libraries/resources/logback.xml deleted file mode 100644 index 9452207268..0000000000 --- a/kotlin-libraries/resources/logback.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/kotlin-libraries/settings.gradle b/kotlin-libraries/settings.gradle deleted file mode 100644 index c91c993971..0000000000 --- a/kotlin-libraries/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'KtorWithKotlin' - diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt deleted file mode 100644 index cc46c65f96..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.klaxon - -import com.beust.klaxon.Json - -class CustomProduct( - @Json(name = "productName") - val name: String, - @Json(ignored = true) - val id: Int) \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt deleted file mode 100644 index 09bcbc8722..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.klaxon - -class Product(val name: String) \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt deleted file mode 100644 index 1f30f26ce9..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.klaxon - -data class ProductData(val name: String, val capacityInGb: Int) \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt deleted file mode 100644 index 75dfb9a2a4..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.kotlin.arrow - -import arrow.core.Either -import arrow.core.filterOrElse -import kotlin.math.sqrt - -class FunctionalErrorHandlingWithEither { - - sealed class ComputeProblem { - object OddNumber : ComputeProblem() - object NotANumber : ComputeProblem() - } - - fun parseInput(s : String) : Either = Either.cond(s.toIntOrNull() != null, {-> s.toInt()}, {->ComputeProblem.NotANumber} ) - - fun isEven(x : Int) : Boolean = x % 2 == 0 - - fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) - - fun biggestDivisor(x : Int, y : Int) : Int { - if(x == y){ - return 1; - } - if(x % y == 0){ - return x / y; - } - return biggestDivisor(x, y+1) - } - - fun isSquareNumber(x : Int) : Boolean { - val sqrt: Double = sqrt(x.toDouble()) - return sqrt % 1.0 == 0.0 - } - - fun computeWithEither(input : String) : Either { - return parseInput(input) - .filterOrElse(::isEven) {->ComputeProblem.OddNumber} - .map (::biggestDivisor) - .map (::isSquareNumber) - } - - fun computeWithEitherClient(input : String) { - val computeWithEither = computeWithEither(input) - - when(computeWithEither){ - is Either.Right -> "The greatest divisor is square number: ${computeWithEither.b}" - is Either.Left -> when(computeWithEither.a){ - is ComputeProblem.NotANumber -> "Wrong input! Not a number!" - is ComputeProblem.OddNumber -> "It is an odd number!" - } - } - } - -} \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt deleted file mode 100644 index 5fddd1d88e..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.kotlin.arrow - -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import kotlin.math.sqrt - -class FunctionalErrorHandlingWithOption { - - fun parseInput(s : String) : Option = Option.fromNullable(s.toIntOrNull()) - - fun isEven(x : Int) : Boolean = x % 2 == 0 - - fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) - - fun biggestDivisor(x : Int, y : Int) : Int { - if(x == y){ - return 1; - } - if(x % y == 0){ - return x / y; - } - return biggestDivisor(x, y+1) - } - - fun isSquareNumber(x : Int) : Boolean { - val sqrt: Double = sqrt(x.toDouble()) - return sqrt % 1.0 == 0.0 - } - - fun computeWithOption(input : String) : Option { - return parseInput(input) - .filter(::isEven) - .map(::biggestDivisor) - .map(::isSquareNumber) - } - - fun computeWithOptionClient(input : String) : String{ - val computeOption = computeWithOption(input) - - return when(computeOption){ - is None -> "Not an even number!" - is Some -> "The greatest divisor is square number: ${computeOption.t}" - } - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt deleted file mode 100644 index 721bdb04bc..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.kodein - -class Controller(private val service : Service) \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt deleted file mode 100644 index a0be7ef0e0..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.kodein - -interface Dao \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt deleted file mode 100644 index 0a09b95dbf..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.kodein - -class JdbcDao : Dao \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt deleted file mode 100644 index 06436fcd21..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.kodein - -class MongoDao : Dao \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt deleted file mode 100644 index bb24a5cc21..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.kodein - -class Service(private val dao: Dao, private val tag: String) \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt deleted file mode 100644 index 993ee555af..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.kotlin - -interface BookService { - fun inStock(bookId: Int): Boolean - fun lend(bookId: Int, memberId: Int) -} \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt deleted file mode 100644 index 5a4718162a..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.kotlin - -class LendBookManager(val bookService:BookService) { - fun checkout(bookId: Int, memberId: Int) { - if(bookService.inStock(bookId)) { - bookService.lend(bookId, memberId) - } else { - throw IllegalStateException("Book is not available") - } - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/AnnotatedServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/AnnotatedServer.kt deleted file mode 100644 index da2bbe4208..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/AnnotatedServer.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.kovert - -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.core.HttpVerb -import uy.kohesive.kovert.core.Location -import uy.kohesive.kovert.core.Verb -import uy.kohesive.kovert.core.VerbAlias -import uy.kohesive.kovert.vertx.bindController -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - - -class AnnotatedServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(AnnotatedServer::class.java) - - @JvmStatic - fun main(args: Array) { - AnnotatedServer().start() - } - } - - @VerbAlias("show", HttpVerb.GET) - class AnnotatedController { - fun RoutingContext.showStringById(id: String) = id - - @Verb(HttpVerb.GET) - @Location("/ping/:id") - fun RoutingContext.ping(id: String) = id - } - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", AnnotatedServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - bindController(AnnotatedController(), "api") - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/ErrorServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/ErrorServer.kt deleted file mode 100644 index a596391ed8..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/ErrorServer.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.kovert - -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.core.HttpErrorCode -import uy.kohesive.kovert.core.HttpErrorCodeWithBody -import uy.kohesive.kovert.core.HttpErrorForbidden -import uy.kohesive.kovert.vertx.bindController -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - - -class ErrorServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(ErrorServer::class.java) - - @JvmStatic - fun main(args: Array) { - ErrorServer().start() - } - } - - class ErrorController { - fun RoutingContext.getForbidden() { - throw HttpErrorForbidden() - } - fun RoutingContext.getError() { - throw HttpErrorCode("Something went wrong", 590) - } - fun RoutingContext.getErrorbody() { - throw HttpErrorCodeWithBody("Something went wrong", 591, "Body here") - } - } - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", ErrorServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - bindController(ErrorController(), "api") - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/JsonServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/JsonServer.kt deleted file mode 100644 index 310fe2a7a0..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/JsonServer.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.kovert - -import com.fasterxml.jackson.annotation.JsonProperty -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.vertx.bindController -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - -class JsonServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(JsonServer::class.java) - - @JvmStatic - fun main(args: Array) { - JsonServer().start() - } - } - - data class Person( - @JsonProperty("_id") - val id: String, - val name: String, - val job: String - ) - - class JsonController { - fun RoutingContext.getPersonById(id: String) = Person( - id = id, - name = "Tony Stark", - job = "Iron Man" - ) - fun RoutingContext.putPersonById(id: String, person: Person) = person - } - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", JsonServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - bindController(JsonController(), "api") - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/NoopServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/NoopServer.kt deleted file mode 100644 index 98ce775e66..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/NoopServer.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.kovert - -import io.vertx.ext.web.Router -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - -class NoopServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(NoopServer::class.java) - - @JvmStatic - fun main(args: Array) { - NoopServer().start() - } - } - - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", NoopServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SecuredServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SecuredServer.kt deleted file mode 100644 index 86ca482808..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SecuredServer.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.kovert - -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.vertx.bindController -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - - -class SecuredServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(SecuredServer::class.java) - - @JvmStatic - fun main(args: Array) { - SecuredServer().start() - } - } - - class SecuredContext(private val routingContext: RoutingContext) { - val authenticated = routingContext.request().getHeader("Authorization") == "Secure" - } - - class SecuredController { - fun SecuredContext.getSecured() = this.authenticated - } - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", SecuredServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - bindController(SecuredController(), "api") - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SimpleServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SimpleServer.kt deleted file mode 100644 index 172469ab46..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/kovert/SimpleServer.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.baeldung.kovert - -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import nl.komponents.kovenant.functional.bind -import org.kodein.di.Kodein -import org.kodein.di.conf.global -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import uy.klutter.config.typesafe.ClassResourceConfig -import uy.klutter.config.typesafe.ReferenceConfig -import uy.klutter.config.typesafe.kodein.importConfig -import uy.klutter.config.typesafe.loadConfig -import uy.klutter.vertx.kodein.KodeinVertx -import uy.kohesive.kovert.vertx.bindController -import uy.kohesive.kovert.vertx.boot.KodeinKovertVertx -import uy.kohesive.kovert.vertx.boot.KovertVerticle -import uy.kohesive.kovert.vertx.boot.KovertVerticleModule -import uy.kohesive.kovert.vertx.boot.KovertVertx - - -class SimpleServer { - companion object { - private val LOG: Logger = LoggerFactory.getLogger(SimpleServer::class.java) - - @JvmStatic - fun main(args: Array) { - SimpleServer().start() - } - } - - class SimpleController { - fun RoutingContext.getStringById(id: String) = id - fun RoutingContext.get_truncatedString_by_id(id: String, length: Int = 1) = id.subSequence(0, length) - } - - fun start() { - Kodein.global.addImport(Kodein.Module { - importConfig(loadConfig(ClassResourceConfig("/kovert.conf", SimpleServer::class.java), ReferenceConfig())) { - import("kovert.vertx", KodeinKovertVertx.configModule) - import("kovert.server", KovertVerticleModule.configModule) - } - - // includes jackson ObjectMapper to match compatibility with Vertx, app logging via Vertx facade to Slf4j - import(KodeinVertx.moduleWithLoggingToSlf4j) - // Kovert boot - import(KodeinKovertVertx.module) - import(KovertVerticleModule.module) - }) - - val initControllers = fun Router.() { - bindController(SimpleController(), "api") - } - - // startup asynchronously... - KovertVertx.start() bind { vertx -> - KovertVerticle.deploy(vertx, routerInit = initControllers) - } success { deploymentId -> - LOG.warn("Deployment complete.") - } fail { error -> - LOG.error("Deployment failed!", error) - } - - } -} diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt deleted file mode 100755 index a12182ccc8..0000000000 --- a/kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt +++ /dev/null @@ -1,73 +0,0 @@ -@file:JvmName("APIServer") - - -import io.ktor.application.call -import io.ktor.application.install -import io.ktor.features.CallLogging -import io.ktor.features.ContentNegotiation -import io.ktor.features.DefaultHeaders -import io.ktor.gson.gson -import io.ktor.request.path -import io.ktor.request.receive -import io.ktor.response.respond -import io.ktor.routing.* -import io.ktor.server.engine.embeddedServer -import io.ktor.server.netty.Netty -import org.slf4j.event.Level - -data class Author(val name: String, val website: String) -data class ToDo(var id: Int, val name: String, val description: String, val completed: Boolean) - -fun main(args: Array) { - - val toDoList = ArrayList(); - val jsonResponse = """{ - "id": 1, - "task": "Pay waterbill", - "description": "Pay water bill today", - }""" - - - embeddedServer(Netty, 8080) { - install(DefaultHeaders) { - header("X-Developer", "Baeldung") - } - install(CallLogging) { - level = Level.DEBUG - filter { call -> call.request.path().startsWith("/todo") } - filter { call -> call.request.path().startsWith("/author") } - } - install(ContentNegotiation) { - gson { - setPrettyPrinting() - } - } - routing() { - route("/todo") { - post { - var toDo = call.receive(); - toDo.id = toDoList.size; - toDoList.add(toDo); - call.respond("Added") - - } - delete("/{id}") { - call.respond(toDoList.removeAt(call.parameters["id"]!!.toInt())); - } - get("/{id}") { - - call.respond(toDoList[call.parameters["id"]!!.toInt()]); - } - get { - call.respond(toDoList); - } - } - get("/author"){ - call.respond(Author("Baeldung","baeldung.com")); - - } - - - } - }.start(wait = true) -} \ No newline at end of file diff --git a/kotlin-libraries/src/main/resources/kovert.conf b/kotlin-libraries/src/main/resources/kovert.conf deleted file mode 100644 index 3b08641693..0000000000 --- a/kotlin-libraries/src/main/resources/kovert.conf +++ /dev/null @@ -1,15 +0,0 @@ -{ - kovert: { - vertx: { - clustered: false - } - server: { - listeners: [ - { - host: "0.0.0.0" - port: "8000" - } - ] - } - } -} diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt deleted file mode 100644 index 2a7d44a163..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt +++ /dev/null @@ -1,163 +0,0 @@ -package com.baeldung.klaxon - -import com.beust.klaxon.JsonArray -import com.beust.klaxon.JsonObject -import com.beust.klaxon.JsonReader -import com.beust.klaxon.Klaxon -import com.beust.klaxon.Parser -import com.beust.klaxon.PathMatcher -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.api.SoftAssertions.assertSoftly -import org.junit.Assert -import org.junit.jupiter.api.Test -import java.io.StringReader -import java.util.regex.Pattern - -class KlaxonUnitTest { - - @Test - fun giveProduct_whenSerialize_thenGetJsonString() { - val product = Product("HDD") - val result = Klaxon().toJsonString(product) - - assertThat(result).isEqualTo("""{"name" : "HDD"}""") - } - - @Test - fun giveJsonString_whenDeserialize_thenGetProduct() { - val result = Klaxon().parse(""" - { - "name" : "RAM" - } - """) - - assertThat(result?.name).isEqualTo("RAM") - } - - @Test - fun giveCustomProduct_whenSerialize_thenGetJsonString() { - val product = CustomProduct("HDD", 1) - val result = Klaxon().toJsonString(product) - - assertThat(result).isEqualTo("""{"productName" : "HDD"}""") - } - - @Test - fun giveJsonArray_whenStreaming_thenGetProductArray() { - val jsonArray = """ - [ - { "name" : "HDD", "capacityInGb" : 512 }, - { "name" : "RAM", "capacityInGb" : 16 } - ]""" - val expectedArray = arrayListOf(ProductData("HDD", 512), - ProductData("RAM", 16)) - val klaxon = Klaxon() - val productArray = arrayListOf() - JsonReader(StringReader(jsonArray)).use { reader -> - reader.beginArray { - while (reader.hasNext()) { - val product = klaxon.parse(reader) - productArray.add(product!!) - } - } - } - - assertThat(productArray).hasSize(2).isEqualTo(expectedArray) - } - - @Test - fun giveJsonString_whenParser_thenGetJsonObject() { - val jsonString = StringBuilder(""" - { - "name" : "HDD", - "capacityInGb" : 512, - "sizeInInch" : 2.5 - } - """) - val parser = Parser() - val json = parser.parse(jsonString) as JsonObject - - assertThat(json).hasSize(3).containsEntry("name", "HDD").containsEntry("capacityInGb", 512).containsEntry("sizeInInch", 2.5) - } - - @Suppress("UNCHECKED_CAST") - @Test - fun giveJsonStringArray_whenParser_thenGetJsonArray() { - val jsonString = StringBuilder(""" - [ - { "name" : "SDD" }, - { "madeIn" : "Taiwan" }, - { "warrantyInYears" : 5 } - ]""") - val parser = Parser() - val json = parser.parse(jsonString) as JsonArray - - assertSoftly({ softly -> - softly.assertThat(json).hasSize(3) - softly.assertThat(json[0]["name"]).isEqualTo("SDD") - softly.assertThat(json[1]["madeIn"]).isEqualTo("Taiwan") - softly.assertThat(json[2]["warrantyInYears"]).isEqualTo(5) - }) - } - - @Test - fun givenJsonString_whenStreaming_thenProcess() { - val jsonString = """ - { - "name" : "HDD", - "madeIn" : "Taiwan", - "warrantyInYears" : 5 - "hasStock" : true - "capacitiesInTb" : [ 1, 2 ], - "features" : { "cacheInMb" : 64, "speedInRpm" : 7200 } - }""" - - JsonReader(StringReader(jsonString)).use { reader -> - reader.beginObject { - while (reader.hasNext()) { - val readName = reader.nextName() - when (readName) { - "name" -> assertThat(reader.nextString()).isEqualTo("HDD") - "madeIn" -> assertThat(reader.nextString()).isEqualTo("Taiwan") - "warrantyInYears" -> assertThat(reader.nextInt()).isEqualTo(5) - "hasStock" -> assertThat(reader.nextBoolean()).isEqualTo(true) - "capacitiesInTb" -> assertThat(reader.nextArray()).contains(1, 2) - "features" -> assertThat(reader.nextObject()).containsEntry("cacheInMb", 64).containsEntry("speedInRpm", 7200) - else -> Assert.fail("Unexpected name: $readName") - } - } - } - } - - } - - @Test - fun givenDiskInventory_whenRegexMatches_thenGetTypes() { - val jsonString = """ - { - "inventory" : { - "disks" : [ - { - "type" : "HDD", - "sizeInGb" : 1000 - }, - { - "type" : "SDD", - "sizeInGb" : 512 - } - ] - } - }""" - val pathMatcher = object : PathMatcher { - override fun pathMatches(path: String) = Pattern.matches(".*inventory.*disks.*type.*", path) - - override fun onMatch(path: String, value: Any) { - when (path) { - "$.inventory.disks[0].type" -> assertThat(value).isEqualTo("HDD") - "$.inventory.disks[1].type" -> assertThat(value).isEqualTo("SDD") - } - } - } - Klaxon().pathMatcher(pathMatcher).parseJsonObject(StringReader(jsonString)) - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt deleted file mode 100644 index 692425ee07..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.baeldung.kotlin.arrow - -import arrow.core.* -import org.junit.Assert -import org.junit.Test - -class FunctionalDataTypes { - - @Test - fun whenIdCreated_thanValueIsPresent(){ - val id = Id("foo") - val justId = Id.just("foo"); - - Assert.assertEquals("foo", id.extract()) - Assert.assertEquals(justId, id) - } - - fun length(s : String) : Int = s.length - - fun isBigEnough(i : Int) : Boolean = i > 10 - - @Test - fun whenIdCreated_thanMapIsAssociative(){ - val foo = Id("foo") - - val map1 = foo.map(::length) - .map(::isBigEnough) - val map2 = foo.map { s -> isBigEnough(length(s)) } - - Assert.assertEquals(map1, map2) - } - - fun lengthId(s : String) : Id = Id.just(length(s)) - - fun isBigEnoughId(i : Int) : Id = Id.just(isBigEnough(i)) - - @Test - fun whenIdCreated_thanFlatMapIsAssociative(){ - val bar = Id("bar") - - val flatMap = bar.flatMap(::lengthId) - .flatMap(::isBigEnoughId) - val flatMap1 = bar.flatMap { s -> lengthId(s).flatMap(::isBigEnoughId) } - - Assert.assertEquals(flatMap, flatMap1) - } - - @Test - fun whenOptionCreated_thanValueIsPresent(){ - val factory = Option.just(42) - val constructor = Option(42) - val emptyOptional = Option.empty() - val fromNullable = Option.fromNullable(null) - - Assert.assertEquals(42, factory.getOrElse { -1 }) - Assert.assertEquals(factory, constructor) - Assert.assertEquals(emptyOptional, fromNullable) - } - - @Test - fun whenOptionCreated_thanConstructorDifferFromFactory(){ - val constructor : Option = Option(null) - val fromNullable : Option = Option.fromNullable(null) - - try{ - constructor.map { s -> s!!.length } - Assert.fail() - } catch (e : KotlinNullPointerException){ - fromNullable.map { s->s!!.length } - } - Assert.assertNotEquals(constructor, fromNullable) - } - - fun wrapper(x : Integer?) : Option = if (x == null) Option.just(-1) else Option.just(x.toInt()) - - @Test - fun whenOptionFromNullableCreated_thanItBreaksLeftIdentity(){ - val optionFromNull = Option.fromNullable(null) - - Assert.assertNotEquals(optionFromNull.flatMap(::wrapper), wrapper(null)) - } - - @Test - fun whenEitherCreated_thanOneValueIsPresent(){ - val rightOnly : Either = Either.right(42) - val leftOnly : Either = Either.left("foo") - - Assert.assertTrue(rightOnly.isRight()) - Assert.assertTrue(leftOnly.isLeft()) - Assert.assertEquals(42, rightOnly.getOrElse { -1 }) - Assert.assertEquals(-1, leftOnly.getOrElse { -1 }) - - Assert.assertEquals(0, rightOnly.map { it % 2 }.getOrElse { -1 }) - Assert.assertEquals(-1, leftOnly.map { it % 2 }.getOrElse { -1 }) - Assert.assertTrue(rightOnly.flatMap { Either.Right(it % 2) }.isRight()) - Assert.assertTrue(leftOnly.flatMap { Either.Right(it % 2) }.isLeft()) - } - - @Test - fun whenEvalNowUsed_thenMapEvaluatedLazily(){ - val now = Eval.now(1) - Assert.assertEquals(1, now.value()) - - var counter : Int = 0 - val map = now.map { x -> counter++; x+1 } - Assert.assertEquals(0, counter) - - val value = map.value() - Assert.assertEquals(2, value) - Assert.assertEquals(1, counter) - } - - @Test - fun whenEvalLaterUsed_theResultIsMemoized(){ - var counter : Int = 0 - val later = Eval.later { counter++; counter } - Assert.assertEquals(0, counter) - - val firstValue = later.value() - Assert.assertEquals(1, firstValue) - Assert.assertEquals(1, counter) - - val secondValue = later.value() - Assert.assertEquals(1, secondValue) - Assert.assertEquals(1, counter) - } - - @Test - fun whenEvalAlwaysUsed_theResultIsNotMemoized(){ - var counter : Int = 0 - val later = Eval.always { counter++; counter } - Assert.assertEquals(0, counter) - - val firstValue = later.value() - Assert.assertEquals(1, firstValue) - Assert.assertEquals(1, counter) - - val secondValue = later.value() - Assert.assertEquals(2, secondValue) - Assert.assertEquals(2, counter) - } - -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt deleted file mode 100644 index 47fbf825a0..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.kotlin.arrow - -import arrow.core.Either -import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.NotANumber -import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.OddNumber -import org.junit.Assert -import org.junit.Test - -class FunctionalErrorHandlingWithEitherTest { - - val operator = FunctionalErrorHandlingWithEither() - - @Test - fun givenInvalidInput_whenComputeInvoked_NotANumberIsPresent(){ - val computeWithEither = operator.computeWithEither("bar") - - Assert.assertTrue(computeWithEither.isLeft()) - when(computeWithEither){ - is Either.Left -> when(computeWithEither.a){ - NotANumber -> "Ok." - else -> Assert.fail() - } - else -> Assert.fail() - } - } - - @Test - fun givenOddNumberInput_whenComputeInvoked_OddNumberIsPresent(){ - val computeWithEither = operator.computeWithEither("121") - - Assert.assertTrue(computeWithEither.isLeft()) - when(computeWithEither){ - is Either.Left -> when(computeWithEither.a){ - OddNumber -> "Ok." - else -> Assert.fail() - } - else -> Assert.fail() - } - } - - @Test - fun givenEvenNumberWithoutSquare_whenComputeInvoked_OddNumberIsPresent(){ - val computeWithEither = operator.computeWithEither("100") - - Assert.assertTrue(computeWithEither.isRight()) - when(computeWithEither){ - is Either.Right -> when(computeWithEither.b){ - false -> "Ok." - else -> Assert.fail() - } - else -> Assert.fail() - } - } - - @Test - fun givenEvenNumberWithSquare_whenComputeInvoked_OddNumberIsPresent(){ - val computeWithEither = operator.computeWithEither("98") - - Assert.assertTrue(computeWithEither.isRight()) - when(computeWithEither){ - is Either.Right -> when(computeWithEither.b){ - true -> "Ok." - else -> Assert.fail() - } - else -> Assert.fail() - } - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt deleted file mode 100644 index 3ca4cd033f..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.kotlin.arrow - -import org.junit.Assert -import org.junit.Test - -class FunctionalErrorHandlingWithOptionTest { - - val operator = FunctionalErrorHandlingWithOption() - - @Test - fun givenInvalidInput_thenErrorMessageIsPresent(){ - val useComputeOption = operator.computeWithOptionClient("foo") - Assert.assertEquals("Not an even number!", useComputeOption) - } - - @Test - fun givenOddNumberInput_thenErrorMessageIsPresent(){ - val useComputeOption = operator.computeWithOptionClient("539") - Assert.assertEquals("Not an even number!",useComputeOption) - } - - @Test - fun givenEvenNumberInputWithNonSquareNum_thenFalseMessageIsPresent(){ - val useComputeOption = operator.computeWithOptionClient("100") - Assert.assertEquals("The greatest divisor is square number: false",useComputeOption) - } - - @Test - fun givenEvenNumberInputWithSquareNum_thenTrueMessageIsPresent(){ - val useComputeOption = operator.computeWithOptionClient("242") - Assert.assertEquals("The greatest divisor is square number: true",useComputeOption) - } - -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt deleted file mode 100644 index 29fa18ef7a..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt +++ /dev/null @@ -1,333 +0,0 @@ -package com.baeldung.kotlin.exposed - -import org.jetbrains.exposed.dao.* -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.TransactionManager -import org.jetbrains.exposed.sql.transactions.transaction -import org.junit.Test -import java.sql.DriverManager -import kotlin.test.* - -class ExposedTest { - - @Test - fun whenH2Database_thenConnectionSuccessful() { - val database = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction { - assertEquals(1.4.toBigDecimal(), database.version) - assertEquals("h2", database.vendor) - } - } - - @Test - fun whenH2DatabaseWithCredentials_thenConnectionSuccessful() { - Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver", user = "myself", password = "secret") - } - - @Test - fun whenH2DatabaseWithManualConnection_thenConnectionSuccessful() { - var connected = false - Database.connect({ connected = true; DriverManager.getConnection("jdbc:h2:mem:test;MODE=MySQL") }) - assertEquals(false, connected) - transaction { - addLogger(StdOutSqlLogger) - assertEquals(false, connected) - SchemaUtils.create(Cities) - assertEquals(true, connected) - } - } - - @Test - fun whenManualCommit_thenOk() { - Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction { - assertTrue(this is Transaction) - commit() - commit() - commit() - } - } - - @Test - fun whenInsert_thenGeneratedKeys() { - Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction { - SchemaUtils.create(StarWarsFilms) - val id = StarWarsFilms.insertAndGetId { - it[name] = "The Last Jedi" - it[sequelId] = 8 - it[director] = "Rian Johnson" - } - assertEquals(1, id.value) - val insert = StarWarsFilms.insert { - it[name] = "The Force Awakens" - it[sequelId] = 7 - it[director] = "J.J. Abrams" - } - assertEquals(2, insert[StarWarsFilms.id]?.value) - val selectAll = StarWarsFilms.selectAll() - selectAll.forEach { - assertTrue { it[StarWarsFilms.sequelId] >= 7 } - } - StarWarsFilms.slice(StarWarsFilms.name, StarWarsFilms.director).selectAll() - .forEach { - assertTrue { it[StarWarsFilms.name].startsWith("The") } - } - val select = StarWarsFilms.select { (StarWarsFilms.director like "J.J.%") and (StarWarsFilms.sequelId eq 7) } - assertEquals(1, select.count()) - StarWarsFilms.update ({ StarWarsFilms.sequelId eq 8 }) { - it[name] = "Episode VIII – The Last Jedi" - with(SqlExpressionBuilder) { - it.update(StarWarsFilms.sequelId, StarWarsFilms.sequelId + 1) - } - } - } - } - - @Test - fun whenForeignKey_thenAutoJoin() { - Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction { - addLogger(StdOutSqlLogger) - SchemaUtils.create(StarWarsFilms, Players) - StarWarsFilms.insert { - it[name] = "The Last Jedi" - it[sequelId] = 8 - it[director] = "Rian Johnson" - } - StarWarsFilms.insert { - it[name] = "The Force Awakens" - it[sequelId] = 7 - it[director] = "J.J. Abrams" - } - Players.insert { - it[name] = "Mark Hamill" - it[sequelId] = 7 - } - Players.insert { - it[name] = "Mark Hamill" - it[sequelId] = 8 - } - val simpleInnerJoin = (StarWarsFilms innerJoin Players).selectAll() - assertEquals(2, simpleInnerJoin.count()) - simpleInnerJoin.forEach { - assertNotNull(it[StarWarsFilms.name]) - assertEquals(it[StarWarsFilms.sequelId], it[Players.sequelId]) - assertEquals("Mark Hamill", it[Players.name]) - } - val innerJoinWithCondition = (StarWarsFilms innerJoin Players) - .select { StarWarsFilms.sequelId eq Players.sequelId } - assertEquals(2, innerJoinWithCondition.count()) - innerJoinWithCondition.forEach { - assertNotNull(it[StarWarsFilms.name]) - assertEquals(it[StarWarsFilms.sequelId], it[Players.sequelId]) - assertEquals("Mark Hamill", it[Players.name]) - } - val complexInnerJoin = Join(StarWarsFilms, Players, joinType = JoinType.INNER, onColumn = StarWarsFilms.sequelId, otherColumn = Players.sequelId, additionalConstraint = { - StarWarsFilms.sequelId eq 8 - }).selectAll() - assertEquals(1, complexInnerJoin.count()) - complexInnerJoin.forEach { - assertNotNull(it[StarWarsFilms.name]) - assertEquals(it[StarWarsFilms.sequelId], it[Players.sequelId]) - assertEquals("Mark Hamill", it[Players.name]) - } - - } - } - - @Test - fun whenJoinWithAlias_thenFun() { - Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction { - addLogger(StdOutSqlLogger) - SchemaUtils.create(StarWarsFilms, Players) - StarWarsFilms.insert { - it[name] = "The Last Jedi" - it[sequelId] = 8 - it[director] = "Rian Johnson" - } - StarWarsFilms.insert { - it[name] = "The Force Awakens" - it[sequelId] = 7 - it[director] = "J.J. Abrams" - } - val sequel = StarWarsFilms.alias("sequel") - Join(StarWarsFilms, sequel, - additionalConstraint = { sequel[StarWarsFilms.sequelId] eq StarWarsFilms.sequelId + 1 }) - .selectAll().forEach { - assertEquals(it[sequel[StarWarsFilms.sequelId]], it[StarWarsFilms.sequelId] + 1) - } - } - } - - @Test - fun whenEntity_thenDAO() { - val database = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - val connection = database.connector.invoke() //Keep a connection open so the DB is not destroyed after the first transaction - val inserted = transaction { - addLogger(StdOutSqlLogger) - SchemaUtils.create(StarWarsFilms, Players) - val theLastJedi = StarWarsFilm.new { - name = "The Last Jedi" - sequelId = 8 - director = "Rian Johnson" - } - assertFalse(TransactionManager.current().entityCache.inserts.isEmpty()) - assertEquals(1, theLastJedi.id.value) //Reading this causes a flush - assertTrue(TransactionManager.current().entityCache.inserts.isEmpty()) - theLastJedi - } - transaction { - val theLastJedi = StarWarsFilm.findById(1) - assertNotNull(theLastJedi) - assertEquals(inserted.id, theLastJedi?.id) - } - connection.close() - } - - @Test - fun whenManyToOne_thenNavigation() { - val database = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - val connection = database.connector.invoke() - transaction { - addLogger(StdOutSqlLogger) - SchemaUtils.create(StarWarsFilms, Players, Users, UserRatings) - val theLastJedi = StarWarsFilm.new { - name = "The Last Jedi" - sequelId = 8 - director = "Rian Johnson" - } - val someUser = User.new { - name = "Some User" - } - val rating = UserRating.new { - value = 9 - user = someUser - film = theLastJedi - } - assertEquals(theLastJedi, rating.film) - assertEquals(someUser, rating.user) - assertEquals(rating, theLastJedi.ratings.first()) - } - transaction { - val theLastJedi = StarWarsFilm.find { StarWarsFilms.sequelId eq 8 }.first() - val ratings = UserRating.find { UserRatings.film eq theLastJedi.id } - assertEquals(1, ratings.count()) - val rating = ratings.first() - assertEquals("Some User", rating.user.name) - assertEquals(rating, theLastJedi.ratings.first()) - UserRating.new { - value = 8 - user = rating.user - film = theLastJedi - } - assertEquals(2, theLastJedi.ratings.count()) - } - connection.close() - } - - @Test - fun whenManyToMany_thenAssociation() { - val database = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - val connection = database.connector.invoke() - val film = transaction { - SchemaUtils.create(StarWarsFilms) - StarWarsFilm.new { - name = "The Last Jedi" - sequelId = 8 - director = "Rian Johnson" - } - } - - val actor = transaction { - SchemaUtils.create(Actors) - Actor.new { - firstname = "Daisy" - lastname = "Ridley" - } - } - - transaction { - SchemaUtils.create(StarWarsFilmActors) - film.actors = SizedCollection(listOf(actor)) - } - connection.close() - } - -} - -object Cities: IntIdTable() { - val name = varchar("name", 50) -} - -object StarWarsFilms_Simple : Table() { - val id = integer("id").autoIncrement().primaryKey() - val sequelId = integer("sequel_id").uniqueIndex() - val name = varchar("name", 50) - val director = varchar("director", 50) -} - -object StarWarsFilms : IntIdTable() { - val sequelId = integer("sequel_id").uniqueIndex() - val name = varchar("name", 50) - val director = varchar("director", 50) -} - -object Players : Table() { - //val sequelId = integer("sequel_id").uniqueIndex().references(StarWarsFilms.sequelId) - val sequelId = reference("sequel_id", StarWarsFilms.sequelId).uniqueIndex() - //val filmId = reference("film_id", StarWarsFilms).nullable() - val name = varchar("name", 50) -} - -class StarWarsFilm(id: EntityID) : Entity(id) { - companion object : EntityClass(StarWarsFilms) - - var sequelId by StarWarsFilms.sequelId - var name by StarWarsFilms.name - var director by StarWarsFilms.director - var actors by Actor via StarWarsFilmActors - val ratings by UserRating referrersOn UserRatings.film -} - -object Users: IntIdTable() { - val name = varchar("name", 50) -} - -object UserRatings: IntIdTable() { - val value = long("value") - val film = reference("film", StarWarsFilms) - val user = reference("user", Users) -} - -class User(id: EntityID): IntEntity(id) { - companion object : IntEntityClass(Users) - - var name by Users.name -} - -class UserRating(id: EntityID): IntEntity(id) { - companion object : IntEntityClass(UserRatings) - - var value by UserRatings.value - var film by StarWarsFilm referencedOn UserRatings.film - var user by User referencedOn UserRatings.user -} - -object Actors: IntIdTable() { - val firstname = varchar("firstname", 50) - val lastname = varchar("lastname", 50) -} - -class Actor(id: EntityID): IntEntity(id) { - companion object : IntEntityClass(Actors) - - var firstname by Actors.firstname - var lastname by Actors.lastname -} - -object StarWarsFilmActors : Table() { - val starWarsFilm = reference("starWarsFilm", StarWarsFilms).primaryKey(0) - val actor = reference("actor", Actors).primaryKey(1) -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt deleted file mode 100644 index 1b61c05887..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.kotlin.junit5 - -class Calculator { - fun add(a: Int, b: Int) = a + b - - fun divide(a: Int, b: Int) = if (b == 0) { - throw DivideByZeroException(a) - } else { - a / b - } - - fun square(a: Int) = a * a - - fun squareRoot(a: Int) = Math.sqrt(a.toDouble()) - - fun log(base: Int, value: Int) = Math.log(value.toDouble()) / Math.log(base.toDouble()) -} diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt deleted file mode 100644 index 60bc4e2944..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.kotlin.junit5 - -class DivideByZeroException(val numerator: Int) : Exception() diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt deleted file mode 100644 index 4deb576b9f..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt +++ /dev/null @@ -1,153 +0,0 @@ -package com.baeldung.kotlin.khttp - -import khttp.structures.files.FileLike -import org.json.JSONObject -import org.junit.Test -import java.beans.ExceptionListener -import java.beans.XMLEncoder -import java.io.* -import java.lang.Exception -import java.net.ConnectException -import kotlin.test.assertEquals -import kotlin.test.assertTrue -import kotlin.test.fail - -class KhttpLiveTest { - - @Test - fun whenHttpGetRequestIsMade_thenArgsAreReturned() { - val response = khttp.get( - url = "http://httpbin.org/get", - params = mapOf("p1" to "1", "p2" to "2")) - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - } - - @Test - fun whenAlternateHttpGetRequestIsMade_thenArgsAreReturned() { - val response = khttp.request( - method = "GET", - url = "http://httpbin.org/get", - params = mapOf("p1" to "1", "p2" to "2")) - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - } - - @Test - fun whenHeadersAreSet_thenHeadersAreSent() { - val response = khttp.get( - url = "http://httpbin.org/get", - headers = mapOf("header1" to "1", "header2" to "2")) - val headers = response.jsonObject.getJSONObject("headers") - - assertEquals("1", headers["Header1"]) - assertEquals("2", headers["Header2"]) - } - - @Test - fun whenHttpPostRequestIsMadeWithJson_thenBodyIsReturned() { - val response = khttp.post( - url = "http://httpbin.org/post", - params = mapOf("p1" to "1", "p2" to "2"), - json = mapOf("pr1" to "1", "pr2" to "2")) - - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - - val json = response.jsonObject.getJSONObject("json") - - assertEquals("1", json["pr1"]) - assertEquals("2", json["pr2"]) - } - - @Test - fun whenHttpPostRequestIsMadeWithMapData_thenBodyIsReturned() { - val response = khttp.post( - url = "http://httpbin.org/post", - params = mapOf("p1" to "1", "p2" to "2"), - data = mapOf("pr1" to "1", "pr2" to "2")) - - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - - val form = response.jsonObject.getJSONObject("form") - - assertEquals("1", form["pr1"]) - assertEquals("2", form["pr2"]) - } - - @Test - fun whenHttpPostRequestIsMadeWithFiles_thenBodyIsReturned() { - val response = khttp.post( - url = "http://httpbin.org/post", - params = mapOf("p1" to "1", "p2" to "2"), - files = listOf( - FileLike("file1", "content1"), - FileLike("file2", javaClass.getResource("KhttpTest.class").openStream().readBytes()))) - - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - - val files = response.jsonObject.getJSONObject("files") - - assertEquals("content1", files["file1"]) - } - - @Test - fun whenHttpPostRequestIsMadeWithInputStream_thenBodyIsReturned() { - val response = khttp.post( - url = "http://httpbin.org/post", - params = mapOf("p1" to "1", "p2" to "2"), - data = ByteArrayInputStream("content!".toByteArray())) - - val args = response.jsonObject.getJSONObject("args") - - assertEquals("1", args["p1"]) - assertEquals("2", args["p2"]) - - assertEquals("content!", response.jsonObject["data"]) - } - - @Test - fun whenHttpPostStreamingRequestIsMade_thenBodyIsReturnedInChunks() { - val response = khttp.post( - url = "http://httpbin.org/post", - stream = true, - json = mapOf("pr1" to "1", "pr2" to "2")) - - val baos = ByteArrayOutputStream() - response.contentIterator(chunkSize = 10).forEach { arr : ByteArray -> baos.write(arr) } - val json = JSONObject(String(baos.toByteArray())).getJSONObject("json") - - assertEquals("1", json["pr1"]) - assertEquals("2", json["pr2"]) - } - - @Test - fun whenHttpRequestFails_thenExceptionIsThrown() { - try { - khttp.get(url = "http://localhost/nothing/to/see/here") - - fail("Should have thrown an exception") - } catch (e : ConnectException) { - //Ok - } - } - - @Test - fun whenHttpNotFound_thenExceptionIsThrown() { - val response = khttp.get(url = "http://httpbin.org/nothing/to/see/here") - - assertEquals(404, response.statusCode) - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt deleted file mode 100644 index 7776eebd52..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt +++ /dev/null @@ -1,191 +0,0 @@ -package com.baeldung.kotlin.kodein - -import com.github.salomonbrys.kodein.* -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test - -class KodeinUnitTest { - - class InMemoryDao : Dao - - @Test - fun whenSingletonBinding_thenSingleInstanceIsCreated() { - var created = false - val kodein = Kodein { - bind() with singleton { - created = true - MongoDao() - } - } - - assertThat(created).isFalse() - - val dao1: Dao = kodein.instance() - - assertThat(created).isTrue() - - val dao2: Dao = kodein.instance() - - assertThat(dao1).isSameAs(dao2) - } - - @Test - fun whenFactoryBinding_thenNewInstanceIsCreated() { - val kodein = Kodein { - bind() with singleton { MongoDao() } - bind() with factory { tag: String -> Service(instance(), tag) } - } - val service1: Service = kodein.with("myTag").instance() - val service2: Service = kodein.with("myTag").instance() - - assertThat(service1).isNotSameAs(service2) - } - - @Test - fun whenProviderBinding_thenNewInstanceIsCreated() { - val kodein = Kodein { - bind() with provider { MongoDao() } - } - val dao1: Dao = kodein.instance() - val dao2: Dao = kodein.instance() - - assertThat(dao1).isNotSameAs(dao2) - } - - @Test - fun whenTaggedBinding_thenMultipleInstancesOfSameTypeCanBeRegistered() { - val kodein = Kodein { - bind("dao1") with singleton { MongoDao() } - bind("dao2") with singleton { MongoDao() } - } - val dao1: Dao = kodein.instance("dao1") - val dao2: Dao = kodein.instance("dao2") - - assertThat(dao1).isNotSameAs(dao2) - } - - @Test - fun whenEagerSingletonBinding_thenCreationIsEager() { - var created = false - val kodein = Kodein { - bind() with eagerSingleton { - created = true - MongoDao() - } - } - - assertThat(created).isTrue() - val dao1: Dao = kodein.instance() - val dao2: Dao = kodein.instance() - - assertThat(dao1).isSameAs(dao2) - } - - @Test - fun whenMultitonBinding_thenInstancesAreReused() { - val kodein = Kodein { - bind() with singleton { MongoDao() } - bind() with multiton { tag: String -> Service(instance(), tag) } - } - val service1: Service = kodein.with("myTag").instance() - val service2: Service = kodein.with("myTag").instance() - - assertThat(service1).isSameAs(service2) - } - - @Test - fun whenInstanceBinding_thenItIsReused() { - val dao = MongoDao() - val kodein = Kodein { - bind() with instance(dao) - } - val fromContainer: Dao = kodein.instance() - - assertThat(dao).isSameAs(fromContainer) - } - - @Test - fun whenConstantBinding_thenItIsAvailable() { - val kodein = Kodein { - constant("magic") with 42 - } - val fromContainer: Int = kodein.instance("magic") - - assertThat(fromContainer).isEqualTo(42) - } - - @Test - fun whenUsingModules_thenTransitiveDependenciesAreSuccessfullyResolved() { - val jdbcModule = Kodein.Module { - bind() with singleton { JdbcDao() } - } - val kodein = Kodein { - import(jdbcModule) - bind() with singleton { Controller(instance()) } - bind() with singleton { Service(instance(), "myService") } - } - - val dao: Dao = kodein.instance() - assertThat(dao).isInstanceOf(JdbcDao::class.java) - } - - @Test - fun whenComposition_thenBeansAreReUsed() { - val persistenceContainer = Kodein { - bind() with singleton { MongoDao() } - } - val serviceContainer = Kodein { - extend(persistenceContainer) - bind() with singleton { Service(instance(), "myService") } - } - val fromPersistence: Dao = persistenceContainer.instance() - val fromService: Dao = serviceContainer.instance() - - assertThat(fromPersistence).isSameAs(fromService) - } - - @Test - fun whenOverriding_thenRightBeanIsUsed() { - val commonModule = Kodein.Module { - bind() with singleton { MongoDao() } - bind() with singleton { Service(instance(), "myService") } - } - val testContainer = Kodein { - import(commonModule) - bind(overrides = true) with singleton { InMemoryDao() } - } - val dao: Dao = testContainer.instance() - - assertThat(dao).isInstanceOf(InMemoryDao::class.java) - } - - @Test - fun whenMultiBinding_thenWorks() { - val kodein = Kodein { - bind() from setBinding() - bind().inSet() with singleton { MongoDao() } - bind().inSet() with singleton { JdbcDao() } - } - val daos: Set = kodein.instance() - - assertThat(daos.map { it.javaClass as Class<*> }).containsOnly(MongoDao::class.java, JdbcDao::class.java) - } - - @Test - fun whenInjector_thenWorks() { - class Controller2 { - private val injector = KodeinInjector() - val service: Service by injector.instance() - fun injectDependencies(kodein: Kodein) = injector.inject(kodein) - } - - val kodein = Kodein { - bind() with singleton { MongoDao() } - bind() with singleton { Service(instance(), "myService") } - } - val controller = Controller2() - controller.injectDependencies(kodein) - - assertThat(controller.service).isNotNull - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt deleted file mode 100644 index ab08273686..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.kotlin; - -import org.junit.Test -import org.mockito.Mockito - -class LibraryManagementTest { - @Test(expected = IllegalStateException::class) - fun whenBookIsNotAvailable_thenAnExceptionIsThrown() { - val mockBookService = Mockito.mock(BookService::class.java) - - Mockito.`when`(mockBookService.inStock(100)).thenReturn(false) - - val manager = LendBookManager(mockBookService) - - manager.checkout(100, 1) - } - - @Test - fun whenBookIsAvailable_thenLendMethodIsCalled() { - val mockBookService = Mockito.mock(BookService::class.java) - - Mockito.`when`(mockBookService.inStock(100)).thenReturn(true) - - val manager = LendBookManager(mockBookService) - - manager.checkout(100, 1) - - Mockito.verify(mockBookService).lend(100, 1) - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt deleted file mode 100644 index 1ff4e20c61..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.kotlin; - -import com.nhaarman.mockito_kotlin.mock -import com.nhaarman.mockito_kotlin.verify -import com.nhaarman.mockito_kotlin.whenever -import org.junit.Test - -class LibraryManagementTestMockitoKotlin { - @Test(expected = IllegalStateException::class) - fun whenBookIsNotAvailable_thenAnExceptionIsThrown() { - val mockBookService = mock() - - whenever(mockBookService.inStock(100)).thenReturn(false) - - val manager = LendBookManager(mockBookService) - - manager.checkout(100, 1) - } - - @Test - fun whenBookIsAvailable_thenLendMethodIsCalled() { - val mockBookService : BookService = mock() - - whenever(mockBookService.inStock(100)).thenReturn(true) - - val manager = LendBookManager(mockBookService) - - manager.checkout(100, 1) - - verify(mockBookService).lend(100, 1) - } -} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt deleted file mode 100644 index 979ed3f809..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/rxkotlin/RxKotlinTest.kt +++ /dev/null @@ -1,157 +0,0 @@ -package com.baeldung.kotlin.rxkotlin - -import io.reactivex.Maybe -import io.reactivex.Observable -import io.reactivex.functions.BiFunction -import io.reactivex.rxkotlin.* -import io.reactivex.subjects.PublishSubject -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse - -class RxKotlinTest { - - @Test - fun whenBooleanArrayToObserver_thenBooleanObserver() { - val observable = listOf(true, false, false).toObservable() - observable.test().assertValues(true, false, false) - } - - @Test - fun whenBooleanArrayToFlowable_thenBooleanFlowable() { - val flowable = listOf(true, false, false).toFlowable() - flowable.buffer(2).test().assertValues(listOf(true, false), listOf(false)) - } - - @Test - fun whenIntArrayToObserver_thenIntObserver() { - val observable = listOf(1, 1, 2, 3).toObservable() - observable.test().assertValues(1, 1, 2, 3) - } - - @Test - fun whenIntArrayToFlowable_thenIntFlowable() { - val flowable = listOf(1, 1, 2, 3).toFlowable() - flowable.buffer(2).test().assertValues(listOf(1, 1), listOf(2, 3)) - } - - @Test - fun whenObservablePairToMap_thenSingleNoDuplicates() { - val list = listOf(Pair("a", 1), Pair("b", 2), Pair("c", 3), Pair("a", 4)) - val observable = list.toObservable() - val map = observable.toMap() - assertEquals(mapOf(Pair("a", 4), Pair("b", 2), Pair("c", 3)), map.blockingGet()) - } - - @Test - fun whenObservablePairToMap_thenSingleWithDuplicates() { - val list = listOf(Pair("a", 1), Pair("b", 2), Pair("c", 3), Pair("a", 4)) - val observable = list.toObservable() - val map = observable.toMultimap() - assertEquals( - mapOf(Pair("a", listOf(1, 4)), Pair("b", listOf(2)), Pair("c", listOf(3))), - map.blockingGet()) - } - - @Test - fun whenMergeAll_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.mergeAll() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenConcatAll_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.concatAll() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenSwitchLatest_thenStream() { - val subject = PublishSubject.create>() - val observable = subject.switchLatest() - val testObserver = observable.test() - subject.onNext(Observable.just("first", "second")) - testObserver.assertValues("first", "second") - subject.onNext(Observable.just("third", "fourth")) - subject.onNext(Observable.just("fifth")) - testObserver.assertValues("first", "second", "third", "fourth", "fifth") - } - - @Test - fun whenMergeAllMaybes_thenObservable() { - val subject = PublishSubject.create>() - val observable = subject.mergeAllMaybes() - val testObserver = observable.test() - subject.onNext(Maybe.just(1)) - subject.onNext(Maybe.just(2)) - subject.onNext(Maybe.empty()) - testObserver.assertValues(1, 2) - subject.onNext(Maybe.error(Exception(""))) - subject.onNext(Maybe.just(3)) - testObserver.assertValues(1, 2).assertError(Exception::class.java) - } - - @Test - fun whenMerge_thenStream() { - val observables = mutableListOf(Observable.just("first", "second")) - val observable = observables.merge() - observables.add(Observable.just("third", "fourth")) - observables.add(Observable.error(Exception("e"))) - observables.add(Observable.just("fifth")) - - observable.test().assertValues("first", "second", "third", "fourth").assertError(Exception::class.java) - } - - @Test - fun whenMergeDelayError_thenStream() { - val observables = mutableListOf>(Observable.error(Exception("e1"))) - val observable = observables.mergeDelayError() - observables.add(Observable.just("1", "2")) - observables.add(Observable.error(Exception("e2"))) - observables.add(Observable.just("3")) - - observable.test().assertValues("1", "2", "3").assertError(Exception::class.java) - } - - @Test - fun whenCast_thenUniformType() { - val observable = Observable.just(1, 1, 2, 3) - observable.cast().test().assertValues(1, 1, 2, 3) - } - - @Test - fun whenOfType_thenFilter() { - val observable = Observable.just(1, "and", 2, "and") - observable.ofType().test().assertValues(1, 2) - } - - @Test - fun whenFunction_thenCompletable() { - var value = 0 - val completable = { value = 3 }.toCompletable() - assertFalse(completable.test().isCancelled) - assertEquals(3, value) - } - - @Test - fun whenHelper_thenMoreIdiomaticKotlin() { - val zipWith = Observable.just(1).zipWith(Observable.just(2)) { a, b -> a + b } - zipWith.subscribeBy(onNext = { println(it) }) - val zip = Observables.zip(Observable.just(1), Observable.just(2)) { a, b -> a + b } - zip.subscribeBy(onNext = { println(it) }) - val zipOrig = Observable.zip(Observable.just(1), Observable.just(2), BiFunction { a, b -> a + b }) - zipOrig.subscribeBy(onNext = { println(it) }) - } -} diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt deleted file mode 100644 index f595d65bf2..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.kotlin.spek - -import com.baeldung.kotlin.junit5.Calculator -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.subject.SubjectSpek -import org.junit.jupiter.api.Assertions.assertEquals - -class CalculatorSubjectTest5 : SubjectSpek({ - subject { Calculator() } - describe("A calculator") { - describe("Addition") { - val result = subject.add(3, 5) - it("Produces the correct answer") { - assertEquals(8, result) - } - } - } -}) diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt deleted file mode 100644 index 3c49d916e4..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.kotlin.spek - -import com.baeldung.kotlin.junit5.Calculator -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.given -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.api.dsl.on -import org.junit.jupiter.api.Assertions.assertEquals - -class CalculatorTest5 : Spek({ - given("A calculator") { - val calculator = Calculator() - on("Adding 3 and 5") { - val result = calculator.add(3, 5) - it("Produces 8") { - assertEquals(8, result) - } - } - } - - describe("A calculator") { - val calculator = Calculator() - describe("Addition") { - val result = calculator.add(3, 5) - it("Produces the correct answer") { - assertEquals(8, result) - } - } - } - -}) diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt deleted file mode 100644 index bbcb36e8bb..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.kotlin.spek - -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.junit.jupiter.api.Assertions - -class DataDrivenTest5 : Spek({ - describe("A data driven test") { - mapOf( - "hello" to "HELLO", - "world" to "WORLD" - ).forEach { input, expected -> - describe("Capitalising $input") { - it("Correctly returns $expected") { - Assertions.assertEquals(expected, input.toUpperCase()) - } - } - } - } -}) diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt deleted file mode 100644 index 5aeee622e4..0000000000 --- a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.baeldung.kotlin.spek - -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it - -class GroupTest5 : Spek({ - describe("Outer group") { - beforeEachTest { - System.out.println("BeforeEachTest 0") - } - beforeGroup { - System.out.println("BeforeGroup 0") - } - afterEachTest { - System.out.println("AfterEachTest 0") - } - afterGroup { - System.out.println("AfterGroup 0") - } - describe("Inner group 1") { - beforeEachTest { - System.out.println("BeforeEachTest 1") - } - beforeGroup { - System.out.println("BeforeGroup 1") - } - afterEachTest { - System.out.println("AfterEachTest 1") - } - afterGroup { - System.out.println("AfterGroup 1") - } - it("Test 1") { - System.out.println("Test 1") - } - it("Test 2") { - System.out.println("Test 2") - } - } - describe("Inner group 2") { - beforeEachTest { - System.out.println("BeforeEachTest 2") - } - beforeGroup { - System.out.println("BeforeGroup 2") - } - afterEachTest { - System.out.println("AfterEachTest 2") - } - afterGroup { - System.out.println("AfterGroup 2") - } - it("Test 3") { - System.out.println("Test 3") - } - it("Test 4") { - System.out.println("Test 4") - } - } - } -}) diff --git a/kotlin-quasar/README.md b/kotlin-quasar/README.md deleted file mode 100644 index b3693284f9..0000000000 --- a/kotlin-quasar/README.md +++ /dev/null @@ -1,4 +0,0 @@ -### Relevant Articles - -- [Introduction to Quasar in Kotlin](https://www.baeldung.com/kotlin-quasar) -- [Advanced Quasar Usage for Kotlin](https://www.baeldung.com/kotlin-quasar-advanced) diff --git a/kotlin-quasar/pom.xml b/kotlin-quasar/pom.xml deleted file mode 100644 index 59553f422e..0000000000 --- a/kotlin-quasar/pom.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - 4.0.0 - kotlin-quasar - 1.0.0-SNAPSHOT - kotlin-quasar - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - co.paralleluniverse - quasar-core - ${quasar.version} - - - co.paralleluniverse - quasar-actors - ${quasar.version} - - - co.paralleluniverse - quasar-reactive-streams - ${quasar.version} - - - co.paralleluniverse - quasar-kotlin - ${quasar.version} - - - junit - junit - ${junit.version} - - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - ch.qos.logback - logback-core - ${logback.version} - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - - - - - src/main/kotlin - src/test/kotlin - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - 1.8 - - - - maven-dependency-plugin - ${dependency.plugin.version} - - - getClasspathFilenames - - properties - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.plugin.version} - - -Dco.paralleluniverse.fibers.verifyInstrumentation=true - -javaagent:${co.paralleluniverse:quasar-core:jar} - - - - org.codehaus.mojo - exec-maven-plugin - ${exec.plugin.version} - - target/classes - echo - - -javaagent:${co.paralleluniverse:quasar-core:jar} - -classpath - - com.baeldung.quasar.QuasarHelloWorldKt - - - - - - - - 0.8.0 - 1.3.31 - 1.7.21 - 1.1.7 - 3.1.1 - 2.22.1 - 1.3.2 - - - diff --git a/kotlin-quasar/src/main/kotlin/com/baeldung/quasar/QuasarHelloWorld.kt b/kotlin-quasar/src/main/kotlin/com/baeldung/quasar/QuasarHelloWorld.kt deleted file mode 100644 index 9bf01ecb09..0000000000 --- a/kotlin-quasar/src/main/kotlin/com/baeldung/quasar/QuasarHelloWorld.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Fiber -import co.paralleluniverse.strands.SuspendableRunnable - - -/** - * Entrypoint into the application - */ -fun main(args: Array) { - class Runnable : SuspendableRunnable { - override fun run() { - println("Hello") - } - } - val result = Fiber(Runnable()).start() - result.join() - println("World") -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsBehaviorTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsBehaviorTest.kt deleted file mode 100644 index b4d0288a64..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsBehaviorTest.kt +++ /dev/null @@ -1,157 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.actors.Actor -import co.paralleluniverse.actors.ActorRef -import co.paralleluniverse.actors.behaviors.* -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.strands.SuspendableCallable -import org.junit.Test -import org.slf4j.LoggerFactory -import java.lang.Exception - -class ActorsBehaviorTest { - companion object { - private val LOG = LoggerFactory.getLogger(ActorsBehaviorTest::class.java) - } - - @Test - fun requestReplyHelper() { - data class TestMessage(val input: Int) : RequestMessage() - - val actor = object : Actor("requestReplyActor", null) { - @Suspendable - override fun doRun(): Void? { - while (true) { - val msg = receive() - LOG.info("Processing message: {}", msg) - - RequestReplyHelper.reply(msg, msg.input * 100) - } - } - } - - val actorRef = actor.spawn() - - val result = RequestReplyHelper.call(actorRef, TestMessage(50)) - LOG.info("Received reply: {}", result) - } - - @Test - fun server() { - val actor = ServerActor(object : AbstractServerHandler() { - @Suspendable - override fun handleCall(from: ActorRef<*>?, id: Any?, m: Int?): String { - LOG.info("Called with message: {} from {} with ID {}", m, from, id) - return m.toString() ?: "None" - } - - @Suspendable - override fun handleCast(from: ActorRef<*>?, id: Any?, m: Float?) { - LOG.info("Cast message: {} from {} with ID {}", m, from, id) - } - }) - - val server = actor.spawn() - - LOG.info("Call result: {}", server.call(5)) - server.cast(2.5f) - - server.shutdown() - } - - interface Summer { - fun sum(a: Int, b: Int) : Int - } - - @Test - fun proxyServer() { - val actor = ProxyServerActor(false, object : Summer { - @Synchronized - override fun sum(a: Int, b: Int): Int { - Exception().printStackTrace() - LOG.info("Adding together {} and {}", a, b) - return a + b - } - }) - - val summerActor = actor.spawn() - - val result = (summerActor as Summer).sum(1, 2) - LOG.info("Result: {}", result) - - summerActor.shutdown() - } - - @Test - fun eventSource() { - val actor = EventSourceActor() - val eventSource = actor.spawn() - - eventSource.addHandler { msg -> - LOG.info("Sent message: {}", msg) - } - - val name = "Outside Value" - eventSource.addHandler { msg -> - LOG.info("Also Sent message: {} {}", msg, name) - } - - eventSource.send("Hello") - - eventSource.shutdown() - } - - @Test - fun finiteStateMachine() { - val actor = object : FiniteStateMachineActor() { - @Suspendable - override fun initialState(): SuspendableCallable> { - LOG.info("Starting") - return SuspendableCallable { lockedState() } - } - - @Suspendable - fun lockedState() : SuspendableCallable> { - return receive {msg -> - when (msg) { - "PUSH" -> { - LOG.info("Still locked") - lockedState() - } - "COIN" -> { - LOG.info("Unlocking...") - unlockedState() - } - else -> TERMINATE - } - } - } - - @Suspendable - fun unlockedState() : SuspendableCallable> { - return receive {msg -> - when (msg) { - "PUSH" -> { - LOG.info("Locking") - lockedState() - } - "COIN" -> { - LOG.info("Unlocked") - unlockedState() - } - else -> TERMINATE - } - } - } - } - - val actorRef = actor.spawn() - - listOf("PUSH", "COIN", "COIN", "PUSH", "PUSH").forEach { - LOG.info(it) - actorRef.sendSync(it) - } - - actorRef.shutdown() - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsTest.kt deleted file mode 100644 index 819a149af3..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ActorsTest.kt +++ /dev/null @@ -1,298 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.actors.* -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.strands.channels.Channels -import org.junit.Assert -import org.junit.Test -import org.slf4j.LoggerFactory -import java.util.concurrent.TimeUnit - -class ActorsTest { - companion object { - private val LOG = LoggerFactory.getLogger(ActorsTest::class.java) - } - - @Test - fun createNoopActor() { - val actor = object : Actor("noopActor", MailboxConfig(5, Channels.OverflowPolicy.THROW)) { - @Suspendable - override fun doRun(): String { - return "Hello" - } - } - - actor.spawn() - - println("Noop Actor: ${actor.get()}") - } - - @Test - fun registerActor() { - val actor = object : Actor("registerActor", null) { - @Suspendable - override fun doRun(): String { - return "Hello" - } - } - - val actorRef = actor.spawn() - actor.register() - - val retrievedRef = ActorRegistry.getActor>("registerActor") - - Assert.assertEquals(actorRef, retrievedRef) - actor.join() - } - - @Test - fun registerActorNewName() { - val actor = object : Actor(null, null) { - @Suspendable - override fun doRun(): String { - return "Hello" - } - } - - val actorRef = actor.spawn() - actor.register("renamedActor") - - val retrievedRef = ActorRegistry.getActor>("renamedActor") - - Assert.assertEquals(actorRef, retrievedRef) - actor.join() - } - - @Test - fun retrieveUnknownActor() { - val retrievedRef = ActorRegistry.getActor>("unknownActor", 1, TimeUnit.SECONDS) - - Assert.assertNull(retrievedRef) - } - - @Test - fun createSimpleActor() { - val actor = object : Actor("simpleActor", null) { - @Suspendable - override fun doRun(): Void? { - val msg = receive() - LOG.info("SimpleActor Received Message: {}", msg) - - return null - } - } - - val actorRef = actor.spawn() - - actorRef.send(1) - - actor.join() - } - - @Test - fun createLoopingActor() { - val actor = object : Actor("loopingActor", null) { - @Suspendable - override fun doRun(): Void? { - while (true) { - val msg = receive() - - if (msg > 0) { - LOG.info("LoopingActor Received Message: {}", msg) - } else { - break - } - } - - return null - } - } - - val actorRef = actor.spawn() - - actorRef.send(3) - actorRef.send(2) - actorRef.send(1) - actorRef.send(0) - - actor.join() - } - - @Test - fun actorBacklog() { - val actor = object : Actor("backlogActor", MailboxConfig(1, Channels.OverflowPolicy.THROW)) { - @Suspendable - override fun doRun(): String { - TimeUnit.MILLISECONDS.sleep(500); - LOG.info("Backlog Actor Received: {}", receive()) - - try { - receive() - } catch (e: Throwable) { - LOG.info("==== Exception throws by receive() ====") - e.printStackTrace() - } - - return "No Exception" - } - } - - val actorRef = actor.spawn() - - actorRef.send(1) - actorRef.send(2) - - try { - LOG.info("Backlog Actor: {}", actor.get()) - } catch (e: Exception) { - // Expected - LOG.info("==== Exception throws by get() ====") - e.printStackTrace() - } - } - - @Test - fun actorBacklogTrySend() { - val actor = object : Actor("backlogTrySendActor", MailboxConfig(1, Channels.OverflowPolicy.THROW)) { - @Suspendable - override fun doRun(): String { - TimeUnit.MILLISECONDS.sleep(500); - LOG.info("Backlog TrySend Actor Received: {}", receive()) - - return "No Exception" - } - } - - val actorRef = actor.spawn() - - LOG.info("Backlog TrySend 1: {}", actorRef.trySend(1)) - LOG.info("Backlog TrySend 1: {}", actorRef.trySend(2)) - - actor.join() - } - - @Test - fun actorTimeoutReceive() { - val actor = object : Actor("TimeoutReceiveActor", MailboxConfig(1, Channels.OverflowPolicy.THROW)) { - @Suspendable - override fun doRun(): String { - LOG.info("Timeout Actor Received: {}", receive(500, TimeUnit.MILLISECONDS)) - - return "Finished" - } - } - - val actorRef = actor.spawn() - - TimeUnit.MILLISECONDS.sleep(300) - actorRef.trySend(1) - - actor.join() - } - - - @Test - fun actorNonBlockingReceive() { - val actor = object : Actor("NonBlockingReceiveActor", MailboxConfig(1, Channels.OverflowPolicy.THROW)) { - @Suspendable - override fun doRun(): String { - LOG.info("NonBlocking Actor Received #1: {}", tryReceive()) - TimeUnit.MILLISECONDS.sleep(500) - LOG.info("NonBlocking Actor Received #2: {}", tryReceive()) - - return "Finished" - } - } - - val actorRef = actor.spawn() - - TimeUnit.MILLISECONDS.sleep(300) - actorRef.trySend(1) - - actor.join() - } - - @Test - fun evenActor() { - val actor = object : Actor("EvenActor", null) { - @Suspendable - override fun filterMessage(m: Any?): Int? { - return when (m) { - is Int -> { - if (m % 2 == 0) { - m * 10 - } else { - null - } - } - else -> super.filterMessage(m) - } - } - - @Suspendable - override fun doRun(): Void? { - while (true) { - val msg = receive() - - if (msg > 0) { - LOG.info("EvenActor Received Message: {}", msg) - } else { - break - } - } - - return null - } - } - - val actorRef = actor.spawn() - - actorRef.send(3) - actorRef.send(2) - actorRef.send(1) - actorRef.send(0) - - actor.join() - } - - @Test - fun watchingActors() { - val watched = object : Actor("WatchedActor", null) { - @Suspendable - override fun doRun(): Void? { - LOG.info("WatchedActor Starting") - receive(500, TimeUnit.MILLISECONDS) - LOG.info("WatchedActor Finishing") - return null - } - } - - val watcher = object : Actor("WatcherActor", null) { - @Suspendable - override fun doRun(): Void? { - LOG.info("WatcherActor Listening") - try { - LOG.info("WatcherActor received Message: {}", receive(2, TimeUnit.SECONDS)) - } catch (e: Exception) { - LOG.info("WatcherActor Received Exception", e) - } - return null - } - - @Suspendable - override fun handleLifecycleMessage(m: LifecycleMessage?): Int? { - LOG.info("WatcherActor Received Lifecycle Message: {}", m) - return super.handleLifecycleMessage(m) - } - } - - val watcherRef = watcher.spawn() - TimeUnit.MILLISECONDS.sleep(200) - - val watchedRef = watched.spawn() - watcher.link(watchedRef) - - watched.join() - watcher.join() - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ChannelsTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ChannelsTest.kt deleted file mode 100644 index b51943446e..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ChannelsTest.kt +++ /dev/null @@ -1,155 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.kotlin.fiber -import co.paralleluniverse.strands.channels.Channels -import co.paralleluniverse.strands.channels.Selector -import com.google.common.base.Function -import org.junit.Test - -class ChannelsTest { - @Test - fun createChannel() { - Channels.newChannel(0, // The size of the channel buffer - Channels.OverflowPolicy.BLOCK, // The policy for when the buffer is full - true, // Whether we should optimize for a single message producer - true) // Whether we should optimize for a single message consumer - } - - @Test - fun blockOnMessage() { - val channel = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - - fiber @Suspendable { - while (!channel.isClosed) { - val message = channel.receive() - println("Received: $message") - } - println("Stopped receiving messages") - } - - channel.send("Hello") - channel.send("World") - - channel.close() - } - - @Test - fun selectReceiveChannels() { - val channel1 = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - val channel2 = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - - fiber @Suspendable { - while (!channel1.isClosed && !channel2.isClosed) { - val received = Selector.select(Selector.receive(channel1), Selector.receive(channel2)) - - println("Received: $received") - } - } - - fiber @Suspendable { - for (i in 0..10) { - channel1.send("Channel 1: $i") - } - } - - fiber @Suspendable { - for (i in 0..10) { - channel2.send("Channel 2: $i") - } - } - } - - @Test - fun selectSendChannels() { - val channel1 = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - val channel2 = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - - fiber @Suspendable { - for (i in 0..10) { - Selector.select( - Selector.send(channel1, "Channel 1: $i"), - Selector.send(channel2, "Channel 2: $i") - ) - } - } - - fiber @Suspendable { - while (!channel1.isClosed) { - val msg = channel1.receive() - println("Read: $msg") - } - } - - fiber @Suspendable { - while (!channel2.isClosed) { - val msg = channel2.receive() - println("Read: $msg") - } - } - } - - @Test - fun tickerChannel() { - val channel = Channels.newChannel(3, Channels.OverflowPolicy.DISPLACE) - - for (i in 0..10) { - val tickerConsumer = Channels.newTickerConsumerFor(channel) - fiber @Suspendable { - while (!tickerConsumer.isClosed) { - val message = tickerConsumer.receive() - println("Received on $i: $message") - } - println("Stopped receiving messages on $i") - } - } - - for (i in 0..50) { - channel.send("Message $i") - } - - channel.close() - } - - - @Test - fun transformOnSend() { - val channel = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - - fiber @Suspendable { - while (!channel.isClosed) { - val message = channel.receive() - println("Received: $message") - } - println("Stopped receiving messages") - } - - val transformOnSend = Channels.mapSend(channel, Function { msg: String? -> msg?.toUpperCase() }) - - transformOnSend.send("Hello") - transformOnSend.send("World") - - channel.close() - } - - @Test - fun transformOnReceive() { - val channel = Channels.newChannel(0, Channels.OverflowPolicy.BLOCK, true, true) - - val transformOnReceive = Channels.map(channel, Function { msg: String? -> msg?.reversed() }) - - fiber @Suspendable { - while (!transformOnReceive.isClosed) { - val message = transformOnReceive.receive() - println("Received: $message") - } - println("Stopped receiving messages") - } - - - channel.send("Hello") - channel.send("World") - - channel.close() - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/DataflowTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/DataflowTest.kt deleted file mode 100644 index 3f73af3917..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/DataflowTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.strands.dataflow.Val -import co.paralleluniverse.strands.dataflow.Var -import org.junit.Assert -import org.junit.Test -import java.util.concurrent.TimeUnit - -class DataflowTest { - @Test - fun testValVar() { - val a = Var() - val b = Val() - - val c = Var { a.get() + b.get() } - val d = Var { a.get() * b.get() } - - // (a*b) - (a+b) - val initialResult = Val { d.get() - c.get() } - val currentResult = Var { d.get() - c.get() } - - a.set(2) - b.set(4) - - Assert.assertEquals(2, initialResult.get()) - Assert.assertEquals(2, currentResult.get()) - - a.set(3) - - TimeUnit.SECONDS.sleep(1) - - Assert.assertEquals(2, initialResult.get()) - Assert.assertEquals(5, currentResult.get()) - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/PiAsyncTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/PiAsyncTest.kt deleted file mode 100644 index d4ea04820d..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/PiAsyncTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Fiber -import co.paralleluniverse.fibers.FiberAsync -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.kotlin.fiber -import co.paralleluniverse.strands.Strand -import org.junit.Assert -import org.junit.Test -import java.math.BigDecimal -import java.util.concurrent.TimeUnit - -interface PiCallback { - fun success(result: BigDecimal) - fun failure(error: Exception) -} - -fun computePi(callback: PiCallback) { - println("Starting calculations") - TimeUnit.SECONDS.sleep(2) - println("Finished calculations") - callback.success(BigDecimal("3.14")) -} - -class PiAsync : PiCallback, FiberAsync() { - override fun success(result: BigDecimal) { - asyncCompleted(result) - } - - override fun failure(error: Exception) { - asyncFailed(error) - } - - override fun requestAsync() { - computePi(this) - } -} - -class PiAsyncTest { - @Test - fun testPi() { - val result = fiber @Suspendable { - val pi = PiAsync() - println("Waiting to get PI on: " + Fiber.currentFiber().name) - val result = pi.run() - println("Got PI") - - result - }.get() - - Assert.assertEquals(BigDecimal("3.14"), result) - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ReactiveStreamsTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ReactiveStreamsTest.kt deleted file mode 100644 index 83e06bf7d6..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/ReactiveStreamsTest.kt +++ /dev/null @@ -1,135 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.kotlin.fiber -import co.paralleluniverse.strands.channels.Channels -import co.paralleluniverse.strands.channels.Topic -import co.paralleluniverse.strands.channels.reactivestreams.ReactiveStreams -import org.junit.Test -import org.reactivestreams.Subscriber -import org.reactivestreams.Subscription -import org.slf4j.LoggerFactory -import java.util.concurrent.TimeUnit - -class ReactiveStreamsTest { - companion object { - private val LOG = LoggerFactory.getLogger(ReactiveStreamsTest::class.java) - } - - @Test - fun publisher() { - val inputChannel = Channels.newChannel(1); - - val publisher = ReactiveStreams.toPublisher(inputChannel) - publisher.subscribe(object : Subscriber { - @Suspendable - override fun onComplete() { - LOG.info("onComplete") - } - - @Suspendable - override fun onSubscribe(s: Subscription) { - LOG.info("onSubscribe: {}", s) - s.request(2) - } - - @Suspendable - override fun onNext(t: String?) { - LOG.info("onNext: {}", t) - } - - @Suspendable - override fun onError(t: Throwable?) { - LOG.info("onError: {}", t) - } - }) - - inputChannel.send("Hello") - inputChannel.send("World") - - TimeUnit.SECONDS.sleep(1) - - inputChannel.close() - } - - @Test - fun publisherTopic() { - val inputTopic = Topic() - - val publisher = ReactiveStreams.toPublisher(inputTopic) - publisher.subscribe(object : Subscriber { - @Suspendable - override fun onComplete() { - LOG.info("onComplete 1") - } - - @Suspendable - override fun onSubscribe(s: Subscription) { - LOG.info("onSubscribe 1: {}", s) - s.request(2) - } - - @Suspendable - override fun onNext(t: String?) { - LOG.info("onNext 1: {}", t) - } - - @Suspendable - override fun onError(t: Throwable?) { - LOG.info("onError 1: {}", t) - } - }) - publisher.subscribe(object : Subscriber { - @Suspendable - override fun onComplete() { - LOG.info("onComplete 2") - } - - @Suspendable - override fun onSubscribe(s: Subscription) { - LOG.info("onSubscribe 2: {}", s) - s.request(2) - } - - @Suspendable - override fun onNext(t: String?) { - LOG.info("onNext 2: {}", t) - } - - @Suspendable - override fun onError(t: Throwable?) { - LOG.info("onError 2: {}", t) - } - }) - - inputTopic.send("Hello") - inputTopic.send("World") - - TimeUnit.SECONDS.sleep(1) - - inputTopic.close() - } - - @Test - fun subscribe() { - val inputChannel = Channels.newChannel(10); - val publisher = ReactiveStreams.toPublisher(inputChannel) - - val channel = ReactiveStreams.subscribe(10, Channels.OverflowPolicy.THROW, publisher) - - fiber @Suspendable { - while (!channel.isClosed) { - val message = channel.receive() - LOG.info("Received: {}", message) - } - LOG.info("Stopped receiving messages") - } - - inputChannel.send("Hello") - inputChannel.send("World") - - TimeUnit.SECONDS.sleep(1) - - inputChannel.close() - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspendableCallableTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspendableCallableTest.kt deleted file mode 100644 index 9b139dd686..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspendableCallableTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Fiber -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.kotlin.fiber -import co.paralleluniverse.strands.SuspendableCallable -import org.junit.Assert -import org.junit.Test -import java.util.concurrent.TimeUnit - - -class SuspendableCallableTest { - @Test - fun createFiber() { - class Callable : SuspendableCallable { - override fun run(): String { - println("Inside Fiber") - return "Hello" - } - } - val result = Fiber(Callable()).start() - - Assert.assertEquals("Hello", result.get()) - } - - @Test - fun createFiberLambda() { - val lambda: (() -> String) = { - println("Inside Fiber Lambda") - "Hello" - } - val result = Fiber(lambda) - result.start() - - Assert.assertEquals("Hello", result.get()) - } - - @Test - fun createFiberDsl() { - val result = fiber @Suspendable { - TimeUnit.SECONDS.sleep(5) - println("Inside Fiber DSL") - "Hello" - } - - Assert.assertEquals("Hello", result.get()) - } -} diff --git a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspensableRunnableTest.kt b/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspensableRunnableTest.kt deleted file mode 100644 index ba4cef8f4c..0000000000 --- a/kotlin-quasar/src/test/kotlin/com/baeldung/quasar/SuspensableRunnableTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.quasar - -import co.paralleluniverse.fibers.Fiber -import co.paralleluniverse.fibers.Suspendable -import co.paralleluniverse.kotlin.fiber -import co.paralleluniverse.strands.SuspendableRunnable -import org.junit.Test -import java.util.concurrent.TimeUnit -import java.util.concurrent.TimeoutException - - -class SuspensableRunnableTest { - @Test - fun createFiber() { - class Runnable : SuspendableRunnable { - override fun run() { - println("Inside Fiber") - } - } - val result = Fiber(Runnable()).start() - result.join() - } - - @Test - fun createFiberLambda() { - val result = Fiber { - println("Inside Fiber Lambda") - } - result.start() - result.join() - } - - @Test - fun createFiberDsl() { - fiber @Suspendable { - println("Inside Fiber DSL") - }.join() - } - - @Test(expected = TimeoutException::class) - fun fiberTimeout() { - fiber @Suspendable { - TimeUnit.SECONDS.sleep(5) - println("Inside Fiber DSL") - }.join(2, TimeUnit.SECONDS) - } -} diff --git a/parent-kotlin/README.md b/parent-kotlin/README.md deleted file mode 100644 index c78ecbac42..0000000000 --- a/parent-kotlin/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Parent Kotlin - -This is a parent module for all projects using Kotlin diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml deleted file mode 100644 index 947dd20483..0000000000 --- a/parent-kotlin/pom.xml +++ /dev/null @@ -1,223 +0,0 @@ - - - 4.0.0 - parent-kotlin - parent-kotlin - pom - Parent for all kotlin modules - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - jcenter - https://jcenter.bintray.com - - - kotlin-ktor - https://dl.bintray.com/kotlin/ktor/ - - - kotlin-eap - https://dl.bintray.com/kotlin/kotlin-eap - - - spring-milestone - Spring Milestone Repository - https://repo.spring.io/milestone - - - - - - kotlin-eap - https://dl.bintray.com/kotlin/kotlin-eap - - - - - - - org.springframework.boot - spring-boot-dependencies - ${boot.dependencies.version} - pom - import - - - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-reflect - - - - org.jetbrains.kotlinx - kotlinx-coroutines-core - ${kotlinx.version} - - - - io.ktor - ktor-server-netty - ${ktor.io.version} - - - io.ktor - ktor-gson - ${ktor.io.version} - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - - org.jetbrains.kotlin - kotlin-test-junit - test - - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - - compile - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/java - - ${java.version} - - -Xjvm-default=enable - - - - - test-compile - - test-compile - - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/java - - ${java.version} - - - - - - spring - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - - compile - - - - java-test-compile - test-compile - - testCompile - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - ${maven-failsafe-plugin.version} - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - - - - junit5 - - integration-test - verify - - - - **/*Test5.java - - - - - - - - - - 1.3.30 - 1.0.0 - 0.9.5 - 3.12.0 - 1.3.2 - 2.2.0.M4 - - - diff --git a/pom.xml b/pom.xml index ccc22a1546..ed2f31c394 100644 --- a/pom.xml +++ b/pom.xml @@ -325,7 +325,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin akka-http akka-streams @@ -386,7 +385,6 @@ core-groovy-strings core-java-modules - core-kotlin-modules core-scala couchbase @@ -457,7 +455,6 @@ jaxb jee-7 jee-7-security - jee-kotlin jersey jgit jgroups @@ -475,11 +472,6 @@ jsoup jta - - kotlin-libraries - kotlin-libraries-2 - kotlin-quasar - language-interop libraries-2 @@ -599,7 +591,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin saas software-security/sql-injection-samples @@ -683,7 +674,6 @@ spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 - spring-mvc-kotlin spring-mvc-velocity spring-mvc-views @@ -693,7 +683,6 @@ spring-protobuf spring-quartz - spring-reactive-kotlin spring-reactor spring-remoting spring-rest-angular @@ -793,7 +782,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin jenkins/plugins jhipster @@ -838,7 +826,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin akka-http akka-streams @@ -898,7 +885,6 @@ core-groovy-strings core-java-modules - core-kotlin-modules core-scala couchbase @@ -969,7 +955,6 @@ jaxb jee-7 jee-7-security - jee-kotlin jersey jgit jgroups @@ -986,11 +971,6 @@ jsoup jta - - kotlin-libraries - kotlin-libraries-2 - kotlin-quasar - libraries-2 libraries-3 @@ -1101,7 +1081,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin saas software-security/sql-injection-samples @@ -1183,8 +1162,7 @@ spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java - spring-mvc-java-2 - spring-mvc-kotlin + spring-mvc-java-2 spring-mvc-velocity spring-mvc-views @@ -1195,7 +1173,6 @@ spring-protobuf spring-quartz - spring-reactive-kotlin spring-reactor spring-remoting spring-rest-angular @@ -1286,7 +1263,6 @@ parent-spring-4 parent-spring-5 parent-java - parent-kotlin jenkins/plugins jhipster diff --git a/spring-boot-modules/spring-boot-kotlin/README.md b/spring-boot-modules/spring-boot-kotlin/README.md deleted file mode 100644 index fb91fdee15..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Spring Boot Kotlin - -This module contains articles about Kotlin in Spring Boot projects. - -### Relevant Articles: -- [Non-blocking Spring Boot with Kotlin Coroutines](https://www.baeldung.com/spring-boot-kotlin-coroutines) diff --git a/spring-boot-modules/spring-boot-kotlin/pom.xml b/spring-boot-modules/spring-boot-kotlin/pom.xml deleted file mode 100644 index 7ee048546a..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/pom.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - 4.0.0 - spring-boot-kotlin - spring-boot-kotlin - jar - Demo project showing how to use non-blocking in Kotlin with Spring Boot - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../../parent-kotlin - - - - - org.jetbrains.kotlin - kotlin-reflect - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - org.jetbrains.kotlinx - kotlinx-coroutines-core - ${kotlinx-coroutines.version} - - - org.jetbrains.kotlinx - kotlinx-coroutines-reactor - ${kotlinx-coroutines.version} - - - org.springframework.boot - spring-boot-starter-webflux - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.springframework.data - spring-data-r2dbc - ${r2dbc.version} - - - io.r2dbc - r2dbc-h2 - ${h2-r2dbc.version} - - - io.r2dbc - r2dbc-spi - ${r2dbc-spi.version} - - - org.springframework.boot - spring-boot-starter-test - test - - - junit - junit - - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - io.projectreactor - reactor-test - test - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - -Xjsr305=strict - - - spring - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - - - - 1.3.31 - 1.0.0.RELEASE - 0.8.2.RELEASE - 0.8.4.RELEASE - 1.2.1 - - - diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/SpringApplication.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/SpringApplication.kt deleted file mode 100644 index 23af4fe90b..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/SpringApplication.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.nonblockingcoroutines - -import org.springframework.boot.SpringApplication.run -import org.springframework.boot.autoconfigure.SpringBootApplication - -@SpringBootApplication -class SpringApplication - -fun main(args: Array) { - run(SpringApplication::class.java, *args) -} diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/DatastoreConfig.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/DatastoreConfig.kt deleted file mode 100644 index 52ef8a708b..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/DatastoreConfig.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.nonblockingcoroutines.config - -import io.r2dbc.h2.H2ConnectionConfiguration -import io.r2dbc.h2.H2ConnectionFactory -import io.r2dbc.spi.ConnectionFactory -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration -import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories - -@Configuration -@EnableR2dbcRepositories -class DatastoreConfig : AbstractR2dbcConfiguration() { - @Value("\${spring.datasource.username}") - private val userName: String = "" - - @Value("\${spring.datasource.password}") - private val password: String = "" - - @Value("\${spring.datasource.dbname}") - private val dbName: String = "" - - @Bean - override fun connectionFactory(): ConnectionFactory { - return H2ConnectionFactory(H2ConnectionConfiguration.builder() - .inMemory(dbName) - .username(userName) - .password(password) - .build()) - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/RouterConfiguration.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/RouterConfiguration.kt deleted file mode 100644 index bda1d26278..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/RouterConfiguration.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.nonblockingcoroutines.config - -import com.baeldung.nonblockingcoroutines.handlers.ProductsHandler -import kotlinx.coroutines.FlowPreview -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.reactive.function.server.coRouter - -@Configuration -class RouterConfiguration { - - @FlowPreview - @Bean - fun productRoutes(productsHandler: ProductsHandler) = coRouter { - GET("/", productsHandler::findAll) - GET("/{id}", productsHandler::findOne) - GET("/{id}/stock", productsHandler::findOneInStock) - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/WebClientConfiguration.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/WebClientConfiguration.kt deleted file mode 100644 index 85938b8be2..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/config/WebClientConfiguration.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.nonblockingcoroutines.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.reactive.function.client.WebClient - -@Configuration -class WebClientConfiguration { - - @Bean - fun webClient() = WebClient.builder().baseUrl("http://localhost:8080").build() -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductController.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductController.kt deleted file mode 100644 index 91b091859a..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductController.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.nonblockingcoroutines.controller - -import com.baeldung.nonblockingcoroutines.model.Product -import com.baeldung.nonblockingcoroutines.repository.ProductRepository -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.reactive.function.client.WebClient -import org.springframework.web.reactive.function.client.bodyToMono -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono - -class ProductController { - @Autowired - lateinit var webClient: WebClient - @Autowired - lateinit var productRepository: ProductRepository - - @GetMapping("/{id}") - fun findOne(@PathVariable id: Int): Mono { - return productRepository - .getProductById(id) - } - - @GetMapping("/{id}/stock") - fun findOneInStock(@PathVariable id: Int): Mono { - val product = productRepository.getProductById(id) - - val stockQuantity = webClient.get() - .uri("/stock-service/product/$id/quantity") - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono() - return product.zipWith(stockQuantity) { productInStock, stockQty -> - ProductStockView(productInStock, stockQty) - } - } - - @GetMapping("/stock-service/product/{id}/quantity") - fun getStockQuantity(): Mono { - return Mono.just(2) - } - - @GetMapping("/") - fun findAll(): Flux { - return productRepository.getAllProducts() - } -} diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt deleted file mode 100644 index 464ed2773a..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.nonblockingcoroutines.controller - -import com.baeldung.nonblockingcoroutines.model.Product -import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.flow.Flow -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType.APPLICATION_JSON -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.reactive.function.client.WebClient -import org.springframework.web.reactive.function.client.awaitBody - -class ProductControllerCoroutines { - @Autowired - lateinit var webClient: WebClient - - @Autowired - lateinit var productRepository: ProductRepositoryCoroutines - - @GetMapping("/{id}") - suspend fun findOne(@PathVariable id: Int): Product? { - return productRepository.getProductById(id) - } - - @GetMapping("/{id}/stock") - suspend fun findOneInStock(@PathVariable id: Int): ProductStockView = coroutineScope { - val product: Deferred = async(start = CoroutineStart.LAZY) { - productRepository.getProductById(id) - } - val quantity: Deferred = async(start = CoroutineStart.LAZY) { - webClient.get() - .uri("/stock-service/product/$id/quantity") - .accept(APPLICATION_JSON) - .retrieve().awaitBody() - } - ProductStockView(product.await()!!, quantity.await()) - } - - @FlowPreview - @GetMapping("/") - fun findAll(): Flow { - return productRepository.getAllProducts() - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductStockView.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductStockView.kt deleted file mode 100644 index 44611fd1de..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductStockView.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.nonblockingcoroutines.controller - -import com.baeldung.nonblockingcoroutines.model.Product - -class ProductStockView(product: Product, var stockQuantity: Int) { - var id: Int = 0 - var name: String = "" - var price: Float = 0.0f - - init { - this.id = product.id - this.name = product.name - this.price = product.price - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt deleted file mode 100644 index e05b718e64..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.nonblockingcoroutines.handlers - -import com.baeldung.nonblockingcoroutines.controller.ProductStockView -import com.baeldung.nonblockingcoroutines.model.Product -import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.async -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType -import org.springframework.stereotype.Component -import org.springframework.web.reactive.function.client.WebClient -import org.springframework.web.reactive.function.client.awaitBody -import org.springframework.web.reactive.function.server.ServerRequest -import org.springframework.web.reactive.function.server.ServerResponse -import org.springframework.web.reactive.function.server.bodyAndAwait -import org.springframework.web.reactive.function.server.json - -@Component -class ProductsHandler( - @Autowired var webClient: WebClient, - @Autowired var productRepository: ProductRepositoryCoroutines) { - - @FlowPreview - suspend fun findAll(request: ServerRequest): ServerResponse = - ServerResponse.ok().json().bodyAndAwait(productRepository.getAllProducts()) - - suspend fun findOneInStock(request: ServerRequest): ServerResponse { - val id = request.pathVariable("id").toInt() - - val product: Deferred = GlobalScope.async { - productRepository.getProductById(id) - } - val quantity: Deferred = GlobalScope.async { - webClient.get() - .uri("/stock-service/product/$id/quantity") - .accept(MediaType.APPLICATION_JSON) - .retrieve().awaitBody() - } - return ServerResponse.ok().json().bodyAndAwait(ProductStockView(product.await()!!, quantity.await())) - } - - suspend fun findOne(request: ServerRequest): ServerResponse { - val id = request.pathVariable("id").toInt() - return ServerResponse.ok().json().bodyAndAwait(productRepository.getProductById(id)!!) - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/model/Product.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/model/Product.kt deleted file mode 100644 index c6dcbdc9c4..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/model/Product.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.nonblockingcoroutines.model - -data class Product( - var id: Int = 0, - var name: String = "", - var price: Float = 0.0f -) diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt deleted file mode 100644 index 64ffd014ad..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.nonblockingcoroutines.repository - -import com.baeldung.nonblockingcoroutines.model.Product -import org.springframework.data.r2dbc.core.DatabaseClient -import org.springframework.stereotype.Repository -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono - -@Repository -class ProductRepository(private val client: DatabaseClient) { - - fun getProductById(id: Int): Mono { - return client.execute("SELECT * FROM products WHERE id = $1") - .bind(0, id) - .`as`(Product::class.java) - .fetch() - .one() - } - - fun addNewProduct(name: String, price: Float): Mono { - return client.execute("INSERT INTO products (name, price) VALUES($1, $2)") - .bind(0, name) - .bind(1, price) - .then() - } - - fun getAllProducts(): Flux { - return client.select().from("products") - .`as`(Product::class.java) - .fetch() - .all() - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt deleted file mode 100644 index f2667ec033..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.nonblockingcoroutines.repository - - -import com.baeldung.nonblockingcoroutines.model.Product -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.reactive.awaitFirstOrNull -import kotlinx.coroutines.reactive.flow.asFlow -import org.springframework.data.r2dbc.core.DatabaseClient -import org.springframework.stereotype.Repository - -@Repository -class ProductRepositoryCoroutines(private val client: DatabaseClient) { - - suspend fun getProductById(id: Int): Product? = - client.execute("SELECT * FROM products WHERE id = $1") - .bind(0, id) - .`as`(Product::class.java) - .fetch() - .one() - .awaitFirstOrNull() - - suspend fun addNewProduct(name: String, price: Float) = - client.execute("INSERT INTO products (name, price) VALUES($1, $2)") - .bind(0, name) - .bind(1, price) - .then() - .awaitFirstOrNull() - - @FlowPreview - fun getAllProducts(): Flow = - client.select() - .from("products") - .`as`(Product::class.java) - .fetch() - .all() - .log() - .asFlow() -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/resources/application.properties b/spring-boot-modules/spring-boot-kotlin/src/main/resources/application.properties deleted file mode 100644 index 0f84ff2d75..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/resources/application.properties +++ /dev/null @@ -1,8 +0,0 @@ -logging.level.org.springframework.data.r2dbc=DEBUG -logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACE -spring.http.log-request-details=true -spring.h2.console.enabled=true -spring.datasource.username=sa -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.password= -spring.datasource.dbname=testdb \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/resources/logback.xml b/spring-boot-modules/spring-boot-kotlin/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-kotlin/src/test/kotlin/com/baeldung/nonblockingcoroutines/ProductHandlerTest.kt b/spring-boot-modules/spring-boot-kotlin/src/test/kotlin/com/baeldung/nonblockingcoroutines/ProductHandlerTest.kt deleted file mode 100644 index 53b1d50f21..0000000000 --- a/spring-boot-modules/spring-boot-kotlin/src/test/kotlin/com/baeldung/nonblockingcoroutines/ProductHandlerTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.nonblockingcoroutines - -import com.baeldung.nonblockingcoroutines.config.RouterConfiguration -import com.baeldung.nonblockingcoroutines.handlers.ProductsHandler -import com.baeldung.nonblockingcoroutines.model.Product -import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.reactive.flow.asFlow -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.BDDMockito.given -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration -import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.boot.test.mock.mockito.MockBean -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.reactive.server.WebTestClient -import org.springframework.test.web.reactive.server.expectBodyList -import org.springframework.web.reactive.function.client.WebClient -import reactor.core.publisher.Flux -import org.springframework.test.context.ContextConfiguration - -@WebFluxTest( - excludeAutoConfiguration = [ReactiveUserDetailsServiceAutoConfiguration::class, ReactiveSecurityAutoConfiguration::class] -) -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ProductsHandler::class, RouterConfiguration::class]) -class ProductHandlerTest { - - @Autowired - private lateinit var client: WebTestClient - - @MockBean - private lateinit var webClient: WebClient - - @MockBean - private lateinit var productsRepository: ProductRepositoryCoroutines - - - @FlowPreview - @Test - public fun `get all products`() { - val productsFlow = Flux.just( - Product(1, "product1", 1000.0F), - Product(2, "product2", 2000.0F), - Product(3, "product3", 3000.0F) - ).asFlow() - given(productsRepository.getAllProducts()).willReturn(productsFlow) - client.get() - .uri("/") - .exchange() - .expectStatus() - .isOk - .expectBodyList() - } - -} diff --git a/spring-mvc-kotlin/.gitignore b/spring-mvc-kotlin/.gitignore deleted file mode 100644 index 416395ffea..0000000000 --- a/spring-mvc-kotlin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -transaction.log \ No newline at end of file diff --git a/spring-mvc-kotlin/README.md b/spring-mvc-kotlin/README.md deleted file mode 100644 index 590c627cb6..0000000000 --- a/spring-mvc-kotlin/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Spring MVC with Kotlin - -This module contains articles about Spring MVC with Kotlin - -### Relevant articles -- [Spring MVC Setup with Kotlin](https://www.baeldung.com/spring-mvc-kotlin) -- [Working with Kotlin and JPA](https://www.baeldung.com/kotlin-jpa) -- [Kotlin-allopen and Spring](https://www.baeldung.com/kotlin-allopen-spring) -- [MockMvc Kotlin DSL](https://www.baeldung.com/mockmvc-kotlin-dsl) diff --git a/spring-mvc-kotlin/pom.xml b/spring-mvc-kotlin/pom.xml deleted file mode 100644 index 30d2c32ecf..0000000000 --- a/spring-mvc-kotlin/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - 4.0.0 - spring-mvc-kotlin - spring-mvc-kotlin - war - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../parent-kotlin - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-json - - - org.thymeleaf - thymeleaf - - - org.thymeleaf - thymeleaf-spring4 - ${thymeleaf.version} - - - org.hibernate - hibernate-core - - - org.hibernate - hibernate-testing - test - - - com.h2database - h2 - test - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - spring - jpa - - - - - org.jetbrains.kotlin - kotlin-maven-noarg - ${kotlin.version} - - - - - - - - 3.0.7.RELEASE - - - \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/allopen/SimpleConfiguration.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/allopen/SimpleConfiguration.kt deleted file mode 100644 index 5d0a3e13bf..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/allopen/SimpleConfiguration.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.kotlin.allopen - -import org.springframework.context.annotation.Configuration - -@Configuration -class SimpleConfiguration { -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/Person.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/Person.kt deleted file mode 100644 index 2b2a2bd6d9..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/Person.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.kotlin.jpa - -import javax.persistence.CascadeType -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.GenerationType -import javax.persistence.Id -import javax.persistence.OneToMany - -@Entity -data class Person @JvmOverloads constructor( - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - val id: Int, - @Column(nullable = false) - val name: String, - @Column(nullable = true) - val email: String? = null, - @OneToMany(cascade = [CascadeType.ALL]) - val phoneNumbers: List? = null) diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/PhoneNumber.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/PhoneNumber.kt deleted file mode 100644 index 734e8b4cc4..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/jpa/PhoneNumber.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.kotlin.jpa - -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.GenerationType -import javax.persistence.Id - -@Entity -data class PhoneNumber( - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - val id: Int, - @Column(nullable = false) - val number: String) \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcController.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcController.kt deleted file mode 100644 index 68ab5f31a6..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcController.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.kotlin.mockmvc - -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod -import org.springframework.web.bind.annotation.RestController - -@RestController -@RequestMapping("/mockmvc") -class MockMvcController { - - @RequestMapping(value = ["/validate"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) - fun validate(@RequestBody request: Request): Response { - val error = if (request.name.first == "admin") { - null - } else { - ERROR - } - return Response(error) - } - - companion object { - const val ERROR = "invalid user" - } -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcModel.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcModel.kt deleted file mode 100644 index 3231b6f186..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mockmvc/MockMvcModel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.kotlin.mockmvc - -import com.fasterxml.jackson.annotation.JsonInclude - -data class Name(val first: String, val last: String) - -data class Request(val name: Name) - -@JsonInclude(JsonInclude.Include.NON_NULL) -data class Response(val error: String?) \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebConfig.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebConfig.kt deleted file mode 100644 index 23aadf282a..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebConfig.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.kotlin.mvc - -import org.springframework.context.ApplicationContext -import org.springframework.context.ApplicationContextAware -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.servlet.config.annotation.EnableWebMvc -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter -import org.thymeleaf.spring4.SpringTemplateEngine -import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver -import org.thymeleaf.spring4.view.ThymeleafViewResolver -import org.thymeleaf.templatemode.TemplateMode - -@EnableWebMvc -@Configuration -open class ApplicationWebConfig : WebMvcConfigurerAdapter(), ApplicationContextAware { - - private var applicationContext: ApplicationContext? = null - - override fun setApplicationContext(applicationContext: ApplicationContext?) { - this.applicationContext = applicationContext - } - - override fun addViewControllers(registry: ViewControllerRegistry?) { - super.addViewControllers(registry) - - registry!!.addViewController("/welcome.html") - } - - @Bean - open fun templateResolver(): SpringResourceTemplateResolver { - return SpringResourceTemplateResolver() - .apply { prefix = "/WEB-INF/view/" } - .apply { suffix = ".html"} - .apply { templateMode = TemplateMode.HTML } - .apply { setApplicationContext(applicationContext) } - } - - @Bean - open fun templateEngine(): SpringTemplateEngine { - return SpringTemplateEngine() - .apply { setTemplateResolver(templateResolver()) } - } - - @Bean - open fun viewResolver(): ThymeleafViewResolver { - return ThymeleafViewResolver() - .apply { templateEngine = templateEngine() } - .apply { order = 1 } - } -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebInitializer.kt b/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebInitializer.kt deleted file mode 100644 index 4c1a35823c..0000000000 --- a/spring-mvc-kotlin/src/main/kotlin/com/baeldung/kotlin/mvc/ApplicationWebInitializer.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.kotlin.mvc - -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer - -class ApplicationWebInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { - - override fun getRootConfigClasses(): Array>? { - return null - } - - override fun getServletMappings(): Array { - return arrayOf("/") - } - - override fun getServletConfigClasses(): Array> { - return arrayOf(ApplicationWebConfig::class.java) - } -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/resources/logback.xml b/spring-mvc-kotlin/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-mvc-kotlin/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/webapp/WEB-INF/spring-web-config.xml b/spring-mvc-kotlin/src/main/webapp/WEB-INF/spring-web-config.xml deleted file mode 100644 index c7f110ea94..0000000000 --- a/spring-mvc-kotlin/src/main/webapp/WEB-INF/spring-web-config.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp deleted file mode 100644 index 3f68f128bc..0000000000 --- a/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp +++ /dev/null @@ -1,7 +0,0 @@ - - Welcome - - -

    This is the body of the welcome view

    - - \ No newline at end of file diff --git a/spring-mvc-kotlin/src/main/webapp/WEB-INF/web.xml b/spring-mvc-kotlin/src/main/webapp/WEB-INF/web.xml deleted file mode 100755 index cbee6a1b11..0000000000 --- a/spring-mvc-kotlin/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - Spring Kotlin MVC Application - - - spring-web-mvc - org.springframework.web.servlet.DispatcherServlet - 1 - - contextConfigLocation - /WEB-INF/spring-web-config.xml - - - - - spring-web-mvc - / - - - \ No newline at end of file diff --git a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/allopen/SimpleConfigurationTest.kt b/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/allopen/SimpleConfigurationTest.kt deleted file mode 100644 index 65a60c7157..0000000000 --- a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/allopen/SimpleConfigurationTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.kotlin.allopen - -import org.junit.Test -import org.junit.runner.RunWith -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner -import org.springframework.test.context.support.AnnotationConfigContextLoader - -@RunWith(SpringJUnit4ClassRunner::class) -@ContextConfiguration( - loader = AnnotationConfigContextLoader::class, - classes = arrayOf(SimpleConfiguration::class)) -class SimpleConfigurationTest { - - @Test - fun contextLoads() { - } - -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/jpa/HibernateKotlinIntegrationTest.kt b/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/jpa/HibernateKotlinIntegrationTest.kt deleted file mode 100644 index adac9d0cbf..0000000000 --- a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/jpa/HibernateKotlinIntegrationTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.kotlin.jpa - -import org.hibernate.cfg.Configuration -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase -import org.hibernate.testing.transaction.TransactionUtil.doInHibernate -import org.junit.Assert.assertTrue -import org.junit.Test -import java.io.IOException -import java.util.* - - -class HibernateKotlinIntegrationTest : BaseCoreFunctionalTestCase() { - - private val properties: Properties - @Throws(IOException::class) - get() { - val properties = Properties() - properties.load(javaClass.classLoader.getResourceAsStream("hibernate.properties")) - return properties - } - - override fun getAnnotatedClasses(): Array> { - return arrayOf(Person::class.java, PhoneNumber::class.java) - } - - override fun configure(configuration: Configuration) { - super.configure(configuration) - configuration.properties = properties - } - - @Test - fun givenPersonWithFullData_whenSaved_thenFound() { - doInHibernate(({ this.sessionFactory() }), { session -> - val personToSave = Person(0, "John", "jhon@test.com", Arrays.asList(PhoneNumber(0, "202-555-0171"), PhoneNumber(0, "202-555-0102"))) - session.persist(personToSave) - val personFound = session.find(Person::class.java, personToSave.id) - session.refresh(personFound) - - assertTrue(personToSave == personFound) - }) - } - - @Test - fun givenPerson_whenSaved_thenFound() { - doInHibernate(({ this.sessionFactory() }), { session -> - val personToSave = Person(0, "John") - session.persist(personToSave) - val personFound = session.find(Person::class.java, personToSave.id) - session.refresh(personFound) - - assertTrue(personToSave == personFound) - }) - } - - @Test - fun givenPersonWithNullFields_whenSaved_thenFound() { - doInHibernate(({ this.sessionFactory() }), { session -> - val personToSave = Person(0, "John", null, null) - session.persist(personToSave) - val personFound = session.find(Person::class.java, personToSave.id) - session.refresh(personFound) - - assertTrue(personToSave == personFound) - }) - } -} \ No newline at end of file diff --git a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/mockmvc/MockMvcControllerTest.kt b/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/mockmvc/MockMvcControllerTest.kt deleted file mode 100644 index 802cd4c1e7..0000000000 --- a/spring-mvc-kotlin/src/test/kotlin/com/baeldung/kotlin/mockmvc/MockMvcControllerTest.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.kotlin.mockmvc - -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.Test -import org.junit.runner.RunWith -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity.status -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.post -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders -import org.springframework.test.web.servlet.result.MockMvcResultHandlers -import org.springframework.test.web.servlet.result.MockMvcResultMatchers - -@RunWith(SpringRunner::class) -@WebMvcTest -class MockMvcControllerTest { - - @Autowired lateinit var mockMvc: MockMvc - @Autowired lateinit var mapper: ObjectMapper - - @Test - fun `when supported user is given then raw MockMvc-based validation is successful`() { - mockMvc.perform(MockMvcRequestBuilders - .post("/mockmvc/validate") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(Request(Name("admin", ""))))) - .andExpect(MockMvcResultMatchers.status().isOk) - .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.content().string("{}")) - } - - @Test - fun `when supported user is given then kotlin DSL-based validation is successful`() { - doTest(Request(Name("admin", "")), Response(null)) - } - - @Test - fun `when unsupported user is given then validation is failed`() { - doTest(Request(Name("some-name", "some-surname")), Response(MockMvcController.ERROR)) - } - - private fun doTest(input: Request, expectation: Response) { - mockMvc.post("/mockmvc/validate") { - contentType = MediaType.APPLICATION_JSON - content = mapper.writeValueAsString(input) - accept = MediaType.APPLICATION_JSON - }.andExpect { - status { isOk } - content { contentType(MediaType.APPLICATION_JSON) } - content { json(mapper.writeValueAsString(expectation)) } - } - } -} - -@SpringBootApplication -class MockMvcApplication \ No newline at end of file diff --git a/spring-mvc-kotlin/src/test/resources/hibernate.properties b/spring-mvc-kotlin/src/test/resources/hibernate.properties deleted file mode 100644 index 7b8764637b..0000000000 --- a/spring-mvc-kotlin/src/test/resources/hibernate.properties +++ /dev/null @@ -1,9 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.connection.autocommit=true -jdbc.password= - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/spring-reactive-kotlin/README.md b/spring-reactive-kotlin/README.md deleted file mode 100644 index d6ce3b7645..0000000000 --- a/spring-reactive-kotlin/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Spring Reactive Kotlin - -This module contains articles about reactive Kotlin - -### Relevant Articles: -- [Spring Webflux with Kotlin](https://www.baeldung.com/spring-webflux-kotlin) -- [Kotlin Reactive Microservice With Spring Boot](https://www.baeldung.com/spring-boot-kotlin-reactive-microservice) diff --git a/spring-reactive-kotlin/pom.xml b/spring-reactive-kotlin/pom.xml deleted file mode 100644 index cbb143f6ec..0000000000 --- a/spring-reactive-kotlin/pom.xml +++ /dev/null @@ -1,145 +0,0 @@ - - - 4.0.0 - spring-reactive-kotlin - spring-reactive-kotlin - Demo project for Spring Boot - - jar - - - com.baeldung - parent-kotlin - 1.0.0-SNAPSHOT - ../parent-kotlin - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.boot.experimental - spring-boot-starter-data-r2dbc - - - org.springframework.boot - spring-boot-starter-actuator - - - io.r2dbc - r2dbc-h2 - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - - org.springframework.boot - spring-boot-starter-test - test - - - io.projectreactor - reactor-test - test - - - - org.springframework.boot.experimental - spring-boot-test-autoconfigure-r2dbc - test - - - io.projectreactor - reactor-test - test - - - - - - - - org.springframework.boot.experimental - spring-boot-bom-r2dbc - 0.1.0.M3 - pom - import - - - - - - src/main/kotlin - src/test/kotlin - - - kotlin-maven-plugin - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - org.jetbrains.kotlin - ${kotlin.version} - - - -Xjsr305=strict - - 1.8 - - spring - jpa - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-maven-noarg - ${kotlin.version} - - - - - - - - 1.8 - 1.3.70 - 2.2.5.RELEASE - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - - diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt deleted file mode 100644 index c70057b5de..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.bootmicroservice - -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.runApplication - -@SpringBootApplication -class HealthTrackerApplication - -fun main(args: Array) { - runApplication(*args) -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt deleted file mode 100644 index b14682cc5c..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.bootmicroservice.config; - -import org.springframework.context.annotation.Configuration -import org.springframework.data.r2dbc.core.DatabaseClient - -@Configuration -class DBConfiguration(db: DatabaseClient) { - init { - val initDb = db.execute { - """ CREATE TABLE IF NOT EXISTS profile ( - id SERIAL PRIMARY KEY, - first_name VARCHAR(20) NOT NULL, - last_name VARCHAR(20) NOT NULL, - birth_date DATE NOT NULL - ); - CREATE TABLE IF NOT EXISTS health_record( - id SERIAL PRIMARY KEY, - profile_id LONG NOT NULL, - temperature DECIMAL NOT NULL, - blood_pressure DECIMAL NOT NULL, - heart_rate DECIMAL, - date DATE NOT NULL - ); - """ - } - initDb.then().subscribe() - } -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt deleted file mode 100644 index 620f187b7b..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.bootmicroservice.controller - -import com.baeldung.bootmicroservice.model.AverageHealthStatus -import com.baeldung.bootmicroservice.model.HealthRecord -import com.baeldung.bootmicroservice.repository.HealthRecordRepository -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController -import reactor.core.publisher.Mono - -@RestController -class HealthRecordController(val repository: HealthRecordRepository) { - - @PostMapping("/health/{profileId}/record") - fun storeHealthRecord(@PathVariable("profileId") profileId: Long, @RequestBody record: HealthRecord): Mono = - repository.save(HealthRecord(null - , profileId - , record.temperature - , record.bloodPressure - , record.heartRate - , record.date)) - - @GetMapping("/health/{profileId}/avg") - fun fetchHealthRecordAverage(@PathVariable("profileId") profileId: Long): Mono = - repository.findByProfileId(profileId) - .reduce( - AverageHealthStatus(0, 0.0, 0.0, 0.0) - , { s, r -> - AverageHealthStatus(s.cnt + 1 - , s.temperature + r.temperature - , s.bloodPressure + r.bloodPressure - , s.heartRate + r.heartRate - ) - } - ).map { s -> - AverageHealthStatus(s.cnt - , if (s.cnt != 0) s.temperature / s.cnt else 0.0 - , if (s.cnt != 0) s.bloodPressure / s.cnt else 0.0 - , if (s.cnt != 0) s.heartRate / s.cnt else 0.0) - } - -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt deleted file mode 100644 index 1dc3bcdc50..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.bootmicroservice.controller - -import com.baeldung.bootmicroservice.model.Profile -import com.baeldung.bootmicroservice.repository.ProfileRepository -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController -import reactor.core.publisher.Mono - -@RestController -class ProfileController(val repository: ProfileRepository) { - - @PostMapping("/profile") - fun save(@RequestBody profile: Profile): Mono = repository.save(profile) -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt deleted file mode 100644 index 3141146b9c..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.bootmicroservice.model; - -class AverageHealthStatus(var cnt: Int, var temperature: Double, var bloodPressure: Double, var heartRate: Double) diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt deleted file mode 100644 index 71c534027f..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.bootmicroservice.model - -import org.springframework.data.annotation.Id -import org.springframework.data.relational.core.mapping.Table -import java.time.LocalDate - -@Table -data class HealthRecord(@Id var id: Long?, var profileId: Long?, var temperature: Double, var bloodPressure: Double, var heartRate: Double, var date: LocalDate) \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt deleted file mode 100644 index cbb7e675ea..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.bootmicroservice.model - -import org.springframework.data.annotation.Id -import org.springframework.data.relational.core.mapping.Table -import java.time.LocalDateTime - -@Table -data class Profile(@Id var id:Long?, var firstName : String, var lastName : String, var birthDate: LocalDateTime) \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt deleted file mode 100644 index 8cc91f06e4..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.bootmicroservice.repository - -import com.baeldung.bootmicroservice.model.HealthRecord -import org.springframework.data.r2dbc.repository.Query -import org.springframework.data.repository.reactive.ReactiveCrudRepository -import org.springframework.stereotype.Repository -import reactor.core.publisher.Flux - -@Repository -interface HealthRecordRepository: ReactiveCrudRepository { - @Query("select p.* from health_record p where p.profile_id = :profileId ") - fun findByProfileId(profileId: Long): Flux -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt deleted file mode 100644 index eee8c5fcbe..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.bootmicroservice.repository - -import com.baeldung.bootmicroservice.model.Profile -import org.springframework.data.repository.reactive.ReactiveCrudRepository -import org.springframework.stereotype.Repository - -@Repository -interface ProfileRepository: ReactiveCrudRepository \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Application.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Application.kt deleted file mode 100644 index 87ac7417b7..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Application.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.springreactivekotlin - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication - -@SpringBootApplication -class Application - -fun main(args: Array) { - SpringApplication.run(Application::class.java, *args) -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Controller.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Controller.kt deleted file mode 100644 index 76f8a62b85..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Controller.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.springreactivekotlin - -import org.springframework.http.MediaType -import org.springframework.stereotype.Controller -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.ResponseBody -import reactor.core.publisher.Flux - -@Controller -class Controller { - - @GetMapping(path = ["/numbers"], produces = [MediaType.APPLICATION_STREAM_JSON_VALUE]) - @ResponseBody - fun getNumbers(): Flux { - return Flux.range(1, 100) - } - -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Device.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Device.kt deleted file mode 100644 index 9eb6eb8488..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Device.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.springreactivekotlin - -class Device(val name: String, val reading: Double) { - -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsHandler.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsHandler.kt deleted file mode 100644 index 0ef9f37f1b..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsHandler.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.springreactivekotlin - -import org.springframework.stereotype.Component -import org.springframework.web.reactive.function.BodyInserters.fromObject -import org.springframework.web.reactive.function.server.ServerRequest -import org.springframework.web.reactive.function.server.ServerResponse -import reactor.core.publisher.Mono - -@Component -class HomeSensorsHandler { - - var data = mapOf("lamp" to arrayOf(0.7, 0.65, 0.67), "fridge" to arrayOf(12.0, 11.9, 12.5)) - - fun setLight(request: ServerRequest): Mono = ServerResponse.ok().build() - - fun getLightReading(request: ServerRequest): Mono = - ServerResponse.ok().body(fromObject(data["lamp"]!!)) - - fun getDeviceReadings(request: ServerRequest): Mono { - val id = request.pathVariable("id") - return ServerResponse.ok().body(fromObject(Device(id, 1.0))) - } - - fun getAllDevices(request: ServerRequest): Mono = - ServerResponse.ok().body(fromObject(arrayOf("lamp", "tv"))) - - fun getAllDeviceApi(request: ServerRequest): Mono = - ServerResponse.ok().body(fromObject(arrayListOf("kettle", "fridge"))) - - fun setDeviceReadingApi(request: ServerRequest): Mono { - return request.bodyToMono(Device::class.java).flatMap { it -> - ServerResponse.ok().body(fromObject(Device(it.name.toUpperCase(), it.reading))) - } - } - -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsRouters.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsRouters.kt deleted file mode 100644 index 27d87afd89..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/HomeSensorsRouters.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.springreactivekotlin - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.http.MediaType.APPLICATION_JSON -import org.springframework.http.MediaType.TEXT_HTML -import org.springframework.web.reactive.function.server.router - -@Configuration -class HomeSensorsRouters(private val handler: HomeSensorsHandler) { - - @Bean - fun roomsRouter() = router { - (accept(TEXT_HTML) and "/room").nest { - GET("/light", handler::getLightReading) - POST("/light", handler::setLight) - } - } - - @Bean - fun deviceRouter() = router { - accept(TEXT_HTML).nest { - (GET("/device/") or GET("/devices/")).invoke(handler::getAllDevices) - GET("/device/{id}", handler::getDeviceReadings) - } - (accept(APPLICATION_JSON) and "/api").nest { - (GET("/device/") or GET("/devices/")).invoke(handler::getAllDeviceApi) - POST("/device/", handler::setDeviceReadingApi) - } - } - -} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Routes.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Routes.kt deleted file mode 100644 index 9015fc5df8..0000000000 --- a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/springreactivekotlin/Routes.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.springreactivekotlin - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.reactive.function.server.ServerResponse -import org.springframework.web.reactive.function.server.router - -import org.springframework.web.reactive.function.BodyInserters.fromObject - -@Configuration -class SimpleRoute { - @Bean - fun route() = router { - GET("/route") { _ -> ServerResponse.ok().body(fromObject(arrayOf(1, 2, 3))) } - } -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/resources/application.yml b/spring-reactive-kotlin/src/main/resources/application.yml deleted file mode 100644 index d75683f905..0000000000 --- a/spring-reactive-kotlin/src/main/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ -management.endpoints.web.exposure.include: health,metrics \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/resources/logback.xml b/spring-reactive-kotlin/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-reactive-kotlin/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/spring-reactive-kotlin/src/test/kotlin/RoutesTest.kt b/spring-reactive-kotlin/src/test/kotlin/RoutesTest.kt deleted file mode 100644 index ba640070e3..0000000000 --- a/spring-reactive-kotlin/src/test/kotlin/RoutesTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -package veontomo - -import com.baeldung.springreactivekotlin.SimpleRoute -import org.junit.Before -import org.junit.Test -import org.springframework.test.web.reactive.server.WebTestClient - -class RoutesTest { - - lateinit var client: WebTestClient - - @Before - fun init() { - this.client = WebTestClient.bindToRouterFunction(SimpleRoute().route()).build() - } - - - @Test - fun whenRequestToRoute_thenStatusShouldBeOk() { - client.get() - .uri("/route") - .exchange() - .expectStatus().isOk - } - - - @Test - fun whenRequestToRoute_thenBodyShouldContainArray123() { - client.get() - .uri("/route") - .exchange() - .expectBody() - .json("[1, 2, 3]") - } -} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt b/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt deleted file mode 100644 index 51481af3d7..0000000000 --- a/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.bootmicroservice.controller; - -import com.baeldung.bootmicroservice.model.Profile -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.MediaType -import org.springframework.test.web.reactive.server.WebTestClient -import java.time.LocalDateTime - -@SpringBootTest -class ProfileControllerTest { - @Autowired - lateinit var controller: ProfileController - - @Autowired - lateinit var mapper: ObjectMapper ; - - lateinit var client: WebTestClient - lateinit var profile: String - - @BeforeEach - fun setup() { - client = WebTestClient.bindToController(controller).build() - profile = mapper.writeValueAsString(Profile(null, "kotlin", "reactive", LocalDateTime.now())) - } - - @Test - fun whenRequestProfile_thenStatusShouldBeOk() { - client.post() - .uri("/profile") - .contentType(MediaType.APPLICATION_JSON) - .bodyValue(profile) - .exchange() - .expectStatus().isOk - } - - @Test - fun whenRequestProfile_thenIdShouldBeNotNull() { - client.post() - .uri("/profile") - .contentType(MediaType.APPLICATION_JSON) - .bodyValue(profile) - .exchange() - .expectBody() - .jsonPath("$.id") - .isNotEmpty - } -} From 2a1baae5991ffa9d240acd4257be5f8604384e4e Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 23 Nov 2020 20:10:17 +0530 Subject: [PATCH 230/590] BAEL-4686:Allow Null test --- .../concurrenthashmap/NullAllowInMapTest.java | 27 +++++++++++++++++++ ...formanceTest.java => PerformanceTest.java} | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java rename core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/{ConcurrentHashMapVsSynchronizedMapPerformanceTest.java => PerformanceTest.java} (99%) diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java new file mode 100644 index 0000000000..23c76e59e8 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java @@ -0,0 +1,27 @@ +package com.baeldung.map.concurrenthashmap; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.Assert; +import org.junit.Test; + +public class NullAllowInMapTest { + + @Test + public void allowOnlyNull_In_SynchronizedMap() { + Map map = Collections + .synchronizedMap(new HashMap()); + map.put(null, 1); + Assert.assertTrue(map.get(null).equals(1)); + } + + @Test(expected = NullPointerException.class) + public void allowOnlyNull_In_ConcurrentHasMap() { + Map map = new ConcurrentHashMap<>(); + map.put(null, 1); + } + +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java similarity index 99% rename from core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java rename to core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java index 573087d5a5..5321d33b36 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentHashMapVsSynchronizedMapPerformanceTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; -public class ConcurrentHashMapVsSynchronizedMapPerformanceTest { +public class PerformanceTest { public final static int THREAD_POOL_SIZE = 5; public final static int TEST_ITERATIONS = 5; From c61ed5f8b02b25cd4a86c6bd586c4c2b79a9b7ac Mon Sep 17 00:00:00 2001 From: ashleyfrieze Date: Mon, 23 Nov 2020 18:13:16 +0000 Subject: [PATCH 231/590] BAEL-4560 Add various patterns for adding iteration counter to loops/streams (#10266) * Add various patterns for adding iteration counter to loops/streams * Add various patterns for adding iteration counter to loops/streams --- .../iterationcounter/IterationCounter.java | 68 +++++++++++++++++++ .../IterationCounterUnitTest.java | 36 ++++++++++ 2 files changed, 104 insertions(+) create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java new file mode 100644 index 0000000000..40d997cb0e --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java @@ -0,0 +1,68 @@ +package com.baeldung.iterationcounter; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.stream.Stream; + +public class IterationCounter { + public static final List IMDB_TOP_MOVIES = Arrays.asList("The Shawshank Redemption", + "The Godfather", "The Godfather II", "The Dark Knight"); + + public static List getRankingsWithForLoop(List movies) { + List rankings = new ArrayList<>(); + for (int i = 0; i < movies.size(); i++) { + String ranking = (i + 1) + ": " + movies.get(i); + rankings.add(ranking); + } + return rankings; + } + + public static List getRankingsWithForEachLoop(List movies) { + List rankings = new ArrayList<>(); + int i = 0; + for (String movie : movies) { + String ranking = (i + 1) + ": " + movies.get(i); + rankings.add(ranking); + + i++; + } + return rankings; + } + + public static List getRankingsWithFunctionalForEachLoop(List movies) { + List rankings = new ArrayList<>(); + forEachWithCounter(movies, (i, movie) -> { + String ranking = (i + 1) + ": " + movie; + rankings.add(ranking); + }); + + return rankings; + } + + public static void forEachWithCounter(Iterable source, BiConsumer consumer) { + int i = 0; + for (T item : source) { + consumer.accept(i, item); + i++; + } + } + + public static List getRankingsWithStream(Stream movies) { + List rankings = new ArrayList<>(); + movies.forEach(withCounter((i, movie) -> { + String ranking = (i + 1) + ": " + movie; + rankings.add(ranking); + })); + + return rankings; + } + + public static Consumer withCounter(BiConsumer consumer) { + AtomicInteger counter = new AtomicInteger(0); + return item -> consumer.accept(counter.getAndIncrement(), item); + } +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java new file mode 100644 index 0000000000..6746e570ca --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.iterationcounter; + +import org.junit.Test; + +import static com.baeldung.iterationcounter.IterationCounter.*; +import static org.assertj.core.api.Assertions.*; + +public class IterationCounterUnitTest { + @Test + public void givenRankings_whenCalculateWithForLoop_thenRankingsCorrect() { + assertThat(getRankingsWithForLoop(IMDB_TOP_MOVIES)) + .containsExactly("1: The Shawshank Redemption", + "2: The Godfather", "3: The Godfather II", "4: The Dark Knight"); + } + + @Test + public void givenRankings_whenCalculateWithForEachLoop_thenRankingsCorrect() { + assertThat(getRankingsWithForEachLoop(IMDB_TOP_MOVIES)) + .containsExactly("1: The Shawshank Redemption", + "2: The Godfather", "3: The Godfather II", "4: The Dark Knight"); + } + + @Test + public void givenRankings_whenCalculateWithFunctionalForEach_thenRankingsCorrect() { + assertThat(getRankingsWithFunctionalForEachLoop(IMDB_TOP_MOVIES)) + .containsExactly("1: The Shawshank Redemption", + "2: The Godfather", "3: The Godfather II", "4: The Dark Knight"); + } + + @Test + public void givenRankings_whenCalculateWithStream_thenRankingsCorrect() { + assertThat(getRankingsWithStream(IMDB_TOP_MOVIES.stream())) + .containsExactly("1: The Shawshank Redemption", + "2: The Godfather", "3: The Godfather II", "4: The Dark Knight"); + } +} From 1d90857c7dbe2eb1599f231b37bb2e11f652e626 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Nov 2020 02:43:41 +0800 Subject: [PATCH 232/590] Update README.md --- spring-security-modules/spring-security-oidc/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-security-modules/spring-security-oidc/README.md b/spring-security-modules/spring-security-oidc/README.md index 6a45824fcb..92ba60cad9 100644 --- a/spring-security-modules/spring-security-oidc/README.md +++ b/spring-security-modules/spring-security-oidc/README.md @@ -4,7 +4,6 @@ This module contains articles about OpenID with Spring Security ### Relevant articles -- [Spring Security and OpenID Connect (Legacy)](https://www.baeldung.com/spring-security-openid-connect-legacy) - [Spring Security and OpenID Connect](https://www.baeldung.com/spring-security-openid-connect) ### OpenID Connect with Spring Security From 57f16ccd0cb5b960ba506ed9aeb4126c77e39b3d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Nov 2020 03:01:37 +0800 Subject: [PATCH 233/590] Update README.md --- spring-resttemplate-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-resttemplate-2/README.md b/spring-resttemplate-2/README.md index 37d8ac9740..aab6a188b6 100644 --- a/spring-resttemplate-2/README.md +++ b/spring-resttemplate-2/README.md @@ -8,4 +8,4 @@ This module contains articles about Spring RestTemplate - [Proxies With RestTemplate](https://www.baeldung.com/java-resttemplate-proxy) - [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type) - [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) -- [How to compress requests using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) +- [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) From 319e3b752c244bcb176bc62e3d1a70cd7ddf7536 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Nov 2020 03:07:59 +0800 Subject: [PATCH 234/590] Update README.md --- jackson-modules/jackson/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/jackson-modules/jackson/README.md b/jackson-modules/jackson/README.md index bcf8c3036f..50e13a5b75 100644 --- a/jackson-modules/jackson/README.md +++ b/jackson-modules/jackson/README.md @@ -10,6 +10,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Using Optional with Jackson](https://www.baeldung.com/jackson-optional) - [Compare Two JSON Objects with Jackson](https://www.baeldung.com/jackson-compare-two-json-objects) - [Jackson vs Gson](https://www.baeldung.com/jackson-vs-gson) -- [Jackson JSON Tutorial](https://www.baeldung.com/jackson) - [Inheritance with Jackson](https://www.baeldung.com/jackson-inheritance) - [Working with Tree Model Nodes in Jackson](https://www.baeldung.com/jackson-json-node-tree-model) From 82af24010b6ba60ac2c8e7510ba60b367cd6e844 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Nov 2020 17:05:49 +0800 Subject: [PATCH 235/590] Update README.md --- core-java-modules/core-java-string-apis/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-apis/README.md b/core-java-modules/core-java-string-apis/README.md index fc36ba8640..c9aa40de7a 100644 --- a/core-java-modules/core-java-string-apis/README.md +++ b/core-java-modules/core-java-string-apis/README.md @@ -8,5 +8,5 @@ This module contains articles about string APIs. - [Guide to java.util.Formatter](https://www.baeldung.com/java-string-formatter) - [Guide to StreamTokenizer](https://www.baeldung.com/java-streamtokenizer) - [CharSequence vs. String in Java](https://www.baeldung.com/java-char-sequence-string) -- [StringBuilder and StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer) +- [StringBuilder vs StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer) - [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password) From bd5891852ce5950c797997d4ec1c865276ac4fcd Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 24 Nov 2020 14:32:14 +0200 Subject: [PATCH 236/590] remove kotlin project from pom --- spring-boot-modules/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 622a5c0f42..44b3e28291 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -49,7 +49,6 @@ spring-boot-libraries spring-boot-libraries-2 spring-boot-logging-log4j2 - spring-boot-kotlin spring-boot-mvc spring-boot-mvc-2 spring-boot-mvc-3 From d3ee95024fee76ee4dae694f1b82b0add2f520c5 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 24 Nov 2020 17:13:44 +0200 Subject: [PATCH 237/590] fix unstable tests in libraries-http-2 --- libraries-http-2/pom.xml | 1 - .../src/main/resources/logback.xml | 13 +++++++ .../jetty/httpclient/AbstractUnitTest.java | 34 +++++------------ .../httpclient/ProjectReactorUnitTest.java | 32 +++++++++++++--- .../httpclient/ReactiveStreamsUnitTest.java | 31 +++++++++++++--- .../jetty/httpclient/RxJava2UnitTest.java | 37 +++++++++++++++---- .../httpclient/SpringWebFluxUnitTest.java | 36 +++++++++++++----- 7 files changed, 131 insertions(+), 53 deletions(-) create mode 100644 libraries-http-2/src/main/resources/logback.xml diff --git a/libraries-http-2/pom.xml b/libraries-http-2/pom.xml index 96f9e2911d..d0bdb26bd4 100644 --- a/libraries-http-2/pom.xml +++ b/libraries-http-2/pom.xml @@ -84,7 +84,6 @@ 3.14.2 2.8.5 3.14.2 - 1.0.3 9.4.19.v20190610 2.2.11 diff --git a/libraries-http-2/src/main/resources/logback.xml b/libraries-http-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/libraries-http-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java index 4a3e67a7c5..876586032a 100644 --- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java +++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java @@ -3,23 +3,16 @@ package com.baeldung.jetty.httpclient; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; public abstract class AbstractUnitTest { - protected HttpClient httpClient; - protected Server server; + protected static HttpClient httpClient; + protected static Server server; protected static final String CONTENT = "Hello World!"; - protected final int port = 9080; - - @Before - public void init() { - startServer(new RequestHandler()); - startClient(); - } - private void startClient() { + protected static void startClient() { httpClient = new HttpClient(); try { httpClient.start(); @@ -28,7 +21,7 @@ public abstract class AbstractUnitTest { } } - private void startServer(Handler handler) { + protected static void startServer(Handler handler, int port) { server = new Server(port); server.setHandler(handler); try { @@ -37,18 +30,9 @@ public abstract class AbstractUnitTest { e.printStackTrace(); } } - - @After - public void dispose() throws Exception { - if (httpClient != null) { - httpClient.stop(); - } - if (server != null) { - server.stop(); - } - } - - protected String uri() { + + protected String uri(int port) { return "http://localhost:" + port; } + } \ No newline at end of file diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java index 6d79773609..db27ea1c89 100644 --- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java +++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java @@ -4,18 +4,29 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.reactive.client.ReactiveRequest; import org.eclipse.jetty.reactive.client.ReactiveResponse; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; public class ProjectReactorUnitTest extends AbstractUnitTest { + protected static int port = 9080; + + @BeforeAll + public static void init() { + startServer(new RequestHandler(), port); + startClient(); + } + @Test public void givenReactiveClient_whenRequested_shouldReturn200() throws Exception { - Request request = httpClient.newRequest(uri()); + Request request = httpClient.newRequest(uri(port)); ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request) .build(); Publisher publisher = reactiveRequest.response(); @@ -23,8 +34,19 @@ public class ProjectReactorUnitTest extends AbstractUnitTest { ReactiveResponse response = Mono.from(publisher) .block(); - Assert.assertNotNull(response); - Assert.assertEquals(response.getStatus(), HttpStatus.OK_200); + assertNotNull(response); + assertEquals(response.getStatus(), HttpStatus.OK_200); } + + @AfterAll + public static void dispose() throws Exception { + if (httpClient != null) { + httpClient.stop(); + } + if (server != null) { + server.stop(); + } + } + } diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java index 3db4553c86..494d65e9e1 100644 --- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java +++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java @@ -4,16 +4,27 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.reactive.client.ReactiveRequest; import org.eclipse.jetty.reactive.client.ReactiveResponse; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; public class ReactiveStreamsUnitTest extends AbstractUnitTest { + + protected static int port = 9081; + + @BeforeAll + public static void init() { + startServer(new RequestHandler(), port); + startClient(); + } @Test public void givenReactiveClient_whenRequested_shouldReturn200() throws Exception { - Request request = httpClient.newRequest(uri()); + Request request = httpClient.newRequest(uri(port)); ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request) .build(); Publisher publisher = reactiveRequest.response(); @@ -21,8 +32,18 @@ public class ReactiveStreamsUnitTest extends AbstractUnitTest { BlockingSubscriber subscriber = new BlockingSubscriber(); publisher.subscribe(subscriber); ReactiveResponse response = subscriber.block(); - Assert.assertNotNull(response); - Assert.assertEquals(response.getStatus(), HttpStatus.OK_200); + assertNotNull(response); + assertEquals(response.getStatus(), HttpStatus.OK_200); + } + + @AfterAll + public static void dispose() throws Exception { + if (httpClient != null) { + httpClient.stop(); + } + if (server != null) { + server.stop(); + } } } diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java index dabd768702..a819eec475 100644 --- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java +++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java @@ -10,8 +10,11 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.reactive.client.ReactiveRequest; import org.eclipse.jetty.reactive.client.ReactiveRequest.Event.Type; import org.eclipse.jetty.reactive.client.ReactiveResponse; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import org.springframework.http.MediaType; @@ -19,11 +22,19 @@ import io.reactivex.Flowable; import io.reactivex.Single; public class RxJava2UnitTest extends AbstractUnitTest { + + protected static int port = 9082; + + @BeforeAll + public static void init() { + startServer(new RequestHandler(), port); + startClient(); + } @Test public void givenReactiveClient_whenRequestedWithBody_ShouldReturnBody() throws Exception { - Request request = httpClient.newRequest(uri()); + Request request = httpClient.newRequest(uri(port)); ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request) .content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8)) .build(); @@ -32,12 +43,12 @@ public class RxJava2UnitTest extends AbstractUnitTest { String responseContent = Single.fromPublisher(publisher) .blockingGet(); - Assert.assertEquals(CONTENT, responseContent); + assertEquals(CONTENT, responseContent); } @Test public void givenReactiveClient_whenRequested_ShouldPrintEvents() throws Exception { - ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri()) + ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri(port)) .content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8)) .build(); Publisher requestEvents = request.requestEvents(); @@ -58,10 +69,20 @@ public class RxJava2UnitTest extends AbstractUnitTest { int actualStatus = response.blockingGet() .getStatus(); - Assert.assertEquals(6, requestEventTypes.size()); - Assert.assertEquals(5, responseEventTypes.size()); + assertEquals(6, requestEventTypes.size()); + assertEquals(5, responseEventTypes.size()); - Assert.assertEquals(actualStatus, HttpStatus.OK_200); + assertEquals(actualStatus, HttpStatus.OK_200); + } + + @AfterAll + public static void dispose() throws Exception { + if (httpClient != null) { + httpClient.stop(); + } + if (server != null) { + server.stop(); + } } } \ No newline at end of file diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java index 4a1a9bb2b5..f14fc38e1d 100644 --- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java +++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java @@ -1,8 +1,11 @@ package com.baeldung.jetty.httpclient; import org.eclipse.jetty.client.HttpClient; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.JettyClientHttpConnector; @@ -12,25 +15,40 @@ import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; public class SpringWebFluxUnitTest extends AbstractUnitTest { - + + protected static int port = 9083; + + @BeforeAll + public static void init() { + startServer(new RequestHandler(), port); + startClient(); + } + @Test public void givenReactiveClient_whenRequested_shouldReturnResponse() throws Exception { - - HttpClient httpClient = new HttpClient(); - httpClient.start(); ClientHttpConnector clientConnector = new JettyClientHttpConnector(httpClient); WebClient client = WebClient.builder() .clientConnector(clientConnector) .build(); String responseContent = client.post() - .uri(uri()) + .uri(uri(port)) .contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromPublisher(Mono.just(CONTENT), String.class)) .retrieve() .bodyToMono(String.class) .block(); - Assert.assertNotNull(responseContent); - Assert.assertEquals(CONTENT, responseContent); + assertNotNull(responseContent); + assertEquals(CONTENT, responseContent); + } + + @AfterAll + public static void dispose() throws Exception { + if (httpClient != null) { + httpClient.stop(); + } + if (server != null) { + server.stop(); + } } } \ No newline at end of file From 3c01b8f9f85b8be732a1faa955dcab3eb2bf6333 Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Tue, 24 Nov 2020 23:38:20 +0000 Subject: [PATCH 238/590] BAEL-4742 System Stubs example tests --- testing-modules/testing-libraries-2/pom.xml | 8 +- .../FakeDatabaseJUnit5UnitTest.java | 16 +++ .../systemstubs/FakeDatabaseTestResource.java | 22 ++++ .../FakeDatabaseTestResourceUnitTest.java | 21 ++++ ...gStartedWithSystemStubsJUnit4UnitTest.java | 58 ++++++++++ ...GettingStartedWithSystemStubsUnitTest.java | 109 ++++++++++++++++++ .../JUnit4SystemPropertiesUnitTest.java | 42 +++++++ .../JUnit5SystemPropertiesUnitTest.java | 89 ++++++++++++++ .../OutputMutingJUnit4UnitTest.java | 16 +++ .../systemstubs/OutputMutingUnitTest.java | 35 ++++++ .../SystemExitExecuteAroundUnitTest.java | 17 +++ .../systemstubs/SystemExitJUnit4UnitTest.java | 29 +++++ .../systemstubs/SystemExitJUnit5UnitTest.java | 26 +++++ .../SystemInExecuteAroundUnitTest.java | 20 ++++ .../systemstubs/SystemInJUnit4UnitTest.java | 21 ++++ .../systemstubs/SystemInJUnit5UnitTest.java | 23 ++++ .../SystemOutAndErrExecuteAroundUnitTest.java | 43 +++++++ .../systemstubs/SystemOutJUnit4UnitTest.java | 52 +++++++++ .../systemstubs/SystemOutJUnit5UnitTest.java | 28 +++++ ...SystemPropertiesExecuteAroundUnitTest.java | 31 +++++ .../WithMockedInputStreamUnitTest.java | 18 +++ 21 files changed, 723 insertions(+), 1 deletion(-) create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseJUnit5UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResource.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResourceUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsJUnit4UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit4SystemPropertiesUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit5SystemPropertiesUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingJUnit4UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitExecuteAroundUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit4UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit5UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInExecuteAroundUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit4UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit5UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutAndErrExecuteAroundUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit4UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit5UnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemPropertiesExecuteAroundUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/WithMockedInputStreamUnitTest.java diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index dd863af6ee..42c84d0da9 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -13,6 +13,12 @@ + + org.assertj + assertj-core + 3.16.1 + test + com.github.stefanbirkner system-rules @@ -78,7 +84,7 @@ 1.19.0 1.0.0 - 1.0.0 + 1.1.0 5.6.2 diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseJUnit5UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseJUnit5UnitTest.java new file mode 100644 index 0000000000..cb9371bd69 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseJUnit5UnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SystemStubsExtension.class) +class FakeDatabaseJUnit5UnitTest { + + @Test + void useFakeDatabase(FakeDatabaseTestResource fakeDatabase) { + assertThat(fakeDatabase.getDatabaseConnection()).isEqualTo("open"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResource.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResource.java new file mode 100644 index 0000000000..6cb1b1d607 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResource.java @@ -0,0 +1,22 @@ +package com.baeldung.systemstubs; + +import uk.org.webcompere.systemstubs.resource.TestResource; + +public class FakeDatabaseTestResource implements TestResource { + // let's pretend this is a database connection + private String databaseConnection = "closed"; + + @Override + public void setup() throws Exception { + databaseConnection = "open"; + } + + @Override + public void teardown() throws Exception { + databaseConnection = "closed"; + } + + public String getDatabaseConnection() { + return databaseConnection; + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResourceUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResourceUnitTest.java new file mode 100644 index 0000000000..6b8fdcecdd --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/FakeDatabaseTestResourceUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class FakeDatabaseTestResourceUnitTest { + @Nested + class ExecuteAround { + @Test + void theResourceIsClosedToStartWith() throws Exception { + FakeDatabaseTestResource fake = new FakeDatabaseTestResource(); + assertThat(fake.getDatabaseConnection()).isEqualTo("closed"); + + fake.execute(() -> { + assertThat(fake.getDatabaseConnection()).isEqualTo("open"); + }); + } + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsJUnit4UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsJUnit4UnitTest.java new file mode 100644 index 0000000000..6eaffac7ed --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsJUnit4UnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.systemstubs; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import uk.org.webcompere.systemstubs.rules.EnvironmentVariablesRule; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(Enclosed.class) +public class GettingStartedWithSystemStubsJUnit4UnitTest { + public static class SetEnvironmentInsideTest { + @Rule + public EnvironmentVariablesRule environmentVariablesRule = new EnvironmentVariablesRule(); + + @Test + public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + environmentVariablesRule.set("ENV", "value1"); + + assertThat(System.getenv("ENV")).isEqualTo("value1"); + } + } + + public static class SetEnvironmentAtConstruction { + @Rule + public EnvironmentVariablesRule environmentVariablesRule = + new EnvironmentVariablesRule("ENV", "value1", + "ENV2", "value2"); + + + @Test + public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + assertThat(System.getenv("ENV")).isEqualTo("value1"); + assertThat(System.getenv("ENV2")).isEqualTo("value2"); + } + } + + public static class SetEnvironmentInBefore { + @Rule + public EnvironmentVariablesRule environmentVariablesRule = + new EnvironmentVariablesRule(); + + @Before + public void before() { + environmentVariablesRule.set("ENV", "value1") + .set("ENV2", "value2"); + } + + + @Test + public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + assertThat(System.getenv("ENV")).isEqualTo("value1"); + assertThat(System.getenv("ENV2")).isEqualTo("value2"); + } + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsUnitTest.java new file mode 100644 index 0000000000..76fb768d34 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsUnitTest.java @@ -0,0 +1,109 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.properties.SystemProperties; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable; +import static uk.org.webcompere.systemstubs.resource.Resources.with; + +class GettingStartedWithSystemStubsUnitTest { + @Nested + @ExtendWith(SystemStubsExtension.class) + class EnvironmentVariablesJUnit5 { + @SystemStub + private EnvironmentVariables environmentVariables; + + @Test + void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + environmentVariables.set("ENV", "value1"); + + assertThat(System.getenv("ENV")).isEqualTo("value1"); + } + } + + @Nested + @ExtendWith(SystemStubsExtension.class) + class EnvironmentVariablesConstructedJUnit5 { + @SystemStub + private EnvironmentVariables environmentVariables = + new EnvironmentVariables("ENV", "value1"); + + @Test + void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + assertThat(System.getenv("ENV")).isEqualTo("value1"); + } + } + + @Nested + @ExtendWith(SystemStubsExtension.class) + class EnvironmentVariablesConstructedWithSetJUnit5 { + @SystemStub + private EnvironmentVariables environmentVariables = + new EnvironmentVariables() + .set("ENV", "value1") + .set("ENV2", "value2"); + + @Test + void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { + assertThat(System.getenv("ENV")).isEqualTo("value1"); + } + } + + @Nested + @ExtendWith(SystemStubsExtension.class) + class EnvironmentVariablesJUnit5ParameterInjection { + @Test + void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet(EnvironmentVariables environmentVariables) { + environmentVariables.set("ENV", "value1"); + + assertThat(System.getenv("ENV")).isEqualTo("value1"); + } + } + + @Nested + class EnvironmentVariablesExecuteAround { + @Test + void givenSetupUsingWithEnvironmentVariable_thenItIsSet() throws Exception { + withEnvironmentVariable("ENV3", "val") + .execute(() -> { + assertThat(System.getenv("ENV3")).isEqualTo("val"); + }); + } + + @Test + void givenSetupUsingConstructor_thenItIsSet() throws Exception { + EnvironmentVariables environment = new EnvironmentVariables() + .set("ENV3", "val"); + environment.execute(() -> { + assertThat(System.getenv("ENV3")).isEqualTo("val"); + }); + } + + @Test + void givenEnvironment_thenCanReturnValue() throws Exception { + String extracted = new EnvironmentVariables("PROXY", "none") + .execute(() -> System.getenv("PROXY")); + + assertThat(extracted).isEqualTo("none"); + } + } + + @Nested + class RunMultiple { + @Test + void runMultiple() throws Exception { + with(new EnvironmentVariables("FOO", "bar"), + new SystemProperties("prop", "val")) + .execute(() -> { + assertThat(System.getenv("FOO")).isEqualTo("bar"); + assertThat(System.getProperty("prop")).isEqualTo("val"); + }); + } + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit4SystemPropertiesUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit4SystemPropertiesUnitTest.java new file mode 100644 index 0000000000..111baf9e9c --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit4SystemPropertiesUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.systemstubs; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import uk.org.webcompere.systemstubs.rules.SystemPropertiesRule; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JUnit4SystemPropertiesUnitTest { + @Rule + public SystemPropertiesRule systemProperties = + new SystemPropertiesRule("db.connection", "false"); + + @Before + public void before() { + systemProperties.set("before.prop", "before"); + } + + @Test + public void givenPropertyIsSet_thenCanBeUsedInTest() { + assertThat(System.getProperty("db.connection")).isEqualTo("false"); + } + + @Test + public void givenPropertyIsSet_thenAnotherCanBeSetAndBeUsedInTest() { + assertThat(System.getProperty("db.connection")).isEqualTo("false"); + + systemProperties.set("prop2", "true"); + assertThat(System.getProperty("prop2")).isEqualTo("true"); + } + + @Test + public void givenPropertySetInBefore_thenCanBeSeenInTest() { + assertThat(System.getProperty("before.prop")).isEqualTo("before"); + } + + @Test + public void givenPropertySetEarlier_thenNotVisibleLater() { + assertThat(System.getProperty("prop2")).isNull(); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit5SystemPropertiesUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit5SystemPropertiesUnitTest.java new file mode 100644 index 0000000000..7aaf4cebad --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/JUnit5SystemPropertiesUnitTest.java @@ -0,0 +1,89 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.properties.SystemProperties; +import uk.org.webcompere.systemstubs.resource.PropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +class JUnit5SystemPropertiesUnitTest { + + @ExtendWith(SystemStubsExtension.class) + @Nested + class RestoreSystemProperties { + @SystemStub + private SystemProperties systemProperties; + + @Test + void givenAPropertyIsSet_thenItIsOnlyAvailableInsideThisTest1() { + assertThat(System.getProperty("localProperty")).isNull(); + + System.setProperty("localProperty", "nonnull"); + assertThat(System.getProperty("localProperty")).isEqualTo("nonnull"); + } + + @Test + void givenAPropertyIsSet_thenItIsOnlyAvailableInsideThisTest2() { + assertThat(System.getProperty("localProperty")).isNull(); + + System.setProperty("localProperty", "true"); + assertThat(System.getProperty("localProperty")).isEqualTo("true"); + } + } + + @ExtendWith(SystemStubsExtension.class) + @Nested + class RestoreSystemPropertiesByParameter { + + @Test + void givenAPropertyIsSet_thenItIsOnlyAvailableInsideThisTest1(SystemProperties systemProperties) { + assertThat(System.getProperty("localProperty")).isNull(); + + System.setProperty("localProperty", "nonnull"); + assertThat(System.getProperty("localProperty")).isEqualTo("nonnull"); + } + + @Test + void givenAPropertyIsSet_thenItIsOnlyAvailableInsideThisTest2(SystemProperties systemProperties) { + assertThat(System.getProperty("localProperty")).isNull(); + + System.setProperty("localProperty", "true"); + assertThat(System.getProperty("localProperty")).isEqualTo("true"); + } + } + + @ExtendWith(SystemStubsExtension.class) + @Nested + class SetSomeSystemProperties { + @SystemStub + private SystemProperties systemProperties; + + @BeforeEach + void before() { + systemProperties.set("beforeProperty", "before"); + } + + @Test + void givenAPropertyIsSetInBefore_thenItIsAvailableInsideThisTest() { + assertThat(System.getProperty("beforeProperty")).isEqualTo("before"); + } + } + + @ExtendWith(SystemStubsExtension.class) + @Nested + class SetSomeSystemPropertiesFromResources { + @SystemStub + private SystemProperties systemProperties = + new SystemProperties(PropertySource.fromResource("test.properties")); + + @Test + void givenPropertiesReadFromResources_thenCanBeUsed() { + assertThat(System.getProperty("name")).isEqualTo("baeldung"); + } + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingJUnit4UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingJUnit4UnitTest.java new file mode 100644 index 0000000000..a178efbb9d --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingJUnit4UnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.systemstubs; + +import org.junit.Rule; +import org.junit.Test; +import uk.org.webcompere.systemstubs.rules.SystemOutRule; +import uk.org.webcompere.systemstubs.stream.output.NoopStream; + +public class OutputMutingJUnit4UnitTest { + @Rule + public SystemOutRule systemOutRule = new SystemOutRule(new NoopStream()); + + @Test + public void givenMuteSystemOut() throws Exception { + System.out.println("nothing is output"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingUnitTest.java new file mode 100644 index 0000000000..c75a523fff --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/OutputMutingUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.stream.SystemOut; +import uk.org.webcompere.systemstubs.stream.output.NoopStream; + +import static uk.org.webcompere.systemstubs.SystemStubs.muteSystemOut; + +class OutputMutingUnitTest { + @Nested + class MutingWithFacade { + @Test + void givenMuteSystemOut() throws Exception { + muteSystemOut(() -> { + System.out.println("nothing is output"); + }); + } + } + + @ExtendWith(SystemStubsExtension.class) + @Nested + class MutingWithJUnit5 { + @SystemStub + private SystemOut systemOut = new SystemOut(new NoopStream()); + + @Test + void givenMuteSystemOut() throws Exception { + System.out.println("nothing is output"); + } + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitExecuteAroundUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitExecuteAroundUnitTest.java new file mode 100644 index 0000000000..b42cc43307 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitExecuteAroundUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; + + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.org.webcompere.systemstubs.SystemStubs.catchSystemExit; + +class SystemExitExecuteAroundUnitTest { + @Test + void canCheckExitCode() throws Exception { + int exitCode = catchSystemExit(() -> { + System.exit(123); + }); + assertThat(exitCode).isEqualTo(123); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit4UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit4UnitTest.java new file mode 100644 index 0000000000..c044e250dd --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit4UnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.systemstubs; + +import org.junit.Rule; +import org.junit.Test; +import uk.org.webcompere.systemstubs.rules.SystemExitRule; +import uk.org.webcompere.systemstubs.security.AbortExecutionException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class SystemExitJUnit4UnitTest { + @Rule + public SystemExitRule systemExitRule = new SystemExitRule(); + + @Test + public void whenAccidentalSystemExit_thenTestFailsRatherThanJVMKilled() { + // uncomment this to try it + //System.exit(1); + } + + @Test + public void whenExit_thenExitCodeIsAvailable() { + assertThatThrownBy(() -> { + System.exit(123); + }).isInstanceOf(AbortExecutionException.class); + + assertThat(systemExitRule.getExitCode()).isEqualTo(123); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit5UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit5UnitTest.java new file mode 100644 index 0000000000..4451d7e31f --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit5UnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.security.AbortExecutionException; +import uk.org.webcompere.systemstubs.security.SystemExit; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@ExtendWith(SystemStubsExtension.class) +class SystemExitJUnit5UnitTest { + @SystemStub + private SystemExit systemExit; + + @Test + void whenExit_thenExitCodeIsAvailable() { + assertThatThrownBy(() -> { + System.exit(123); + }).isInstanceOf(AbortExecutionException.class); + + assertThat(systemExit.getExitCode()).isEqualTo(123); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInExecuteAroundUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInExecuteAroundUnitTest.java new file mode 100644 index 0000000000..5a1d510e35 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInExecuteAroundUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; + +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.org.webcompere.systemstubs.SystemStubs.withTextFromSystemIn; + +class SystemInExecuteAroundUnitTest { + + @Test + void givenTextInSystemIn_thenCanReadIt() throws Exception { + withTextFromSystemIn("line1", "line2", "line3") + .execute(() -> { + assertThat(new Scanner(System.in).nextLine()) + .isEqualTo("line1"); + }); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit4UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit4UnitTest.java new file mode 100644 index 0000000000..ccd422ea24 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit4UnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.systemstubs; + +import org.junit.Rule; +import org.junit.Test; +import uk.org.webcompere.systemstubs.rules.SystemInRule; + +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SystemInJUnit4UnitTest { + @Rule + public SystemInRule systemInRule = + new SystemInRule("line1", "line2", "line3"); + + @Test + public void givenInput_canReadFirstLine() { + assertThat(new Scanner(System.in).nextLine()) + .isEqualTo("line1"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit5UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit5UnitTest.java new file mode 100644 index 0000000000..ed506eb40e --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemInJUnit5UnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.stream.SystemIn; + +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SystemStubsExtension.class) +class SystemInJUnit5UnitTest { + @SystemStub + private SystemIn systemIn = new SystemIn("line1", "line2", "line3"); + + @Test + void givenInput_canReadFirstLine() { + assertThat(new Scanner(System.in).nextLine()) + .isEqualTo("line1"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutAndErrExecuteAroundUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutAndErrExecuteAroundUnitTest.java new file mode 100644 index 0000000000..36b127d3cb --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutAndErrExecuteAroundUnitTest.java @@ -0,0 +1,43 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.properties.SystemProperties; +import uk.org.webcompere.systemstubs.stream.SystemOut; +import uk.org.webcompere.systemstubs.stream.output.DisallowWriteStream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static uk.org.webcompere.systemstubs.SystemStubs.tapSystemOutNormalized; +import static uk.org.webcompere.systemstubs.resource.Resources.with; + +class SystemOutAndErrExecuteAroundUnitTest { + @Test + void givenTapOutput_thenGetOutput() throws Exception { + String output = tapSystemOutNormalized(() -> { + System.out.println("a"); + System.out.println("b"); + }); + + assertThat(output).isEqualTo("a\nb\n"); + } + + @Test + void givenCaptureOutputWithSystemOut_thenGetOutput() throws Exception { + SystemOut systemOut = new SystemOut(); + SystemProperties systemProperties = new SystemProperties("a", "!"); + with(systemOut, systemProperties) + .execute(() -> { + System.out.println("a: " + System.getProperty("a")); + }); + + assertThat(systemOut.getLines()).containsExactly("a: !"); + } + + @Test + void givenCannotWrite_thenWritingIsError() { + assertThatThrownBy(() -> { + new SystemOut(new DisallowWriteStream()) + .execute(() -> System.out.println("boo")); + }).isInstanceOf(AssertionError.class); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit4UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit4UnitTest.java new file mode 100644 index 0000000000..d6ff70a49b --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit4UnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.systemstubs; + +import org.junit.Rule; +import org.junit.Test; +import uk.org.webcompere.systemstubs.rules.SystemErrRule; +import uk.org.webcompere.systemstubs.rules.SystemOutRule; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SystemOutJUnit4UnitTest { + @Rule + public SystemOutRule systemOutRule = new SystemOutRule(); + + @Rule + public SystemErrRule systemErrRule = new SystemErrRule(); + + @Test + public void whenCodeWritesToSystemOut_itCanBeRead() { + System.out.println("line1"); + System.out.println("line2"); + + assertThat(systemOutRule.getLines()) + .containsExactly("line1", "line2"); + } + + @Test + public void whenCodeWritesToSystemOut_itCanBeReadAsText() { + System.out.println("line1"); + System.out.println("line2"); + + assertThat(systemOutRule.getText()) + .startsWith("line1"); + } + + @Test + public void whenCodeWritesToSystemOut_itCanBeReadAsNormalizedLines() { + System.out.println("line1"); + System.out.println("line2"); + + assertThat(systemOutRule.getLinesNormalized()) + .isEqualTo("line1\nline2\n"); + } + + @Test + public void whenCodeWritesToSystemErr_itCanBeRead() { + System.err.println("line1"); + System.err.println("line2"); + + assertThat(systemErrRule.getLines()) + .containsExactly("line1", "line2"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit5UnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit5UnitTest.java new file mode 100644 index 0000000000..caa8a9264d --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemOutJUnit5UnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.stream.SystemErr; +import uk.org.webcompere.systemstubs.stream.SystemOut; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SystemStubsExtension.class) +class SystemOutJUnit5UnitTest { + @SystemStub + private SystemOut systemOut; + + @SystemStub + private SystemErr systemErr; + + @Test + void whenWriteToOutput_thenItCanBeAsserted() { + System.out.println("to out"); + System.err.println("to err"); + + assertThat(systemOut.getLines()).containsExactly("to out"); + assertThat(systemErr.getLines()).containsExactly("to err"); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemPropertiesExecuteAroundUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemPropertiesExecuteAroundUnitTest.java new file mode 100644 index 0000000000..3f0f780238 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemPropertiesExecuteAroundUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.properties.SystemProperties; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.org.webcompere.systemstubs.SystemStubs.restoreSystemProperties; + +class SystemPropertiesExecuteAroundUnitTest { + @Test + void givenRestoreSystemProperties_thenPropertyRestored() throws Exception { + restoreSystemProperties(() -> { + // test code + System.setProperty("unrestored", "true"); + }); + + assertThat(System.getProperty("unrestored")).isNull(); + } + + @Test + void givenSystemPropertiesObject_thenPropertyRestored() throws Exception { + String result = new SystemProperties() + .execute(() -> { + System.setProperty("unrestored", "true"); + return "it works"; + }); + + assertThat(result).isEqualTo("it works"); + assertThat(System.getProperty("unrestored")).isNull(); + } +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/WithMockedInputStreamUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/WithMockedInputStreamUnitTest.java new file mode 100644 index 0000000000..1019781837 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/WithMockedInputStreamUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.systemstubs; + +import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.stream.input.LinesAltStream; + +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; + +class WithMockedInputStreamUnitTest { + @Test + void givenInputStream_thenCanRead() { + LinesAltStream testInput = new LinesAltStream("line1", "line2"); + + Scanner scanner = new Scanner(testInput); + assertThat(scanner.nextLine()).isEqualTo("line1"); + } +} From 47f7379996fe49939688e1b7cecfef3a56fc4040 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Nov 2020 14:35:35 +0800 Subject: [PATCH 239/590] 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 f93e1a9943..8a59d6a229 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -6,3 +6,4 @@ - [AbstractMethodError in Java](https://www.baeldung.com/java-abstractmethoderror) - [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) - [Localizing Exception Messages in Java](https://www.baeldung.com/java-localize-exception-messages) +- [Explanation of ClassCastException in Java](https://www.baeldung.com/java-classcastexception) From f449b3cc374c66c5ad6a4113ea98422875600525 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Nov 2020 14:38:35 +0800 Subject: [PATCH 240/590] Update README.md --- persistence-modules/spring-data-jpa-repo-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-repo-2/README.md b/persistence-modules/spring-data-jpa-repo-2/README.md index de5188c1ad..0a690fe5a5 100644 --- a/persistence-modules/spring-data-jpa-repo-2/README.md +++ b/persistence-modules/spring-data-jpa-repo-2/README.md @@ -2,4 +2,5 @@ ### Relevant Articles: - [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa) -- More articles: [[<-- prev]](/spring-data-jpa-repo/) \ No newline at end of file +- [Performance Difference Between save() and saveAll() in Spring Data](https://www.baeldung.com/spring-data-save-saveall) +- More articles: [[<-- prev]](/spring-data-jpa-repo/) From ed078e742295ef53fd9b71b0a184ac81b2b254dc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Nov 2020 14:44:18 +0800 Subject: [PATCH 241/590] Update README.md --- core-java-modules/core-java-collections-array-list/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list/README.md b/core-java-modules/core-java-collections-array-list/README.md index 3637f835cf..d24f7492bb 100644 --- a/core-java-modules/core-java-collections-array-list/README.md +++ b/core-java-modules/core-java-collections-array-list/README.md @@ -8,4 +8,4 @@ This module contains articles about the Java ArrayList collection - [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist) - [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist) - [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element) - +- [The Capacity of an ArrayList vs the Size of an Array in Java](https://www.baeldung.com/java-list-capacity-array-size) From 962405675219ef44548f85cb09166f8b4379a493 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 25 Nov 2020 11:52:43 +0200 Subject: [PATCH 242/590] remove remaining kotlin code --- machine-learning/README.md | 3 - machine-learning/pom.xml | 163 ------------------ .../cnn/ConvolutionalNeuralNetwork.kt | 117 ------------- .../com/baeldung/cnn/ZalandoMNISTDataSet.kt | 45 ----- .../SimpleLinearRegression.kt | 31 ---- .../main/resources/train-labels-idx1-ubyte | Bin 60008 -> 0 bytes .../SimpleLinearRegressionUnitTest.kt | 40 ----- pom.xml | 2 - spring-5-data-reactive/README.md | 1 - spring-5-data-reactive/pom.xml | 67 ------- .../main/kotlin/com/baeldung/Application.kt | 12 -- .../src/main/kotlin/com/baeldung/Event.kt | 6 - .../kotlin/com/baeldung/EventRepository.kt | 6 - .../main/kotlin/com/baeldung/MongoConfig.kt | 25 --- .../main/kotlin/com/baeldung/SendEmitter.kt | 16 -- .../src/main/resources/static/index.html | 39 ----- spring-5-mvc/README.md | 1 - spring-5-mvc/pom.xml | 82 --------- .../springbootkotlin/HelloController.kt | 23 --- .../com/baeldung/springbootkotlin/HelloDto.kt | 3 - .../baeldung/springbootkotlin/HelloService.kt | 11 -- .../springbootkotlin/KotlinDemoApplication.kt | 12 -- .../KotlinDemoApplicationIntegrationTest.kt | 52 ------ spring-security-modules/pom.xml | 1 - .../spring-security-kotlin-dsl/README.md | 3 - .../spring-security-kotlin-dsl/pom.xml | 87 ---------- .../dsl/SpringSecurityKotlinApplication.kt | 71 -------- .../src/main/resources/application.properties | 0 .../SpringSecurityKotlinApplicationTests.kt | 35 ---- 29 files changed, 954 deletions(-) delete mode 100644 machine-learning/README.md delete mode 100644 machine-learning/pom.xml delete mode 100644 machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt delete mode 100644 machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt delete mode 100644 machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt delete mode 100644 machine-learning/src/main/resources/train-labels-idx1-ubyte delete mode 100644 machine-learning/src/test/com/baeldung/simplelinearregression/SimpleLinearRegressionUnitTest.kt delete mode 100644 spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt delete mode 100644 spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt delete mode 100644 spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt delete mode 100644 spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt delete mode 100644 spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt delete mode 100644 spring-5-data-reactive/src/main/resources/static/index.html delete mode 100644 spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt delete mode 100644 spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt delete mode 100644 spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt delete mode 100644 spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt delete mode 100644 spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt delete mode 100644 spring-security-modules/spring-security-kotlin-dsl/README.md delete mode 100644 spring-security-modules/spring-security-kotlin-dsl/pom.xml delete mode 100644 spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt delete mode 100644 spring-security-modules/spring-security-kotlin-dsl/src/main/resources/application.properties delete mode 100644 spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt diff --git a/machine-learning/README.md b/machine-learning/README.md deleted file mode 100644 index 80f2d2c6cd..0000000000 --- a/machine-learning/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Introduction to Supervised Learning in Kotlin](https://www.baeldung.com/kotlin-supervised-learning) diff --git a/machine-learning/pom.xml b/machine-learning/pom.xml deleted file mode 100644 index 842e488985..0000000000 --- a/machine-learning/pom.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - 4.0.0 - machine-learning - 1.0-SNAPSHOT - machine-learning - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.nd4j - nd4j-native-platform - ${dl4j.version} - - - org.deeplearning4j - deeplearning4j-core - ${dl4j.version} - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - - - src/main/kotlin - src/test - - - - - maven-clean-plugin - ${clean.plugin.version} - - - - maven-resources-plugin - ${resources.plugin.version} - - - maven-compiler-plugin - ${compiler.plugin.version} - - - maven-surefire-plugin - ${surefire.plugin.version} - - - maven-jar-plugin - ${jar.plugin.version} - - - maven-install-plugin - ${install.plugin.version} - - - maven-deploy-plugin - ${deploy.plugin.version} - - - - maven-site-plugin - ${site.plugin.version} - - - maven-project-info-reports-plugin - ${report.plugin.version} - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - 1.8 - - - - org.apache.maven.plugins - maven-compiler-plugin - - - compile - compile - - compile - - - - testCompile - test-compile - - testCompile - - - - - - - - - UTF-8 - 1.7 - 1.7 - 1.3.50 - 0.9.1 - 3.1.0 - 3.0.2 - 3.0.2 - 3.8.0 - 2.22.1 - 2.5.2 - 2.8.2 - 3.7.1 - 3.0.0 - - - diff --git a/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt b/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt deleted file mode 100644 index b77fe273ae..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.baeldung.cnn - -import org.datavec.api.records.reader.impl.collection.ListStringRecordReader -import org.datavec.api.split.ListStringSplit -import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator -import org.deeplearning4j.eval.Evaluation -import org.deeplearning4j.nn.conf.NeuralNetConfiguration -import org.deeplearning4j.nn.conf.inputs.InputType -import org.deeplearning4j.nn.conf.layers.* -import org.deeplearning4j.nn.multilayer.MultiLayerNetwork -import org.deeplearning4j.nn.weights.WeightInit -import org.nd4j.linalg.activations.Activation -import org.nd4j.linalg.learning.config.Adam -import org.nd4j.linalg.lossfunctions.LossFunctions - -object ConvolutionalNeuralNetwork { - - @JvmStatic - fun main(args: Array) { - val dataset = ZalandoMNISTDataSet().load() - dataset.shuffle() - val trainDatasetIterator = createDatasetIterator(dataset.subList(0, 50_000)) - val testDatasetIterator = createDatasetIterator(dataset.subList(50_000, 60_000)) - - val cnn = buildCNN() - learning(cnn, trainDatasetIterator) - testing(cnn, testDatasetIterator) - } - - private fun createDatasetIterator(dataset: MutableList>): RecordReaderDataSetIterator { - val listStringRecordReader = ListStringRecordReader() - listStringRecordReader.initialize(ListStringSplit(dataset)) - return RecordReaderDataSetIterator(listStringRecordReader, 128, 28 * 28, 10) - } - - private fun buildCNN(): MultiLayerNetwork { - val multiLayerNetwork = MultiLayerNetwork(NeuralNetConfiguration.Builder() - .seed(123) - .l2(0.0005) - .updater(Adam()) - .weightInit(WeightInit.XAVIER) - .list() - .layer(0, buildInitialConvolutionLayer()) - .layer(1, buildBatchNormalizationLayer()) - .layer(2, buildPoolingLayer()) - .layer(3, buildConvolutionLayer()) - .layer(4, buildBatchNormalizationLayer()) - .layer(5, buildPoolingLayer()) - .layer(6, buildDenseLayer()) - .layer(7, buildBatchNormalizationLayer()) - .layer(8, buildDenseLayer()) - .layer(9, buildOutputLayer()) - .setInputType(InputType.convolutionalFlat(28, 28, 1)) - .backprop(true) - .build()) - multiLayerNetwork.init() - return multiLayerNetwork - } - - private fun buildOutputLayer(): OutputLayer? { - return OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD) - .nOut(10) - .activation(Activation.SOFTMAX) - .build() - } - - private fun buildDenseLayer(): DenseLayer? { - return DenseLayer.Builder().activation(Activation.RELU) - .nOut(500) - .dropOut(0.5) - .build() - } - - private fun buildPoolingLayer(): SubsamplingLayer? { - return SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) - .kernelSize(2, 2) - .stride(2, 2) - .build() - } - - private fun buildBatchNormalizationLayer() = BatchNormalization.Builder().build() - - private fun buildConvolutionLayer(): ConvolutionLayer? { - return ConvolutionLayer.Builder(5, 5) - .stride(1, 1) // nIn need not specified in later layers - .nOut(50) - .activation(Activation.IDENTITY) - .build() - } - - private fun buildInitialConvolutionLayer(): ConvolutionLayer? { - return ConvolutionLayer.Builder(5, 5) - .nIn(1) - .stride(1, 1) - .nOut(20) - .activation(Activation.IDENTITY) - .build() - } - - private fun learning(cnn: MultiLayerNetwork, trainSet: RecordReaderDataSetIterator) { - for (i in 0 until 10) { - cnn.fit(trainSet) - } - } - - private fun testing(cnn: MultiLayerNetwork, testSet: RecordReaderDataSetIterator) { - val evaluation = Evaluation(10) - while (testSet.hasNext()) { - val next = testSet.next() - val output = cnn.output(next.features) - evaluation.eval(next.labels, output) - } - - println(evaluation.stats()) - println(evaluation.confusionToString()) - } -} \ No newline at end of file diff --git a/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt b/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt deleted file mode 100644 index f29c8f2d0b..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.cnn - -import java.io.File -import java.nio.ByteBuffer -import java.util.* -import java.util.stream.Collectors -import kotlin.streams.asStream - -class ZalandoMNISTDataSet { - private val OFFSET_SIZE = 4 //in bytes - private val NUM_ITEMS_OFFSET = 4 - private val ITEMS_SIZE = 4 - private val ROWS = 28 - private val COLUMNS = 28 - private val IMAGE_OFFSET = 16 - private val IMAGE_SIZE = ROWS * COLUMNS - - fun load(): MutableList> { - val labelsFile = File("machine-learning/src/main/resources/train-labels-idx1-ubyte") - val imagesFile = File("machine-learning/src/main/resources/train-images-idx3-ubyte") - - val labelBytes = labelsFile.readBytes() - val imageBytes = imagesFile.readBytes() - - val byteLabelCount = Arrays.copyOfRange(labelBytes, NUM_ITEMS_OFFSET, NUM_ITEMS_OFFSET + ITEMS_SIZE) - val numberOfLabels = ByteBuffer.wrap(byteLabelCount).int - - val list = mutableListOf>() - - for (i in 0 until numberOfLabels) { - val label = labelBytes[OFFSET_SIZE + ITEMS_SIZE + i] - val startBoundary = i * IMAGE_SIZE + IMAGE_OFFSET - val endBoundary = i * IMAGE_SIZE + IMAGE_OFFSET + IMAGE_SIZE - val imageData = Arrays.copyOfRange(imageBytes, startBoundary, endBoundary) - - val imageDataList = imageData.iterator() - .asSequence() - .asStream().map { b -> b.toString() } - .collect(Collectors.toList()) - imageDataList.add(label.toString()) - list.add(imageDataList) - } - return list - } -} \ No newline at end of file diff --git a/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt b/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt deleted file mode 100644 index 5ab520924e..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.simplelinearregression - -import kotlin.math.pow - -class SimpleLinearRegression(private val xs: List, private val ys: List) { - var slope: Double = 0.0 - var yIntercept: Double = 0.0 - - init { - val covariance = calculateCovariance(xs, ys) - val variance = calculateVariance(xs) - slope = calculateSlope(covariance, variance) - yIntercept = calculateYIntercept(ys, slope, xs) - } - - fun predict(independentVariable: Double) = slope * independentVariable + yIntercept - - fun calculateRSquared(): Double { - val sst = ys.sumByDouble { y -> (y - ys.average()).pow(2) } - val ssr = xs.zip(ys) { x, y -> (y - predict(x.toDouble())).pow(2) }.sum() - return (sst - ssr) / sst - } - - private fun calculateYIntercept(ys: List, slope: Double, xs: List) = ys.average() - slope * xs.average() - - private fun calculateSlope(covariance: Double, variance: Double) = covariance / variance - - private fun calculateCovariance(xs: List, ys: List) = xs.zip(ys) { x, y -> (x - xs.average()) * (y - ys.average()) }.sum() - - private fun calculateVariance(xs: List) = xs.sumByDouble { x -> (x - xs.average()).pow(2) } -} \ No newline at end of file diff --git a/machine-learning/src/main/resources/train-labels-idx1-ubyte b/machine-learning/src/main/resources/train-labels-idx1-ubyte deleted file mode 100644 index 30424ca2ea876655f5bba14f9f07132769687975..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 60008 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
    e{yx2{J+Y$g~_>H0G7E0C=Swi~8Y&ssu7 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 k&;b*9sV(5Nc~<7sGbMllombok-custom lucene - machine-learning mapstruct maven-modules @@ -996,7 +995,6 @@ lombok-custom lucene - machine-learning mapstruct maven-modules diff --git a/spring-5-data-reactive/README.md b/spring-5-data-reactive/README.md index 42fcba96f2..0931161700 100644 --- a/spring-5-data-reactive/README.md +++ b/spring-5-data-reactive/README.md @@ -6,7 +6,6 @@ This module contains articles about reactive Spring 5 Data The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles -- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](https://www.baeldung.com/kotlin-mongodb-spring-webflux) - [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive) - [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors) - [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml index 396f7f5959..0fb689f16d 100644 --- a/spring-5-data-reactive/pom.xml +++ b/spring-5-data-reactive/pom.xml @@ -31,18 +31,6 @@ org.springframework.boot spring-boot-starter-web - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - org.jetbrains.kotlin - kotlin-reflect - org.projectlombok lombok @@ -52,12 +40,6 @@ reactor-test test - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - io.reactivex.rxjava2 rxjava @@ -128,53 +110,6 @@ org.springframework.boot spring-boot-maven-plugin - - kotlin-maven-plugin - ${kotlin-maven-plugin.version} - - - compile - - compile - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/java - - - - - test-compile - - test-compile - - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/java - - - - - org.jetbrains.kotlin - - - -Xjsr305=strict - - - spring - - 1.8 - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - org.apache.maven.plugins maven-compiler-plugin @@ -215,8 +150,6 @@ - 1.2.40 - 1.2.40 5.2.2.RELEASE 1.0.0.RELEASE 0.8.1.RELEASE diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt deleted file mode 100644 index 5a59d11de0..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration - -@SpringBootApplication(exclude = arrayOf(MongoReactiveDataAutoConfiguration::class)) -class Application - -fun main(args: Array) { - SpringApplication.run(Application::class.java, *args) -} diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt deleted file mode 100644 index 17fa9699a8..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung - -import org.springframework.data.mongodb.core.mapping.Document - -@Document -data class Event(val id: String, val name: String) diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt deleted file mode 100644 index e66af71ea6..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung - -import org.springframework.data.mongodb.core.mapping.Document -import org.springframework.data.mongodb.repository.ReactiveMongoRepository - -interface EventRepository : ReactiveMongoRepository diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt deleted file mode 100644 index 64d51a176a..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung - -import com.mongodb.reactivestreams.client.MongoClient -import com.mongodb.reactivestreams.client.MongoClients -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration -import org.springframework.data.mongodb.core.ReactiveMongoTemplate -import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories - - -@Configuration -@EnableReactiveMongoRepositories(basePackageClasses = arrayOf(EventRepository::class)) -class MongoConfig : AbstractReactiveMongoConfiguration() { - - override fun reactiveMongoClient(): MongoClient = mongoClient() - - @Bean - fun mongoClient(): MongoClient = MongoClients.create() - - override fun getDatabaseName(): String = "mongoDatabase" - - @Bean - override fun reactiveMongoTemplate(): ReactiveMongoTemplate = ReactiveMongoTemplate(mongoClient(), databaseName) -} diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt deleted file mode 100644 index 6fa3118d8f..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung - -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController -import java.util.* - - -@RestController -class SendEmitter(val eventRepository: EventRepository) { - - @GetMapping(value = "/save", produces = arrayOf(MediaType.TEXT_EVENT_STREAM_VALUE)) - fun executeExample(@RequestParam("eventName") eventName: String) = - eventRepository.save(Event(UUID.randomUUID().toString(), eventName)).flux() -} diff --git a/spring-5-data-reactive/src/main/resources/static/index.html b/spring-5-data-reactive/src/main/resources/static/index.html deleted file mode 100644 index a0b8f6f884..0000000000 --- a/spring-5-data-reactive/src/main/resources/static/index.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - -
    - - -
    - - - -
    - - - - diff --git a/spring-5-mvc/README.md b/spring-5-mvc/README.md index aff8bb227c..edb6cec455 100644 --- a/spring-5-mvc/README.md +++ b/spring-5-mvc/README.md @@ -3,7 +3,6 @@ This module contains articles about Spring 5 model-view-controller (MVC) pattern ### Relevant Articles: -- [Spring Boot and Kotlin](https://www.baeldung.com/spring-boot-kotlin) - [Spring MVC Streaming and SSE Request Processing](https://www.baeldung.com/spring-mvc-sse-streams) - [Interface Driven Controllers in Spring](https://www.baeldung.com/spring-interface-driven-controllers) - [Returning Plain HTML From a Spring MVC Controller](https://www.baeldung.com/spring-mvc-return-html) diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 0bb69d8057..39fcd22824 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -42,22 +42,6 @@ org.slf4j jcl-over-slf4j
    - - - org.jetbrains.kotlin - kotlin-stdlib-jre8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-reflect - ${kotlin.version} - - - com.fasterxml.jackson.module - jackson-module-kotlin - ${jackson.version} - org.springframework.boot @@ -103,77 +87,11 @@ org.springframework.boot spring-boot-maven-plugin - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - spring - - ${java.version} - - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - generate-sources - - add-source - - - - ${basedir}/src/main/java - ${basedir}/src/main/kotlin - - - - - test-compile - test-compile - - add-test-source - - - - ${basedir}/src/test/java - ${basedir}/src/test/kotlin - - - - - 2.9.0 - 1.2.71 4.5.8 com.baeldung.Spring5Application 0.18 diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt deleted file mode 100644 index 69be7dac7e..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class HelloController(val helloService: HelloService) { - - @GetMapping("/hello") - fun helloKotlin(): String { - return "hello world" - } - - @GetMapping("/hello-service") - fun helloKotlinService(): String { - return helloService.getHello() - } - - @GetMapping("/hello-dto") - fun helloDto(): HelloDto { - return HelloDto("Hello from the dto") - } -} \ No newline at end of file diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt deleted file mode 100644 index f61c101f0f..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.springbootkotlin - -data class HelloDto(val greeting: String) diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt deleted file mode 100644 index 67791a0c2d..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.stereotype.Service - -@Service -class HelloService { - - fun getHello(): String { - return "hello service" - } -} \ No newline at end of file diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt deleted file mode 100644 index 8904d8d805..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration - -@SpringBootApplication(scanBasePackages = arrayOf("com.baeldung.springbootkotlin"), exclude = arrayOf(SecurityAutoConfiguration::class)) -class KotlinDemoApplication - -fun main(args: Array) { - SpringApplication.run(KotlinDemoApplication::class.java, *args) -} diff --git a/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt b/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt deleted file mode 100644 index d0667177c8..0000000000 --- a/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull -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.http.HttpStatus -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@SpringBootTest( - classes = arrayOf(KotlinDemoApplication::class), - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class KotlinDemoApplicationIntegrationTest { - - @Autowired - lateinit var testRestTemplate: TestRestTemplate - - @Test - fun whenCalled_thenShouldReturnHello() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello", String::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals("hello world", result?.body) - } - - @Test - fun whenCalled_thenShouldReturnHelloService() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello-service", String::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals(result?.body, "hello service") - } - - @Test - fun whenCalled_thenShouldReturnJson() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello-dto", HelloDto::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals(result?.body, HelloDto("Hello from the dto")) - } - -} diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 0fc2b49fa7..e32fadd671 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -38,7 +38,6 @@ spring-security-oauth2-sso spring-security-web-thymeleaf spring-security-web-x509 - spring-security-kotlin-dsl diff --git a/spring-security-modules/spring-security-kotlin-dsl/README.md b/spring-security-modules/spring-security-kotlin-dsl/README.md deleted file mode 100644 index 39e521d84e..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Spring Security with Kotlin DSL](https://www.baeldung.com/kotlin/spring-security-dsl) diff --git a/spring-security-modules/spring-security-kotlin-dsl/pom.xml b/spring-security-modules/spring-security-kotlin-dsl/pom.xml deleted file mode 100644 index 24e99decfb..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - 4.0.0 - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - com.baeldung.spring.security.dsl - spring-security-kotlin-dsl - 1.0 - spring-security-kotlin-dsl - Spring Security Kotlin DSL - - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-web - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.jetbrains.kotlin - kotlin-reflect - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - -Xjsr305=strict - - - spring - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - - - - 11 - 1.3.72 - - - diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt b/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt deleted file mode 100644 index 27cc41c1e5..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.security.kotlin.dsl - -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.runApplication -import org.springframework.context.annotation.Configuration -import org.springframework.context.support.beans -import org.springframework.core.annotation.Order -import org.springframework.security.config.annotation.web.builders.HttpSecurity -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter -import org.springframework.security.config.web.servlet.invoke -import org.springframework.security.core.userdetails.User -import org.springframework.security.provisioning.InMemoryUserDetailsManager -import org.springframework.web.servlet.function.ServerResponse -import org.springframework.web.servlet.function.router - -@EnableWebSecurity -@SpringBootApplication -class SpringSecurityKotlinApplication - -@Order(1) -@Configuration -class AdminSecurityConfiguration : WebSecurityConfigurerAdapter() { - override fun configure(http: HttpSecurity?) { - http { - authorizeRequests { - authorize("/greetings/**", hasAuthority("ROLE_ADMIN")) - } - httpBasic {} - } - } -} - -@Configuration -class BasicSecurityConfiguration : WebSecurityConfigurerAdapter() { - override fun configure(http: HttpSecurity?) { - http { - authorizeRequests { - authorize("/**", permitAll) - } - httpBasic {} - } - } -} - -fun main(args: Array) { - runApplication(*args) { - addInitializers( beans { - bean { - fun user(user: String, password: String, vararg roles: String) = - User - .withDefaultPasswordEncoder() - .username(user) - .password(password) - .roles(*roles) - .build() - - InMemoryUserDetailsManager(user("user", "password", "USER") - , user("admin", "password", "USER", "ADMIN")) - } - - bean { - router { - GET("/greetings") { - request -> request.principal().map { it.name }.map { ServerResponse.ok().body(mapOf("greeting" to "Hello $it")) }.orElseGet { ServerResponse.badRequest().build() } - } - } - } - }) - } -} diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/main/resources/application.properties b/spring-security-modules/spring-security-kotlin-dsl/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt b/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt deleted file mode 100644 index 3da8110feb..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.spring.security.kotlin.dsl - -import org.junit.jupiter.api.Test -import org.junit.runner.RunWith -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.security.test.context.support.WithMockUser -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.servlet.MockMvc -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.* -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic -import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated -import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated -import org.springframework.test.web.servlet.get -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status - -@RunWith(SpringRunner::class) -@SpringBootTest -@AutoConfigureMockMvc -class SpringSecurityKotlinApplicationTests { - - @Autowired - private lateinit var mockMvc: MockMvc - - @Test - fun `ordinary user not permitted to access the endpoint`() { - this.mockMvc - .perform(get("/greetings") - .with(httpBasic("user", "password"))) - .andExpect(unauthenticated()) - } -} From 0185b2d0fbe9d109c04be0a53ab3dba8e0ddb4e2 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 23 Nov 2020 12:30:41 -0300 Subject: [PATCH 243/590] removed all PropertyPlaceholderConfigure references --- .../PropertiesWithPlaceHolderConfigurer.java | 21 -------- .../spring/PropertyPlaceholderConfig.java | 23 --------- .../configForPropertyPlaceholderBeans.xml | 9 ---- ...PlaceholdersJavaConfigIntegrationTest.java | 3 +- ...yPlaceHolderPropertiesIntegrationTest.java | 51 ------------------- .../parentchild/config/ChildConfig2.java | 24 --------- .../parentchild/config/ParentConfig2.java | 24 --------- 7 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertiesWithPlaceHolderConfigurer.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/ParentChildPropertyPlaceHolderPropertiesIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ChildConfig2.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ParentConfig2.java diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertiesWithPlaceHolderConfigurer.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertiesWithPlaceHolderConfigurer.java deleted file mode 100644 index 512ecda266..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertiesWithPlaceHolderConfigurer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.properties.spring; - -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class PropertiesWithPlaceHolderConfigurer { - - public PropertiesWithPlaceHolderConfigurer() { - super(); - } - - @Bean - public PropertyPlaceholderConfigurer propertyConfigurer() { - final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer(); - props.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK); - return props; - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java deleted file mode 100644 index 0d1eb4ccf7..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.properties.spring; - -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.*; - -@Configuration -public class PropertyPlaceholderConfig { - - public PropertyPlaceholderConfig(){ - super(); - } - - @Bean - public static PropertyPlaceholderConfigurer properties() { - PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); - Resource[] resources = new ClassPathResource[]{ new ClassPathResource("foo.properties") }; - ppc.setLocations( resources ); - ppc.setIgnoreUnresolvablePlaceholders( true ); - return ppc; - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml index a296cf5169..fd2731df36 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml @@ -3,15 +3,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd" > - - - - classpath:foo.properties - - - - - diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java index 8ebda90321..6c88623ab7 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java @@ -4,12 +4,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import com.baeldung.properties.spring.PropertyPlaceholderConfig; import com.baeldung.properties.spring.PropertySourcesPlaceholderConfig; import static org.assertj.core.api.Assertions.assertThat; -@SpringJUnitConfig({PropertyPlaceholderConfig.class, PropertySourcesPlaceholderConfig.class}) +@SpringJUnitConfig({PropertySourcesPlaceholderConfig.class}) public class MultiplePlaceholdersJavaConfigIntegrationTest { @Value("${key.something}") diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/ParentChildPropertyPlaceHolderPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/ParentChildPropertyPlaceHolderPropertiesIntegrationTest.java deleted file mode 100644 index 374a502e5c..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/ParentChildPropertyPlaceHolderPropertiesIntegrationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.properties.parentchild; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.context.WebApplicationContext; - -import com.baeldung.properties.parentchild.config.ChildConfig2; -import com.baeldung.properties.parentchild.config.ParentConfig2; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig2.class), @ContextConfiguration(classes = ChildConfig2.class) }) -public class ParentChildPropertyPlaceHolderPropertiesIntegrationTest { - - @Autowired - private WebApplicationContext wac; - - @Test - public void givenPropertyPlaceHolder_whenGetPropertyUsingEnv_thenCorrect() { - final Environment childEnv = wac.getEnvironment(); - final Environment parentEnv = wac.getParent().getEnvironment(); - - assertNull(parentEnv.getProperty("parent.name")); - assertNull(parentEnv.getProperty("child.name")); - - assertNull(childEnv.getProperty("parent.name")); - assertNull(childEnv.getProperty("child.name")); - } - - @Test - public void givenPropertyPlaceHolder_whenGetPropertyUsingValueAnnotation_thenCorrect() { - final ChildValueHolder childValueHolder = wac.getBean(ChildValueHolder.class); - final ParentValueHolder parentValueHolder = wac.getParent().getBean(ParentValueHolder.class); - - assertEquals(parentValueHolder.getParentName(), "parent"); - assertEquals(parentValueHolder.getChildName(), "-"); - - assertEquals(childValueHolder.getParentName(), "-"); - assertEquals(childValueHolder.getChildName(), "child"); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ChildConfig2.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ChildConfig2.java deleted file mode 100644 index a506060d1c..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ChildConfig2.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.properties.parentchild.config; - -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; - -import com.baeldung.properties.parentchild.ChildValueHolder; - -@Configuration -public class ChildConfig2 { - - @Bean - public ChildValueHolder childValueHolder() { - return new ChildValueHolder(); - } - - @Bean - public static PropertyPlaceholderConfigurer properties() { - final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); - ppc.setLocations(new ClassPathResource("child.properties")); - return ppc; - } -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ParentConfig2.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ParentConfig2.java deleted file mode 100644 index f5376e0c8e..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/parentchild/config/ParentConfig2.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.properties.parentchild.config; - -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; - -import com.baeldung.properties.parentchild.ParentValueHolder; - -@Configuration -public class ParentConfig2 { - - @Bean - public ParentValueHolder parentValueHolder() { - return new ParentValueHolder(); - } - - @Bean - public static PropertyPlaceholderConfigurer properties() { - final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); - ppc.setLocations(new ClassPathResource("parent.properties")); - return ppc; - } -} From aa44953fe9d66b8cb7790a5b90cb524ad148645a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 25 Nov 2020 09:26:47 -0300 Subject: [PATCH 244/590] removed all XML-related code --- .../core/ComponentInXmlUsingProperties.java | 30 -------------- .../ExternalPropertiesWithXmlConfig.java | 16 -------- .../ExternalPropertiesWithXmlConfigOne.java | 16 -------- .../ExternalPropertiesWithXmlConfigTwo.java | 14 ------- .../resources/basicConfigForProperties.xml | 12 ------ .../resources/basicConfigForPropertiesOne.xml | 12 ------ .../resources/basicConfigForPropertiesTwo.xml | 13 ------- .../main/resources/configForDbProperties.xml | 19 --------- .../main/resources/configForProperties.xml | 17 -------- .../main/resources/configForPropertiesOne.xml | 16 -------- .../configForPropertyPlaceholderBeans.xml | 14 ------- ...ertiesWithMultipleXmlsIntegrationTest.java | 27 ------------- .../PropertiesWithXmlIntegrationTest.java | 27 ------------- ...ertiesWithMultipleXmlsIntegrationTest.java | 39 ------------------- .../ExternalPropertiesWithXmlManualTest.java | 38 ------------------ ...ePlaceholdersXmlConfigIntegrationTest.java | 25 ------------ ...plePropertiesXmlConfigIntegrationTest.java | 24 ------------ .../baeldung/test/IntegrationTestSuite.java | 12 +----- 18 files changed, 1 insertion(+), 370 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/core/ComponentInXmlUsingProperties.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigTwo.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForProperties.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesOne.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesTwo.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configForDbProperties.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertiesOne.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithMultipleXmlsIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithXmlIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithMultipleXmlsIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithXmlManualTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/core/ComponentInXmlUsingProperties.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/core/ComponentInXmlUsingProperties.java deleted file mode 100644 index 675c72e642..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/core/ComponentInXmlUsingProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.properties.core; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; - -public class ComponentInXmlUsingProperties implements InitializingBean { - - @Autowired - private Environment env; - - @Value("${key.something}") - private String injectedProperty; - - public ComponentInXmlUsingProperties(final String propertyValue) { - super(); - - System.out.println("Constructor Injection - Property Value resolved to: " + propertyValue); - } - - // - - @Override - public void afterPropertiesSet() throws Exception { - System.out.println("in afterPropertiesSet via @Value: " + injectedProperty); - System.out.println("in afterPropertiesSet Environment: " + env.getProperty("key.something")); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java deleted file mode 100644 index 9080e3d0ba..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.properties.external; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource("classpath:configForProperties.xml") -@ComponentScan("com.baeldung.core") -public class ExternalPropertiesWithXmlConfig { - - public ExternalPropertiesWithXmlConfig() { - super(); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java deleted file mode 100644 index f45f5b6a03..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.properties.external; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource("classpath:configForPropertiesOne.xml") -@ComponentScan("com.baeldung.core") -public class ExternalPropertiesWithXmlConfigOne { - - public ExternalPropertiesWithXmlConfigOne() { - super(); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigTwo.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigTwo.java deleted file mode 100644 index 38ecdd2aae..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigTwo.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.properties.external; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource("classpath:basicConfigForPropertiesTwo.xml") -public class ExternalPropertiesWithXmlConfigTwo { - - public ExternalPropertiesWithXmlConfigTwo() { - super(); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForProperties.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForProperties.xml deleted file mode 100644 index e50de084f0..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForProperties.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesOne.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesOne.xml deleted file mode 100644 index 01b297d437..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesOne.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesTwo.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesTwo.xml deleted file mode 100644 index 1d470c4340..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/basicConfigForPropertiesTwo.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForDbProperties.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForDbProperties.xml deleted file mode 100644 index 00fd5f0508..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForDbProperties.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml deleted file mode 100644 index 16db00ace3..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertiesOne.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertiesOne.xml deleted file mode 100644 index 53072d89bb..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertiesOne.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml deleted file mode 100644 index fd2731df36..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - classpath:foo.properties - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithMultipleXmlsIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithMultipleXmlsIntegrationTest.java deleted file mode 100644 index c3af2dc1d8..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithMultipleXmlsIntegrationTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.properties.basic; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:basicConfigForPropertiesOne.xml", "classpath:basicConfigForPropertiesTwo.xml" }) -public class PropertiesWithMultipleXmlsIntegrationTest { - - @Autowired - private Environment env; - - @Value("${key.something}") - private String injectedProperty; - - @Test - public final void givenContextIsInitialized_thenNoException() { - System.out.println("in test via @Value: " + injectedProperty); - System.out.println("in test Environment: " + env.getProperty("key.something")); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithXmlIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithXmlIntegrationTest.java deleted file mode 100644 index 85c4ac34e2..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/basic/PropertiesWithXmlIntegrationTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.properties.basic; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath:basicConfigForProperties.xml") -public class PropertiesWithXmlIntegrationTest { - - @Autowired - private Environment env; - - @Value("${key.something}") - private String injectedProperty; - - @Test - public final void givenContextIsInitialized_thenNoException() { - System.out.println("in test via @Value: " + injectedProperty); - System.out.println("in test Environment: " + env.getProperty("key.something")); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithMultipleXmlsIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithMultipleXmlsIntegrationTest.java deleted file mode 100644 index 018c655ec2..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithMultipleXmlsIntegrationTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.properties.external; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -import com.baeldung.properties.external.ExternalPropertiesWithXmlConfigOne; -import com.baeldung.properties.external.ExternalPropertiesWithXmlConfigTwo; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ExternalPropertiesWithXmlConfigOne.class, ExternalPropertiesWithXmlConfigTwo.class }, loader = AnnotationConfigContextLoader.class) -@Ignore("manual only") -public class ExternalPropertiesWithMultipleXmlsIntegrationTest { - - @Autowired - private Environment env; - - @Value("${key.something}") - private String injectedProperty; - - @Value("${external.something}") - private String injectedExternalProperty; - - @Test - public final void givenContextIsInitialized_thenNoException() { - System.out.println("in test via @Value: " + injectedProperty); - System.out.println("in test Environment: " + env.getProperty("key.something")); - - System.out.println("in test via @Value - external: " + injectedExternalProperty); - System.out.println("in test Environment - external: " + env.getProperty("external.something")); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithXmlManualTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithXmlManualTest.java deleted file mode 100644 index 4f0abbc12c..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/external/ExternalPropertiesWithXmlManualTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.properties.external; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -import com.baeldung.properties.external.ExternalPropertiesWithXmlConfig; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ExternalPropertiesWithXmlConfig.class }, loader = AnnotationConfigContextLoader.class) -@Ignore("manual only") -public class ExternalPropertiesWithXmlManualTest { - - @Autowired - private Environment env; - - @Value("${key.something}") - private String injectedProperty; - - @Value("${external.something}") - private String injectedExternalProperty; - - @Test - public final void givenContextIsInitialized_thenNoException() { - System.out.println("in test via @Value: " + injectedProperty); - System.out.println("in test Environment: " + env.getProperty("key.something")); - - System.out.println("in test via @Value - external: " + injectedExternalProperty); - System.out.println("in test Environment - external: " + env.getProperty("external.something")); - } - -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java deleted file mode 100644 index b863e2e080..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.properties.multiple; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import static org.assertj.core.api.Assertions.assertThat; - - -@SpringJUnitConfig(locations = "classpath:configForPropertyPlaceholderBeans.xml") -public class MultiplePlaceholdersXmlConfigIntegrationTest { - - @Value("${foo}") - private String something; - - @Value("${key.something}") - private String something2; - - - @Test - public void whenReadInjectedValues_thenGetCorrectValues() { - assertThat(something).isEqualTo("bar"); - assertThat(something2).isEqualTo("val"); - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java deleted file mode 100644 index 2150d4b3ec..0000000000 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.properties.multiple; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringJUnitConfig(locations = {"classpath:configForProperties.xml", "classpath:configForDbProperties.xml"}) -public class MultiplePropertiesXmlConfigIntegrationTest { - - @Value("${key.something}") private String something; - - @Value("${key.something2}") private String something2; - - @Value("${jdbc.url}") private String jdbcUrl; - - @Test - public void whenReadInjectedValues_thenGetCorrectValues() { - assertThat(something).isEqualTo("val"); - assertThat(something2).isEqualTo("val2"); - assertThat(jdbcUrl).isEqualTo("jdbc:postgresql:/localhost:5432"); - } -} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java index 0e0f8f6230..9a1eccb439 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java @@ -5,22 +5,12 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; import com.baeldung.properties.basic.ExtendedPropertiesWithJavaIntegrationTest; -import com.baeldung.properties.basic.PropertiesWithMultipleXmlsIntegrationTest; -import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest; -import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest; -import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest; -import com.baeldung.properties.multiple.MultiplePropertiesXmlConfigIntegrationTest; -import com.baeldung.properties.multiple.MultiplePlaceholdersXmlConfigIntegrationTest; @RunWith(Suite.class) @SuiteClasses({ //@formatter:off - PropertiesWithXmlIntegrationTest.class, ExternalPropertiesWithJavaIntegrationTest.class, - ExternalPropertiesWithMultipleXmlsIntegrationTest.class, - ExternalPropertiesWithXmlManualTest.class, - ExtendedPropertiesWithJavaIntegrationTest.class, MultiplePropertiesXmlConfigIntegrationTest.class, - PropertiesWithMultipleXmlsIntegrationTest.class, MultiplePlaceholdersXmlConfigIntegrationTest.class + ExtendedPropertiesWithJavaIntegrationTest.class, })// @formatter:on public final class IntegrationTestSuite { // From 73bfea2207c74260842222206786e169d5d82b5e Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 26 Nov 2020 10:51:58 -0300 Subject: [PATCH 245/590] updated Spring Boot version to 2.4.0 --- .../spring-boot-properties/pom.xml | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index cfdc71b8d6..0260a4a72e 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -47,12 +48,10 @@ org.apache.httpcomponents httpcore - ${httpcore.version} org.springframework.boot spring-boot-configuration-processor - ${configuration-processor.version} true @@ -126,16 +125,23 @@ + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + 1.8 - Greenwich.SR1 + 2020.0.0-M5 1.10 20.0 - 4.4.11 @ - 2.2.4.RELEASE - + com.baeldung.yaml.MyApplication + 2.4.0 From b67a3eab35c454c196b74b6a7564a8149b4a8bea Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Thu, 26 Nov 2020 23:44:24 +0530 Subject: [PATCH 246/590] BAEL-4691: Introduction to Servlets and Servlet Containers (#10281) --- .../src/main/java/com/baeldung/jsp/ExampleThree.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java index 7269f917b4..73132704c8 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java @@ -10,11 +10,15 @@ import javax.servlet.http.HttpServletResponse; @WebServlet(name = "ExampleThree", description = "JSP Servlet With Annotations", urlPatterns = { "/ExampleThree" }) public class ExampleThree extends HttpServlet { private static final long serialVersionUID = 1L; + + private String instanceMessage; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message = request.getParameter("message"); + instanceMessage = request.getParameter("message"); request.setAttribute("text", message); + request.setAttribute("unsafeText", instanceMessage); request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response); } } From 83535bf123a1ad9e20d1f229ea726e43a7eef84c Mon Sep 17 00:00:00 2001 From: kwoyke Date: Fri, 27 Nov 2020 11:22:00 +0100 Subject: [PATCH 247/590] BAEL-3689: Add missing code examples (#10282) --- .../main/java/com/baeldung/startup/AppStartupRunner.java | 1 + .../com/baeldung/startup/CommandLineAppStartupRunner.java | 3 ++- .../main/java/com/baeldung/startup/SpringStartupConfig.java | 6 ++++++ .../com/baeldung/startup/SpringStartupIntegrationTest.java | 5 +++++ .../startup/SpringStartupXMLConfigIntegrationTest.java | 2 +- 5 files changed, 15 insertions(+), 2 deletions(-) rename spring-boot-modules/{spring-boot => spring-boot-data}/src/main/java/com/baeldung/startup/AppStartupRunner.java (99%) rename spring-boot-modules/{spring-boot => spring-boot-data}/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java (99%) diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AppStartupRunner.java similarity index 99% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AppStartupRunner.java index 0495473704..0ba719d32b 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AppStartupRunner.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; @Component public class AppStartupRunner implements ApplicationRunner { + private static final Logger LOG = LoggerFactory.getLogger(AppStartupRunner.class); public static int counter; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java similarity index 99% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java index 48c5225cf1..bdedbbe94c 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Component; @Component public class CommandLineAppStartupRunner implements CommandLineRunner { + private static final Logger LOG = LoggerFactory.getLogger(CommandLineAppStartupRunner.class); public static int counter; @@ -15,4 +16,4 @@ public class CommandLineAppStartupRunner implements CommandLineRunner { LOG.info("Increment counter"); counter++; } -} \ No newline at end of file +} diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java index ad6492dadc..27c903955a 100644 --- a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java @@ -1,9 +1,15 @@ package com.baeldung.startup; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan("com.baeldung.startup") public class SpringStartupConfig { + + @Bean(initMethod="init") + public InitMethodExampleBean initMethodExampleBean() { + return new InitMethodExampleBean(); + } } \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java index b58c093c31..ac2b98da6f 100644 --- a/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java +++ b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java @@ -37,6 +37,11 @@ public class SpringStartupIntegrationTest { ctx.getBean(InitializingBeanExampleBean.class); } + @Test + public void whenInitMethod_shouldLogEnv() throws Exception { + ctx.getBean(InitMethodExampleBean.class); + } + @Test public void whenApplicationListener_shouldRunOnce() throws Exception { Assertions.assertThat(StartupApplicationListenerExample.counter).isEqualTo(1); diff --git a/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java index 3dfd4835df..67b430fced 100644 --- a/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java +++ b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java @@ -15,7 +15,7 @@ public class SpringStartupXMLConfigIntegrationTest { private ApplicationContext ctx; @Test - public void whenPostConstruct_shouldLogEnv() throws Exception { + public void whenInitMethod_shouldLogEnv() throws Exception { ctx.getBean(InitMethodExampleBean.class); } From eb4b03eb736dfc39d4a3d34db176c406b46532ad Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 26 Nov 2020 10:52:15 -0300 Subject: [PATCH 248/590] Added simple test for multidocument properties file --- ...documentPropertiesFileIntegrationTest.java | 25 +++++++++++++++++++ ...tiesFileWithDevProfileIntegrationTest.java | 25 +++++++++++++++++++ ...iesFileWithTestProfileIntegrationTest.java | 25 +++++++++++++++++++ .../MultidocumentTestConfig.java | 10 ++++++++ .../src/test/resources/application.properties | 10 ++++++++ 5 files changed, 95 insertions(+) create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..683b0b86ab --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("default") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueDefault"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java new file mode 100644 index 0000000000..3771bdb1c7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileWithDevProfileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileWithDevProfileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueTest"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java new file mode 100644 index 0000000000..b00dda19b7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("dev") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileWithTestProfileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileWithTestProfileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueDev"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java new file mode 100644 index 0000000000..6f80cb70e7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java @@ -0,0 +1,10 @@ +package com.baeldung.properties.multidocument; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.properties.multidocument") +public class MultidocumentTestConfig { + +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties index af38556f81..c3a98b3da4 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties @@ -2,4 +2,14 @@ management.endpoints.web.exposure.include=refresh spring.properties.refreshDelay=1000 spring.config.location=file:extra.properties spring.main.allow-bean-definition-overriding=true +baeldung.customProperty=valueDefault +#--- +spring.config.activate.on-profile=dev +baeldung.customProperty=valueDev +#--- +spring.config.activate.on-profile=test +baeldung.customProperty=valueTest +#--- +spring.config.activate.on-profile=prod +baeldung.customProperty=valueProd From 9116e0cd094233de0e9acf3f0a510fff33907504 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 28 Nov 2020 11:51:46 +0530 Subject: [PATCH 249/590] JAVA-2416 Move/rename module spring-dispatcher-servlet - Moved all the contents from spring-dispatcher-servlet to spring-mvc-basics --- pom.xml | 2 - spring-dispatcher-servlet/README.md | 7 -- spring-dispatcher-servlet/pom.xml | 95 ------------------- .../configuration/AppConfig.java | 83 ---------------- .../configuration/WebAppInitializer.java | 23 ----- .../src/main/resources/logback.xml | 13 --- .../src/main/webapp/WEB-INF/jsp/index.jsp | 30 ------ .../src/main/webapp/resources/css/default.css | 4 - .../src/main/webapp/resources/css/example.css | 4 - .../java/com/baeldung/SpringContextTest.java | 19 ---- spring-mvc-basics/README.md | 1 + spring-mvc-basics/pom.xml | 5 + .../main/java/com/baeldung/model}/User.java | 2 +- .../com/baeldung}/services/UserService.java | 4 +- .../baeldung/spring/web/config/WebConfig.java | 58 +++++++++++ .../web}/controller/MultipartController.java | 2 +- .../web}/controller/UserController.java | 7 +- .../web}/controller/UserRestController.java | 7 +- .../main/resources/themes/default.properties | 0 .../main/resources/themes/example.properties | 0 20 files changed, 76 insertions(+), 290 deletions(-) delete mode 100644 spring-dispatcher-servlet/README.md delete mode 100644 spring-dispatcher-servlet/pom.xml delete mode 100644 spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java delete mode 100644 spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java delete mode 100644 spring-dispatcher-servlet/src/main/resources/logback.xml delete mode 100644 spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp delete mode 100644 spring-dispatcher-servlet/src/main/webapp/resources/css/default.css delete mode 100644 spring-dispatcher-servlet/src/main/webapp/resources/css/example.css delete mode 100644 spring-dispatcher-servlet/src/test/java/com/baeldung/SpringContextTest.java rename {spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain => spring-mvc-basics/src/main/java/com/baeldung/model}/User.java (93%) rename {spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet => spring-mvc-basics/src/main/java/com/baeldung}/services/UserService.java (72%) rename {spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet => spring-mvc-basics/src/main/java/com/baeldung/web}/controller/MultipartController.java (96%) rename {spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet => spring-mvc-basics/src/main/java/com/baeldung/web}/controller/UserController.java (83%) rename {spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet => spring-mvc-basics/src/main/java/com/baeldung/web}/controller/UserRestController.java (82%) rename {spring-dispatcher-servlet => spring-mvc-basics}/src/main/resources/themes/default.properties (100%) rename {spring-dispatcher-servlet => spring-mvc-basics}/src/main/resources/themes/example.properties (100%) diff --git a/pom.xml b/pom.xml index 82e242b9af..8926cdd48f 100644 --- a/pom.xml +++ b/pom.xml @@ -650,7 +650,6 @@ spring-data-rest-querydsl spring-di spring-di-2 - spring-dispatcher-servlet spring-drools spring-ejb @@ -1151,7 +1150,6 @@ spring-data-rest spring-data-rest-querydsl spring-di - spring-dispatcher-servlet spring-drools spring-ejb diff --git a/spring-dispatcher-servlet/README.md b/spring-dispatcher-servlet/README.md deleted file mode 100644 index 3027546152..0000000000 --- a/spring-dispatcher-servlet/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Spring DispatcherServlet - -This module contains articles about Spring DispatcherServlet - -## Relevant articles: - -- [An Intro to the Spring DispatcherServlet](https://www.baeldung.com/spring-dispatcherservlet) diff --git a/spring-dispatcher-servlet/pom.xml b/spring-dispatcher-servlet/pom.xml deleted file mode 100644 index 21324e6757..0000000000 --- a/spring-dispatcher-servlet/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - 4.0.0 - spring-dispatcher-servlet - 1.0.0 - spring-dispatcher-servlet - war - - - com.baeldung - parent-spring-5 - 0.0.1-SNAPSHOT - ../parent-spring-5 - - - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - javax.servlet.jsp.jstl - jstl-api - ${jstl-api.version} - - - javax.servlet.jsp - javax.servlet.jsp-api - ${javax.servlet.jsp-api.version} - - - javax.servlet - jstl - ${jstl.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - commons-fileupload - commons-fileupload - ${commons-fileupload.version} - - - org.springframework.boot - spring-boot-starter-test - ${spring-boot-starter-test.version} - test - - - - - spring-dispatcher-servlet - - - - org.apache.tomcat.maven - tomcat8-maven-plugin - ${tomcat8-maven-plugin.version} - - /springdispatcherservlet - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - src/main/webapp - false - - - - - - - - 3.0-r1655215 - - - \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java deleted file mode 100644 index c8a6cf06a6..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.baeldung.springdispatcherservlet.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.ui.context.support.ResourceBundleThemeSource; -import org.springframework.web.multipart.commons.CommonsMultipartResolver; -import org.springframework.web.servlet.config.annotation.*; -import org.springframework.web.servlet.resource.PathResourceResolver; -import org.springframework.web.servlet.theme.CookieThemeResolver; -import org.springframework.web.servlet.theme.ThemeChangeInterceptor; -import org.springframework.web.servlet.view.JstlView; -import org.springframework.web.servlet.view.UrlBasedViewResolver; - -import java.io.IOException; - -@Configuration -@EnableWebMvc -@ComponentScan("com.baeldung.springdispatcherservlet") -public class AppConfig implements WebMvcConfigurer { - - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("index"); - } - - /** Multipart file uploading configuratioin */ - @Bean - public CommonsMultipartResolver multipartResolver() throws IOException { - CommonsMultipartResolver resolver = new CommonsMultipartResolver(); - resolver.setMaxUploadSize(10000000); - return resolver; - } - - /** View resolver for JSP */ - @Bean - public UrlBasedViewResolver viewResolver() { - UrlBasedViewResolver resolver = new UrlBasedViewResolver(); - resolver.setPrefix("/WEB-INF/jsp/"); - resolver.setSuffix(".jsp"); - resolver.setViewClass(JstlView.class); - return resolver; - } - - /** Static resource locations including themes*/ - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**/*") - .addResourceLocations("/", "/resources/") - .setCachePeriod(3600) - .resourceChain(true) - .addResolver(new PathResourceResolver()); - } - - /** BEGIN theme configuration */ - @Bean - public ResourceBundleThemeSource themeSource(){ - ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource(); - themeSource.setDefaultEncoding("UTF-8"); - themeSource.setBasenamePrefix("themes."); - return themeSource; - } - - @Bean - public CookieThemeResolver themeResolver(){ - CookieThemeResolver resolver = new CookieThemeResolver(); - resolver.setDefaultThemeName("default"); - resolver.setCookieName("example-theme-cookie"); - return resolver; - } - - @Bean - public ThemeChangeInterceptor themeChangeInterceptor(){ - ThemeChangeInterceptor interceptor = new ThemeChangeInterceptor(); - interceptor.setParamName("theme"); - return interceptor; - } - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(themeChangeInterceptor()); - } - /** END theme configuration */ -} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java deleted file mode 100644 index 0c6c7141a7..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.springdispatcherservlet.configuration; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -public class WebAppInitializer implements WebApplicationInitializer { - - @Override - public void onStartup(ServletContext container) throws ServletException { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(AppConfig.class); - context.setServletContext(container); - - ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(context)); - servlet.setLoadOnStartup(1); - servlet.addMapping("/"); - } -} diff --git a/spring-dispatcher-servlet/src/main/resources/logback.xml b/spring-dispatcher-servlet/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp deleted file mode 100644 index c482eac361..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp +++ /dev/null @@ -1,30 +0,0 @@ -<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> -<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> - - - - - - - Spring Dispatcher - - - -

    Hello World!

    -
    -
    Switch Theme! - Switch Theme! -
    -
    -
    -
    - - -
    -
    -
    - ${message} - - diff --git a/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css b/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css deleted file mode 100644 index 7f20f36d96..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css +++ /dev/null @@ -1,4 +0,0 @@ -h2 { - color: green; - font-weight: 400; -} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css b/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css deleted file mode 100644 index fe31b0396a..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css +++ /dev/null @@ -1,4 +0,0 @@ -h2 { - color: red; - font-weight: 700; -} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/test/java/com/baeldung/SpringContextTest.java b/spring-dispatcher-servlet/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index ba8040f81d..0000000000 --- a/spring-dispatcher-servlet/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import com.baeldung.springdispatcherservlet.configuration.AppConfig; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = AppConfig.class) -@WebAppConfiguration -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-mvc-basics/README.md b/spring-mvc-basics/README.md index cd36ffd94a..c1f8bbda70 100644 --- a/spring-mvc-basics/README.md +++ b/spring-mvc-basics/README.md @@ -8,6 +8,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Spring MVC Tutorial](https://www.baeldung.com/spring-mvc-tutorial) +- [An Intro to the Spring DispatcherServlet] (https://www.baeldung.com/spring-dispatcherservlet) - [The Spring @Controller and @RestController Annotations](https://www.baeldung.com/spring-controller-vs-restcontroller) - [A Guide to the ViewResolver in Spring MVC](https://www.baeldung.com/spring-mvc-view-resolver-tutorial) - [Guide to Spring Handler Mappings](https://www.baeldung.com/spring-handler-mappings) diff --git a/spring-mvc-basics/pom.xml b/spring-mvc-basics/pom.xml index d212bc425a..cd486cb1d3 100644 --- a/spring-mvc-basics/pom.xml +++ b/spring-mvc-basics/pom.xml @@ -24,6 +24,11 @@ org.springframework.boot spring-boot-starter-validation + + commons-fileupload + commons-fileupload + ${commons-fileupload.version} + org.apache.tomcat.embed diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java b/spring-mvc-basics/src/main/java/com/baeldung/model/User.java similarity index 93% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java rename to spring-mvc-basics/src/main/java/com/baeldung/model/User.java index 6e8cde50db..3265bcc93a 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/model/User.java @@ -1,4 +1,4 @@ -package com.baeldung.springdispatcherservlet.domain; +package com.baeldung.model; public class User { diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java b/spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java similarity index 72% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java rename to spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java index 1b9bdd4a71..4a70701903 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java @@ -1,8 +1,8 @@ -package com.baeldung.springdispatcherservlet.services; +package com.baeldung.services; import org.springframework.stereotype.Service; -import com.baeldung.springdispatcherservlet.domain.User; +import com.baeldung.model.User; @Service public class UserService { diff --git a/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 9a321f65a2..ac917018b0 100644 --- a/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -1,13 +1,22 @@ package com.baeldung.spring.web.config; +import java.io.IOException; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.http.MediaType; +import org.springframework.ui.context.support.ResourceBundleThemeSource; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.resource.PathResourceResolver; +import org.springframework.web.servlet.theme.CookieThemeResolver; +import org.springframework.web.servlet.theme.ThemeChangeInterceptor; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.ResourceBundleViewResolver; @@ -24,6 +33,14 @@ public class WebConfig implements WebMvcConfigurer { .setViewName("index"); } + /** Multipart file uploading configuratioin */ + @Bean + public CommonsMultipartResolver multipartResolver() throws IOException { + CommonsMultipartResolver resolver = new CommonsMultipartResolver(); + resolver.setMaxUploadSize(10000000); + return resolver; + } + @Bean public ViewResolver viewResolver() { final InternalResourceViewResolver bean = new InternalResourceViewResolver(); @@ -34,6 +51,47 @@ public class WebConfig implements WebMvcConfigurer { return bean; } + /** Static resource locations including themes*/ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**/*") + .addResourceLocations("/", "/resources/") + .setCachePeriod(3600) + .resourceChain(true) + .addResolver(new PathResourceResolver()); + } + + /** BEGIN theme configuration */ + @Bean + public ResourceBundleThemeSource themeSource() { + ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource(); + themeSource.setDefaultEncoding("UTF-8"); + themeSource.setBasenamePrefix("themes."); + return themeSource; + } + + @Bean + public CookieThemeResolver themeResolver() { + CookieThemeResolver resolver = new CookieThemeResolver(); + resolver.setDefaultThemeName("default"); + resolver.setCookieName("example-theme-cookie"); + return resolver; + } + + @Bean + public ThemeChangeInterceptor themeChangeInterceptor() { + ThemeChangeInterceptor interceptor = new ThemeChangeInterceptor(); + interceptor.setParamName("theme"); + return interceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(themeChangeInterceptor()); + } + + /** END theme configuration */ + @Bean public ViewResolver resourceBundleViewResolver() { final ResourceBundleViewResolver bean = new ResourceBundleViewResolver(); diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java similarity index 96% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java rename to spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java index a693bf039f..2255ba780c 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java @@ -1,4 +1,4 @@ -package com.baeldung.springdispatcherservlet.controller; +package com.baeldung.web.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java similarity index 83% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java rename to spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java index 16e6f293ec..9e39c961a1 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java @@ -1,7 +1,8 @@ -package com.baeldung.springdispatcherservlet.controller; +package com.baeldung.web.controller; + +import com.baeldung.model.User; +import com.baeldung.services.UserService; -import com.baeldung.springdispatcherservlet.domain.User; -import com.baeldung.springdispatcherservlet.services.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java similarity index 82% rename from spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java rename to spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java index 9052662f17..7d13c53ba1 100644 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java +++ b/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java @@ -1,7 +1,8 @@ -package com.baeldung.springdispatcherservlet.controller; +package com.baeldung.web.controller; + +import com.baeldung.model.User; +import com.baeldung.services.UserService; -import com.baeldung.springdispatcherservlet.domain.User; -import com.baeldung.springdispatcherservlet.services.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/spring-dispatcher-servlet/src/main/resources/themes/default.properties b/spring-mvc-basics/src/main/resources/themes/default.properties similarity index 100% rename from spring-dispatcher-servlet/src/main/resources/themes/default.properties rename to spring-mvc-basics/src/main/resources/themes/default.properties diff --git a/spring-dispatcher-servlet/src/main/resources/themes/example.properties b/spring-mvc-basics/src/main/resources/themes/example.properties similarity index 100% rename from spring-dispatcher-servlet/src/main/resources/themes/example.properties rename to spring-mvc-basics/src/main/resources/themes/example.properties From 782afc6b06fedc4ba7bace56cf30cb19455d8903 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 28 Nov 2020 14:16:11 +0200 Subject: [PATCH 250/590] JAVA-3700 remove core-scala repo --- core-scala/README.md | 3 --- core-scala/pom.xml | 57 -------------------------------------------- pom.xml | 2 -- 3 files changed, 62 deletions(-) delete mode 100644 core-scala/README.md delete mode 100644 core-scala/pom.xml diff --git a/core-scala/README.md b/core-scala/README.md deleted file mode 100644 index 72b583c22b..0000000000 --- a/core-scala/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Pattern Matching in Scala](https://www.baeldung.com/scala/pattern-matching) diff --git a/core-scala/pom.xml b/core-scala/pom.xml deleted file mode 100644 index 8277b0f856..0000000000 --- a/core-scala/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - 4.0.0 - core-scala - 1.0-SNAPSHOT - core-scala - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.scala-lang - scala-library - ${scala.version} - - - - - src/main/scala - src/test/scala - - - net.alchim31.maven - scala-maven-plugin - ${scala.plugin.version} - - - - compile - testCompile - - - - -dependencyfile - ${project.build.directory}/.scala_dependencies - - - - - - - - - - 2.12.7 - 3.3.2 - - - diff --git a/pom.xml b/pom.xml index 15a9170672..890c1e6c58 100644 --- a/pom.xml +++ b/pom.xml @@ -385,7 +385,6 @@ core-groovy-strings core-java-modules - core-scala couchbase custom-pmd @@ -884,7 +883,6 @@ core-groovy-strings core-java-modules - core-scala couchbase custom-pmd From 2ba52a7def5b59987faffbb235c3032bad4cbb27 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 28 Nov 2020 17:51:32 +0530 Subject: [PATCH 251/590] Update README.md Fixed ReadMe link --- spring-mvc-basics/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-mvc-basics/README.md b/spring-mvc-basics/README.md index c1f8bbda70..dea18a1619 100644 --- a/spring-mvc-basics/README.md +++ b/spring-mvc-basics/README.md @@ -8,7 +8,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Spring MVC Tutorial](https://www.baeldung.com/spring-mvc-tutorial) -- [An Intro to the Spring DispatcherServlet] (https://www.baeldung.com/spring-dispatcherservlet) +- [An Intro to the Spring DispatcherServlet](https://www.baeldung.com/spring-dispatcherservlet) - [The Spring @Controller and @RestController Annotations](https://www.baeldung.com/spring-controller-vs-restcontroller) - [A Guide to the ViewResolver in Spring MVC](https://www.baeldung.com/spring-mvc-view-resolver-tutorial) - [Guide to Spring Handler Mappings](https://www.baeldung.com/spring-handler-mappings) @@ -18,4 +18,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Using Spring @ResponseStatus to Set HTTP Status Code](https://www.baeldung.com/spring-response-status) - [Spring MVC and the @ModelAttribute Annotation](https://www.baeldung.com/spring-mvc-and-the-modelattribute-annotation) - [The HttpMediaTypeNotAcceptableException in Spring MVC](https://www.baeldung.com/spring-httpmediatypenotacceptable) -- More articles: [[more -->]](/spring-mvc-basics-2) \ No newline at end of file +- More articles: [[more -->]](/spring-mvc-basics-2) From f3d390b6844ad2374d0aaa477a5e7c465578b890 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Sat, 28 Nov 2020 14:14:20 +0100 Subject: [PATCH 252/590] initial commit --- spring-cloud/spring-cloud-eureka/pom.xml | 1 + .../pom.xml | 86 +++++++++++++++++++ .../baeldung/spring/cloud/Application.java | 15 ++++ .../spring/cloud/client/BooksClient.java | 16 ++++ .../com/baeldung/spring/cloud/model/Book.java | 15 ++++ .../src/main/resources/application.yml | 12 +++ .../client/BooksClientIntegrationTest.java | 49 +++++++++++ .../cloud/client/EurekaContainerConfig.java | 34 ++++++++ .../client/GreetingClientIntegrationTest.java | 54 ++++++++++++ .../cloud/client/MockBookServiceConfig.java | 31 +++++++ .../spring/cloud/client/WireMockConfig.java | 29 +++++++ .../src/test/resources/application-test.yml | 21 +++++ .../resources/payload/get-books-response.json | 10 +++ 13 files changed, 373 insertions(+) create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/Application.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/client/BooksClient.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/model/Book.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/resources/application.yml create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/GreetingClientIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/MockBookServiceConfig.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index 7af0c15352..9d7350e774 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -19,6 +19,7 @@ spring-cloud-eureka-server spring-cloud-eureka-client spring-cloud-eureka-feign-client + spring-cloud-eureka-feign-client-integration-test diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml new file mode 100644 index 0000000000..09edb89dfe --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + spring-cloud-eureka-feign-client-integration-test + 1.0.0-SNAPSHOT + spring-cloud-eureka-feign-client-integration-test + jar + Spring Cloud Eureka - Feign Client Integration Tests + + + com.baeldung.spring.cloud + spring-cloud-eureka + 1.0.0-SNAPSHOT + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + org.springframework.cloud + spring-cloud-starter-parent + ${spring-cloud-dependencies.version} + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + com.github.tomakehurst + wiremock + 2.27.2 + test + + + + + org.projectlombok + lombok + + + + org.testcontainers + testcontainers + 1.14.3 + test + + + + org.awaitility + awaitility + 4.0.3 + test + + + + + + diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/Application.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/Application.java new file mode 100644 index 0000000000..342e7e163b --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/Application.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@EnableFeignClients +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/client/BooksClient.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/client/BooksClient.java new file mode 100644 index 0000000000..b3abe58e3c --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/client/BooksClient.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.client; + +import com.baeldung.spring.cloud.model.Book; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.List; + +//@FeignClient(value="simple-books-client", url="${book.service.url}") +@FeignClient("books-client") +public interface BooksClient { + + @RequestMapping("/books") + List getBooks(); + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/model/Book.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/model/Book.java new file mode 100644 index 0000000000..64492f678d --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/java/com/baeldung/spring/cloud/model/Book.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloud.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Book { + + private String title; + private String author; + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/resources/application.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/resources/application.yml new file mode 100644 index 0000000000..dba4752ef9 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/main/resources/application.yml @@ -0,0 +1,12 @@ +#book: +# service: +# url: http://book.service.com + +books-client: + ribbon: + eureka: + enabled: false + listOfServers: http://book.service.com + ServerListRefreshInterval: 15000 + MaxAutoRetries: 3 + retryableStatusCodes: 503, 408 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java new file mode 100644 index 0000000000..594b3e785a --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java @@ -0,0 +1,49 @@ +package com.baeldung.spring.cloud.client; + +import com.baeldung.spring.cloud.Application; +import com.baeldung.spring.cloud.model.Book; +import com.netflix.discovery.EurekaClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Lazy; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.util.List; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@ActiveProfiles("test") +@EnableConfigurationProperties +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {MockBookServiceConfig.class}, initializers = {EurekaContainerConfig.Initializer.class}) +class BooksClientIntegrationTest { + + @Autowired + private BooksClient booksClient; + + @Autowired + @Lazy + private EurekaClient eurekaClient; + + @BeforeEach + void setUp() { + await().atMost(60, SECONDS).until(() -> eurekaClient.getApplications().size() > 0); + } + + @Test + public void whenGetBooks_thenListBooksSizeGreaterThanZero() throws InterruptedException { + List books = booksClient.getBooks(); + + assertTrue(books.size() == 1); + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java new file mode 100644 index 0000000000..3e85a791f7 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java @@ -0,0 +1,34 @@ +package com.baeldung.spring.cloud.client; + +import org.jetbrains.annotations.NotNull; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.lifecycle.Startables; + +import java.util.stream.Stream; + +public class EurekaContainerConfig { + + public static class Initializer implements ApplicationContextInitializer { + + public static GenericContainer eurekaServer + = new GenericContainer("springcloud/eureka") + .withExposedPorts(8761); + + @Override + public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) { + + Startables.deepStart(Stream.of(eurekaServer)).join(); + + TestPropertyValues + .of("eureka.client.serviceUrl.defaultZone=http://localhost:" + eurekaServer.getFirstMappedPort().toString() + "/eureka") + .applyTo(configurableApplicationContext); + + } + + } + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/GreetingClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/GreetingClientIntegrationTest.java new file mode 100644 index 0000000000..c743931dae --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/GreetingClientIntegrationTest.java @@ -0,0 +1,54 @@ +package com.baeldung.spring.cloud.client; + +import com.baeldung.spring.cloud.model.Book; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.util.StreamUtils; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; + +import static org.junit.Assert.assertFalse; + +@SpringBootTest +@ActiveProfiles("test") +@EnableConfigurationProperties +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = {WireMockConfig.class}) +class GreetingClientIntegrationTest { + + @Autowired + private WireMockServer wireMockServer; + + @Autowired + private BooksClient booksClient; + + @BeforeEach + void setUp() throws IOException { + wireMockServer.stubFor(WireMock.get(WireMock.urlEqualTo("/books")) + .willReturn(WireMock.aResponse() + .withStatus(HttpStatus.OK.value()) + .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) + .withBody(StreamUtils.copyToString(getClass().getClassLoader().getResourceAsStream("payload/get-books-response.json"), Charset.defaultCharset())))); + } + + @Test + public void whenGetBooks_thenListBooksSizeGreaterThanZero() { + List books = booksClient.getBooks(); + + assertFalse(books.isEmpty()); + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/MockBookServiceConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/MockBookServiceConfig.java new file mode 100644 index 0000000000..d33c6a311b --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/MockBookServiceConfig.java @@ -0,0 +1,31 @@ +package com.baeldung.spring.cloud.client; + +import com.baeldung.spring.cloud.model.Book; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.netflix.loadbalancer.Server; +import com.netflix.loadbalancer.ServerList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.cloud.netflix.ribbon.StaticServerList; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collections; +import java.util.List; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; + +@Configuration +@EnableAutoConfiguration +@RestController +public class MockBookServiceConfig { + + @RequestMapping("/books") + public List getBooks() { + return Collections.singletonList(new Book("some title", "some author")); + } + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java new file mode 100644 index 0000000000..136dd391ca --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java @@ -0,0 +1,29 @@ +package com.baeldung.spring.cloud.client; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.netflix.loadbalancer.Server; +import com.netflix.loadbalancer.ServerList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.cloud.netflix.ribbon.StaticServerList; +import org.springframework.context.annotation.Bean; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; + +@TestConfiguration +public class WireMockConfig { + + @Autowired + private WireMockServer wireMockServer; + + @Bean(initMethod = "start", destroyMethod = "stop") + public WireMockServer booksMockService() { + return new WireMockServer(options().dynamicPort()); + } + + @Bean + public ServerList ribbonServerList() { + return new StaticServerList<>(new Server("localhost", wireMockServer.port())); + } + +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml new file mode 100644 index 0000000000..3e04a54cbc --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml @@ -0,0 +1,21 @@ +#book: +# service: +# url: http://localhost:9561 + +#books-client: +# ribbon: +# listOfServers: http://localhost:9561 + +spring: + application: + name: books-client + +server: + port: 0 + +eureka: + client: + serviceUrl: + defaultZone: ${EUREKA_URI:http://localhost:8761/eureka} + instance: + preferIpAddress: true \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json new file mode 100644 index 0000000000..373dc15926 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json @@ -0,0 +1,10 @@ +[ + { + "title": "Dune", + "author": "Frank Herbert" + }, + { + "title": "Foundation", + "author": "Isaac Asimov" + } +] \ No newline at end of file From 23c81c0595542161f27d39f95b91a5d8003b72ea Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 28 Nov 2020 10:57:31 -0300 Subject: [PATCH 253/590] added test for adding configuration properties scenarios --- ...itionalPropertiesFilesIntegrationTest.java | 29 +++++++++++++++++++ .../AdditionalPropertiesTestConfig.java | 10 +++++++ .../src/test/resources/additional-application | 7 +++++ .../application.properties | 1 + .../additional-application.properties | 5 ++++ .../additional-application2.properties | 1 + .../src/test/resources/application.properties | 8 ++--- 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesFilesIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesTestConfig.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/additional-application create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/additional-application-properties/application.properties create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/additional-application.properties create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/additional-application2.properties diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesFilesIntegrationTest.java new file mode 100644 index 0000000000..0f1f4e0b13 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesFilesIntegrationTest.java @@ -0,0 +1,29 @@ +package com.baeldung.properties.additionalproperties; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("default") +@SpringBootTest(classes = { AdditionalPropertiesTestConfig.class }) +public class AdditionalPropertiesFilesIntegrationTest { + + Logger logger = LoggerFactory.getLogger(AdditionalPropertiesFilesIntegrationTest.class); + + @Value("${baeldung.additionalProperty}") + private String additionalProperty; + + @Value("${baeldung.otherProperty}") + private String otherProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(additionalProperty).isEqualTo("additionalValue2"); + assertThat(otherProperty).isEqualTo("latterValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesTestConfig.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesTestConfig.java new file mode 100644 index 0000000000..9b3483a6c1 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/additionalproperties/AdditionalPropertiesTestConfig.java @@ -0,0 +1,10 @@ +package com.baeldung.properties.additionalproperties; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.properties.additionalproperties") +public class AdditionalPropertiesTestConfig { + +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application new file mode 100644 index 0000000000..46f3c2b1a3 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application @@ -0,0 +1,7 @@ +baeldung: + additionalProperty: additionalValue + otherProperty: otherValue + +spring: + config: + import: classpath:additional-application2.properties \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application-properties/application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application-properties/application.properties new file mode 100644 index 0000000000..b547d16eff --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application-properties/application.properties @@ -0,0 +1 @@ +baeldung.otherProperty=latterValue diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application.properties new file mode 100644 index 0000000000..2edbe692de --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application.properties @@ -0,0 +1,5 @@ +spring.config.activate.on-profile=test +baeldung.customProperty=valueTest +#--- +spring.config.activate.on-profile=prod +baeldung.customProperty=valueProd \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application2.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application2.properties new file mode 100644 index 0000000000..c6cb95ec5b --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/additional-application2.properties @@ -0,0 +1 @@ +baeldung.additionalProperty=additionalValue2 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties index c3a98b3da4..3f6c678b97 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties @@ -2,14 +2,10 @@ management.endpoints.web.exposure.include=refresh spring.properties.refreshDelay=1000 spring.config.location=file:extra.properties spring.main.allow-bean-definition-overriding=true +spring.config.import=classpath:additional-application.properties,classpath:additional-application[.yml],optional:file:./external.properties,classpath:additional-application-properties/ baeldung.customProperty=valueDefault #--- spring.config.activate.on-profile=dev baeldung.customProperty=valueDev -#--- -spring.config.activate.on-profile=test -baeldung.customProperty=valueTest -#--- -spring.config.activate.on-profile=prod -baeldung.customProperty=valueProd + From 9ef57e302749308afe709f68c45b58c17d73ca7b Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Sat, 28 Nov 2020 21:56:57 +0100 Subject: [PATCH 254/590] BAEL-3630 Improve article "Spring Security Context Propagation with @Async" (#10284) * BAEL-3630 Improve article "Spring Security Context Propagation with @Async" * BAEL-3630 Improve article "Spring Security Context Propagation with @Async" Co-authored-by: Krzysztof Majewski --- .../baeldung/security/SecurityJavaConfig.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java b/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java index d20198c2bb..7f0b20ea34 100644 --- a/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java +++ b/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java @@ -7,14 +7,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; @Configuration @@ -34,11 +35,6 @@ public class SecurityJavaConfig extends WebSecurityConfigurerAdapter { private SimpleUrlAuthenticationFailureHandler myFailureHandler = new SimpleUrlAuthenticationFailureHandler(); - public SecurityJavaConfig() { - super(); - SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); - } - @Override protected void configure(final AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() @@ -77,4 +73,18 @@ public class SecurityJavaConfig extends WebSecurityConfigurerAdapter { return new BCryptPasswordEncoder(); } + @Bean + public ThreadPoolTaskExecutor threadPoolTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(10); + executor.setMaxPoolSize(100); + executor.setQueueCapacity(50); + executor.setThreadNamePrefix("async-"); + return executor; + } + + @Bean + public DelegatingSecurityContextAsyncTaskExecutor taskExecutor(ThreadPoolTaskExecutor delegate) { + return new DelegatingSecurityContextAsyncTaskExecutor(delegate); + } } \ No newline at end of file From e67b1f95a87a532ce8a9710add1553c43df527d5 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Sat, 28 Nov 2020 23:38:06 +0100 Subject: [PATCH 255/590] solve port conflict during integration tests --- .../pom.xml | 12 ++++++++++++ .../spring/cloud/client/EurekaContainerConfig.java | 4 ++++ .../LoadBalancerBooksClientIntegrationTest.java | 2 +- .../spring/cloud/client/RibbonTestConfig.java | 9 ++++++++- ... ServiceDiscoveryBooksClientIntegrationTest.java} | 2 +- .../baeldung/spring/cloud/client/WireMockConfig.java | 2 ++ .../src/test/resources/application-ribbon-test.yml | 3 +++ 7 files changed, 31 insertions(+), 3 deletions(-) rename spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/{EurekaBooksClientIntegrationTest.java => ServiceDiscoveryBooksClientIntegrationTest.java} (97%) create mode 100644 spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml index 90aae719d6..3348dbb24f 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml @@ -82,4 +82,16 @@ + + + + maven-surefire-plugin + + 1 + true + + + + + diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java index ed004e43d2..6747d14b88 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaContainerConfig.java @@ -1,14 +1,18 @@ package com.baeldung.spring.cloud.client; import org.jetbrains.annotations.NotNull; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ActiveProfiles; import org.testcontainers.containers.GenericContainer; import org.testcontainers.lifecycle.Startables; import java.util.stream.Stream; +@TestConfiguration +@ActiveProfiles("eureka-test") public class EurekaContainerConfig { public static class Initializer implements ApplicationContextInitializer { diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java index d3284fa197..46159d53a9 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java @@ -22,7 +22,7 @@ import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest -@ActiveProfiles("test") +@ActiveProfiles("ribbon-test") @EnableConfigurationProperties @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { RibbonTestConfig.class }) diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/RibbonTestConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/RibbonTestConfig.java index ac3bae1a3d..273ba182b1 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/RibbonTestConfig.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/RibbonTestConfig.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.cloud.netflix.ribbon.StaticServerList; import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ActiveProfiles; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; @TestConfiguration -public class RibbonTestConfig extends WireMockConfig { +@ActiveProfiles("ribbon-test") +public class RibbonTestConfig { @Autowired private WireMockServer mockBooksService; @@ -19,6 +21,11 @@ public class RibbonTestConfig extends WireMockConfig { @Autowired private WireMockServer secondMockBooksService; + @Bean(initMethod = "start", destroyMethod = "stop") + public WireMockServer mockBooksService() { + return new WireMockServer(options().dynamicPort()); + } + @Bean(name="secondMockBooksService", initMethod = "start", destroyMethod = "stop") public WireMockServer secondBooksMockService() { return new WireMockServer(options().dynamicPort()); diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaBooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java similarity index 97% rename from spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaBooksClientIntegrationTest.java rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java index 89f598ba56..f2c3fde469 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/EurekaBooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ContextConfiguration(classes = { MockBookServiceConfig.class }, initializers = { EurekaContainerConfig.Initializer.class }) -class EurekaBooksClientIntegrationTest { +class ServiceDiscoveryBooksClientIntegrationTest { @Autowired private BooksClient booksClient; diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java index 30421abc78..82b7cddede 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/WireMockConfig.java @@ -3,8 +3,10 @@ package com.baeldung.spring.cloud.client; import com.github.tomakehurst.wiremock.WireMockServer; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ActiveProfiles; @TestConfiguration +@ActiveProfiles("test") public class WireMockConfig { @Bean(initMethod = "start", destroyMethod = "stop") diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml new file mode 100644 index 0000000000..5fde57fd8a --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml @@ -0,0 +1,3 @@ +eureka: + client: + enabled: false \ No newline at end of file From b6ff72353300feea81dccebecdf617c118ee2079 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Sat, 28 Nov 2020 23:44:06 +0100 Subject: [PATCH 256/590] add newlines at end of files --- .../spring/cloud/client/BooksClientIntegrationTest.java | 2 +- .../cloud/client/LoadBalancerBooksClientIntegrationTest.java | 2 +- .../client/ServiceDiscoveryBooksClientIntegrationTest.java | 2 +- .../src/test/resources/application-eureka-test.yml | 2 +- .../src/test/resources/application-ribbon-test.yml | 2 +- .../src/test/resources/application-test.yml | 2 +- .../src/test/resources/payload/get-books-response.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java index b1df99ee5e..2842eef435 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BooksClientIntegrationTest.java @@ -50,4 +50,4 @@ class BooksClientIntegrationTest { new Book("Foundation", "Isaac Asimov")))); } -} \ No newline at end of file +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java index 46159d53a9..f05df11ba3 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/LoadBalancerBooksClientIntegrationTest.java @@ -62,4 +62,4 @@ class LoadBalancerBooksClientIntegrationTest { new Book("Dune", "Frank Herbert"), new Book("Foundation", "Isaac Asimov")))); } -} \ No newline at end of file +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java index f2c3fde469..027579d20d 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java @@ -49,4 +49,4 @@ class ServiceDiscoveryBooksClientIntegrationTest { books.stream().findFirst().get()); } -} \ No newline at end of file +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-eureka-test.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-eureka-test.yml index c34a79c838..6f6af6a080 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-eureka-test.yml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-eureka-test.yml @@ -1,3 +1,3 @@ spring: application: - name: books-service \ No newline at end of file + name: books-service diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml index 5fde57fd8a..84a78d0ec7 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-ribbon-test.yml @@ -1,3 +1,3 @@ eureka: client: - enabled: false \ No newline at end of file + enabled: false diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml index b5a318c659..dce11adf69 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/application-test.yml @@ -8,4 +8,4 @@ books-service: eureka: client: - enabled: false \ No newline at end of file + enabled: false diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json index 373dc15926..b4223ff8f2 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/resources/payload/get-books-response.json @@ -7,4 +7,4 @@ "title": "Foundation", "author": "Isaac Asimov" } -] \ No newline at end of file +] From 5274cf403f7c18a93fb622c8351650cf8edecdf3 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sun, 29 Nov 2020 11:46:11 +0330 Subject: [PATCH 257/590] remove try/catch block and add throw clause --- .../main/java/com/baeldung/aes/AESUtil.java | 218 +++++++----------- 1 file changed, 85 insertions(+), 133 deletions(-) diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java index 361f09f1cb..2952eef625 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java @@ -1,8 +1,5 @@ package com.baeldung.aes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; @@ -28,36 +25,25 @@ import java.security.spec.KeySpec; import java.util.Base64; public class AESUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(AESUtil.class); - public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.ENCRYPT_MODE, key, iv); - byte[] cipherText = cipher.doFinal(input.getBytes()); - return Base64.getEncoder() - .encodeToString(cipherText); - } catch (NoSuchAlgorithmException | NoSuchPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - IllegalBlockSizeException | BadPaddingException exp) { - LOGGER.error(exp.getMessage()); - } - return null; + public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) + throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, + InvalidKeyException, BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + byte[] cipherText = cipher.doFinal(input.getBytes()); + return Base64.getEncoder() + .encodeToString(cipherText); } - public static String decrypt(String algorithm, String cipherText, SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.DECRYPT_MODE, key, iv); - byte[] plainText = cipher.doFinal(Base64.getDecoder() - .decode(cipherText)); - return new String(plainText); - } catch (NoSuchAlgorithmException | NoSuchPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - IllegalBlockSizeException | BadPaddingException exp) { - LOGGER.error(exp.getMessage()); - } - return null; + public static String decrypt(String algorithm, String cipherText, SecretKey key, IvParameterSpec iv) + throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, + InvalidKeyException, BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + byte[] plainText = cipher.doFinal(Base64.getDecoder() + .decode(cipherText)); + return new String(plainText); } public static SecretKey generateKey(int n) throws NoSuchAlgorithmException { @@ -83,122 +69,88 @@ public class AESUtil { } public static void encryptFile(String algorithm, SecretKey key, IvParameterSpec iv, - File inputFile, File outputFile) throws IOException { - FileInputStream inputStream = null; - FileOutputStream outputStream = null; - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.ENCRYPT_MODE, key, iv); - inputStream = new FileInputStream(inputFile); - outputStream = new FileOutputStream(outputFile); - byte[] buffer = new byte[64]; - int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) { - byte[] output = cipher.update(buffer, 0, bytesRead); - if (output != null) { - outputStream.write(output); - } - } - byte[] outputBytes = cipher.doFinal(); - if (outputBytes != null) { - outputStream.write(outputBytes); - } - } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | - NoSuchPaddingException | BadPaddingException | - IllegalBlockSizeException | InvalidKeyException exp) { - LOGGER.error(exp.getMessage()); - } finally { - inputStream.close(); - outputStream.close(); - } - } - - public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv, - File encryptedFile, File decryptedFile) throws IOException { - FileInputStream inputStream = null; - FileOutputStream outputStream = null; - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.DECRYPT_MODE, key, iv); - inputStream = new FileInputStream(encryptedFile); - outputStream = new FileOutputStream(decryptedFile); - byte[] buffer = new byte[64]; - int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) { - byte[] output = cipher.update(buffer, 0, bytesRead); - if (output != null) { - outputStream.write(output); - } - } - byte[] output = cipher.doFinal(); + File inputFile, File outputFile) throws IOException, NoSuchPaddingException, + NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, + BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + FileInputStream inputStream = new FileInputStream(inputFile); + FileOutputStream outputStream = new FileOutputStream(outputFile); + byte[] buffer = new byte[64]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + byte[] output = cipher.update(buffer, 0, bytesRead); if (output != null) { outputStream.write(output); } - } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | - NoSuchPaddingException | BadPaddingException | - IllegalBlockSizeException | InvalidKeyException exp) { - LOGGER.error(exp.getMessage()); - } finally { - inputStream.close(); - outputStream.close(); } + byte[] outputBytes = cipher.doFinal(); + if (outputBytes != null) { + outputStream.write(outputBytes); + } + inputStream.close(); + outputStream.close(); } - public static SealedObject encryptObject(String algorithm, Serializable object, SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.ENCRYPT_MODE, key, iv); - SealedObject sealedObject = new SealedObject(object, cipher); - return sealedObject; - } catch (NoSuchAlgorithmException | NoSuchPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - IOException | IllegalBlockSizeException exp) { - LOGGER.error(exp.getMessage()); + public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv, + File encryptedFile, File decryptedFile) throws IOException, NoSuchPaddingException, + NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, + BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + FileInputStream inputStream = new FileInputStream(encryptedFile); + FileOutputStream outputStream = new FileOutputStream(decryptedFile); + byte[] buffer = new byte[64]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + byte[] output = cipher.update(buffer, 0, bytesRead); + if (output != null) { + outputStream.write(output); + } } - return null; + byte[] output = cipher.doFinal(); + if (output != null) { + outputStream.write(output); + } + inputStream.close(); + outputStream.close(); } - public static Serializable decryptObject(String algorithm, SealedObject sealedObject, - SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.DECRYPT_MODE, key, iv); - Serializable unsealObject = (Serializable) sealedObject.getObject(cipher); - return unsealObject; - } catch (NoSuchAlgorithmException | NoSuchPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - IOException | ClassNotFoundException | IllegalBlockSizeException | BadPaddingException exp) { - LOGGER.error(exp.getMessage()); - } - return null; + public static SealedObject encryptObject(String algorithm, Serializable object, SecretKey key, + IvParameterSpec iv) throws NoSuchPaddingException, NoSuchAlgorithmException, + InvalidAlgorithmParameterException, InvalidKeyException, IOException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + SealedObject sealedObject = new SealedObject(object, cipher); + return sealedObject; } - public static String encryptPasswordBased(String plainText, SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, key, iv); - return Base64.getEncoder() - .encodeToString(cipher.doFinal(plainText.getBytes())); - } catch (NoSuchAlgorithmException | BadPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - NoSuchPaddingException | IllegalBlockSizeException exp) { - LOGGER.error(exp.getMessage()); - } - return null; + public static Serializable decryptObject(String algorithm, SealedObject sealedObject, SecretKey key, + IvParameterSpec iv) throws NoSuchPaddingException, NoSuchAlgorithmException, + InvalidAlgorithmParameterException, InvalidKeyException, ClassNotFoundException, + BadPaddingException, IllegalBlockSizeException, IOException { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + Serializable unsealObject = (Serializable) sealedObject.getObject(cipher); + return unsealObject; } - public static String decryptPasswordBased(String cipherText, SecretKey key, IvParameterSpec iv) { - try { - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - cipher.init(Cipher.DECRYPT_MODE, key, iv); - return new String(cipher.doFinal(Base64.getDecoder() - .decode(cipherText))); - } catch (NoSuchAlgorithmException | BadPaddingException | - InvalidKeyException | InvalidAlgorithmParameterException | - NoSuchPaddingException | IllegalBlockSizeException exp) { - LOGGER.error(exp.getMessage()); - } - return null; + public static String encryptPasswordBased(String plainText, SecretKey key, IvParameterSpec iv) + throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, + InvalidKeyException, BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, iv); + return Base64.getEncoder() + .encodeToString(cipher.doFinal(plainText.getBytes())); + } + + public static String decryptPasswordBased(String cipherText, SecretKey key, IvParameterSpec iv) + throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, + InvalidKeyException, BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + cipher.init(Cipher.DECRYPT_MODE, key, iv); + return new String(cipher.doFinal(Base64.getDecoder() + .decode(cipherText))); } } From a8b42068a94553ecd733d36f19b80949e880db05 Mon Sep 17 00:00:00 2001 From: sharifi Date: Sun, 29 Nov 2020 11:46:34 +0330 Subject: [PATCH 258/590] add throw clause --- .../com/baeldung/aes/AESUtilUnitTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java index 78543d0abc..531c20ca79 100644 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -7,16 +7,23 @@ import org.junit.jupiter.api.Test; import javax.crypto.SealedObject; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import java.io.File; import java.io.IOException; import java.nio.file.Paths; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; class AESUtilUnitTest implements WithAssertions { @Test - void givenString_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException { + void givenString_whenEncrypt_thenSuccess() + throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, + BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { // given String input = "baeldung"; SecretKey key = AESUtil.generateKey(128); @@ -32,7 +39,9 @@ class AESUtilUnitTest implements WithAssertions { } @Test - void givenFile_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException, IOException { + void givenFile_whenEncrypt_thenSuccess() + throws NoSuchAlgorithmException, IOException, IllegalBlockSizeException, InvalidKeyException, + BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { // given SecretKey key = AESUtil.generateKey(128); String algorithm = "AES/CBC/PKCS5Padding"; @@ -53,7 +62,10 @@ class AESUtilUnitTest implements WithAssertions { } @Test - void givenObject_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException { + void givenObject_whenEncrypt_thenSuccess() + throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, + InvalidAlgorithmParameterException, NoSuchPaddingException, IOException, BadPaddingException, + ClassNotFoundException { // given Student student = new Student("Baeldung", 20); SecretKey key = AESUtil.generateKey(128); @@ -69,7 +81,9 @@ class AESUtilUnitTest implements WithAssertions { } @Test - void givenPassword_whenEncrypt_thenSuccess() throws InvalidKeySpecException, NoSuchAlgorithmException { + void givenPassword_whenEncrypt_thenSuccess() + throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { // given String plainText = "www.baeldung.com"; String password = "baeldung"; From 074d016b64ee598e6ad00a1dd856d803cbeef591 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 30 Nov 2020 07:12:58 +0530 Subject: [PATCH 259/590] BAEL-4686: Review comments implemented --- .../core-java-collections-maps-3/pom.xml | 6 +- .../MapPerformanceComparison.java | 96 +++++++++++ .../ConcurrentModificationErrorTest.java | 41 ----- .../concurrenthashmap/NullAllowInMapTest.java | 27 --- .../concurrenthashmap/PerformanceTest.java | 158 ------------------ 5 files changed, 101 insertions(+), 227 deletions(-) create mode 100644 core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java delete mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java delete mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java delete mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java diff --git a/core-java-modules/core-java-collections-maps-3/pom.xml b/core-java-modules/core-java-collections-maps-3/pom.xml index f547968b22..577ad58255 100644 --- a/core-java-modules/core-java-collections-maps-3/pom.xml +++ b/core-java-modules/core-java-collections-maps-3/pom.xml @@ -15,7 +15,11 @@ - + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java new file mode 100644 index 0000000000..c788dbc27d --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java @@ -0,0 +1,96 @@ +package com.baeldung.map.concurrenthashmap; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; + +@Fork(5) +@Threads(10) +@Warmup(iterations = 5) +@State(Scope.Benchmark) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +public class MapPerformanceComparison { + + private int TEST_NO_ITEMS; + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } + + @Setup + public void setup() { + TEST_NO_ITEMS = 1000; + } + + @Benchmark + public void randomReadAndWriteSynchronizedMap() { + Map map = Collections.synchronizedMap(new HashMap()); + performReadAndWriteTest(map); + } + + @Benchmark + public void randomReadAndWriteConcurrentHashMap() { + Map map = new ConcurrentHashMap<>(); + performReadAndWriteTest(map); + } + + private void performReadAndWriteTest(final Map map) { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.get(String.valueOf(randNumber)); + map.put(String.valueOf(randNumber), randNumber); + } + } + + @Benchmark + public void randomWriteSynchronizedMap() { + Map map = Collections.synchronizedMap(new HashMap()); + performWriteTest(map); + } + + @Benchmark + public void randomWriteConcurrentHashMap() { + Map map = new ConcurrentHashMap<>(); + performWriteTest(map); + } + + private void performWriteTest(final Map map) { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.put(String.valueOf(randNumber), randNumber); + } + } + + @Benchmark + public void randomReadSynchronizedMap() { + Map map = Collections.synchronizedMap(new HashMap()); + performReadTest(map); + } + + @Benchmark + public void randomReadConcurrentHashMap() { + Map map = new ConcurrentHashMap<>(); + performReadTest(map); + } + + private void performReadTest(final Map map) { + for (int i = 0; i < TEST_NO_ITEMS; i++) { + Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); + map.get(String.valueOf(randNumber)); + } + } +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java deleted file mode 100644 index 998496720e..0000000000 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.map.concurrenthashmap; - -import java.util.Collections; -import java.util.ConcurrentModificationException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Assert; -import org.junit.Test; - -public class ConcurrentModificationErrorTest { - - @Test(expected = ConcurrentModificationException.class) - public void whenRemoveAndAddOnHashMap_thenConcurrentModificationError() { - Map map = new HashMap<>(); - map.put(1, "baeldung"); - map.put(2, "HashMap"); - Map synchronizedMap = Collections.synchronizedMap(map); - Iterator> iterator = synchronizedMap.entrySet().iterator(); - while (iterator.hasNext()) { - synchronizedMap.put(4, "Modification"); - iterator.next(); - } - } - - public void whenRemoveAndAddOnConcurrentHashMap_thenNoError() { - Map map = new ConcurrentHashMap<>(); - map.put(1, "baeldung"); - map.put(2, "HashMap"); - Iterator> iterator = map.entrySet().iterator(); - while (iterator.hasNext()) { - map.put(4, "Modification"); - iterator.next(); - } - - Assert.assertEquals(4, map.size()); - } -} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java deleted file mode 100644 index 23c76e59e8..0000000000 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.map.concurrenthashmap; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Assert; -import org.junit.Test; - -public class NullAllowInMapTest { - - @Test - public void allowOnlyNull_In_SynchronizedMap() { - Map map = Collections - .synchronizedMap(new HashMap()); - map.put(null, 1); - Assert.assertTrue(map.get(null).equals(1)); - } - - @Test(expected = NullPointerException.class) - public void allowOnlyNull_In_ConcurrentHasMap() { - Map map = new ConcurrentHashMap<>(); - map.put(null, 1); - } - -} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java deleted file mode 100644 index 5321d33b36..0000000000 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/PerformanceTest.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.baeldung.map.concurrenthashmap; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.junit.Assert; -import org.junit.Test; - -public class PerformanceTest { - - public final static int THREAD_POOL_SIZE = 5; - public final static int TEST_ITERATIONS = 5; - public final static int TEST_NO_ITEMS = 10000; - - @Test - public void randomReadAndWritePerformaceTest_ConcurrentHashMap_faster() - throws InterruptedException { - // For synchronizedMap - Long totalTimeForSynchronizedMap = 0l; - Map slowerMap = Collections - .synchronizedMap(new HashMap()); - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForSynchronizedMap += performReadAndWriteTest(slowerMap); - } - Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; - - // For ConcurrentHashMap Object - Long totalTimeForConcurrentHashMap = 0l; - Map fasterMap = new ConcurrentHashMap<>(); - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForConcurrentHashMap += performReadAndWriteTest(fasterMap); - } - Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); - } - - private long performReadAndWriteTest(final Map map) - throws InterruptedException { - long startTime = System.nanoTime(); - ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); - for (int j = 0; j < THREAD_POOL_SIZE; j++) { - exectures.execute(new Runnable() { - @Override - public void run() { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.get(String.valueOf(randNumber)); - map.put(String.valueOf(randNumber), randNumber); - } - } - }); - } - exectures.shutdown(); - exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - long entTime = System.nanoTime(); - return (entTime - startTime) / 1000000L; - } - - @Test - public void randomWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { - // For synchronizedMap - Long totalTimeForSynchronizedMap = 0l; - Map slowerMap = Collections - .synchronizedMap(new HashMap()); - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForSynchronizedMap += performWriteTest(slowerMap); - } - Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; - - // For ConcurrentHashMap Object - Long totalTimeForConcurrentHashMap = 0l; - Map fasterMap = new ConcurrentHashMap<>(); - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForConcurrentHashMap += performWriteTest(fasterMap); - } - Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); - } - - private long performWriteTest(final Map map) throws InterruptedException { - long startTime = System.nanoTime(); - ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); - for (int j = 0; j < THREAD_POOL_SIZE; j++) { - exectures.execute(new Runnable() { - @Override - public void run() { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.put(String.valueOf(randNumber), randNumber); - } - } - }); - } - exectures.shutdown(); - exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - long entTime = System.nanoTime(); - return (entTime - startTime) / 1000000L; - } - - @Test - public void randomReadPerformaceTest_ConcurrentHashMap_faster() throws InterruptedException { - - Map slowerMap = Collections - .synchronizedMap(addItems(new HashMap())); - // For synchronizedMap - Long totalTimeForSynchronizedMap = 0l; - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForSynchronizedMap += performReadTest(slowerMap); - } - Long avgTimeForSynchronizedMap = totalTimeForSynchronizedMap / TEST_ITERATIONS; - - Map fasterMap = addItems(new ConcurrentHashMap()); - // For ConcurrentHashMap Object - Long totalTimeForConcurrentHashMap = 0l; - new ConcurrentHashMap<>(); - for (int i = 0; i < TEST_ITERATIONS; i++) { - totalTimeForConcurrentHashMap += performReadTest(fasterMap); - } - Long avgTimeForConcurrentHashMap = totalTimeForConcurrentHashMap / TEST_ITERATIONS; - - Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap); - } - - private Map addItems(Map map) { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.put(String.valueOf(randNumber), randNumber); - } - return map; - } - - private long performReadTest(final Map map) throws InterruptedException { - long startTime = System.nanoTime(); - ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE); - for (int j = 0; j < THREAD_POOL_SIZE; j++) { - exectures.execute(new Runnable() { - @Override - public void run() { - for (int i = 0; i < TEST_NO_ITEMS; i++) { - Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS); - map.get(String.valueOf(randNumber)); - } - } - }); - } - exectures.shutdown(); - exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - long entTime = System.nanoTime(); - return (entTime - startTime) / 1000000L; - } -} \ No newline at end of file From 993f2baeea0bbe3348eaac6406c5106460e7ea7a Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 30 Nov 2020 07:25:51 +0530 Subject: [PATCH 260/590] Added changes based on review comments --- .../ConcurrentModificationErrorUnitTest.java | 41 +++++++++++++++++++ .../NullAllowInMapUnitTest.java | 40 ++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java new file mode 100644 index 0000000000..899c902fb0 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.map.concurrenthashmap; + +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.Assert; +import org.junit.Test; + +public class ConcurrentModificationErrorUnitTest { + + @Test(expected = ConcurrentModificationException.class) + public void whenRemoveAndAddOnHashMap_thenConcurrentModificationError() { + Map map = new HashMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Map synchronizedMap = Collections.synchronizedMap(map); + Iterator> iterator = synchronizedMap.entrySet().iterator(); + while (iterator.hasNext()) { + synchronizedMap.put(3, "Modification"); + iterator.next(); + } + } + + public void whenRemoveAndAddOnConcurrentHashMap_thenNoError() { + Map map = new ConcurrentHashMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Iterator> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + map.put(3, "Modification"); + iterator.next(); + } + + Assert.assertEquals(3, map.size()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java new file mode 100644 index 0000000000..60e293f4b3 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.map.concurrenthashmap; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.Assert; +import org.junit.Test; + +public class NullAllowInMapUnitTest { + + @Test + public void allowNullKey_In_SynchronizedMap() { + Map map = Collections + .synchronizedMap(new HashMap()); + map.put(null, 1); + Assert.assertTrue(map.get(null).equals(1)); + } + + @Test(expected = NullPointerException.class) + public void allowNullKey_In_ConcurrentHasMap() { + Map map = new ConcurrentHashMap<>(); + map.put(null, 1); + } + + @Test + public void allowNullValue_In_SynchronizedMap() { + Map map = Collections.synchronizedMap(new HashMap()); + map.put("1", null); + Assert.assertNull(map.get("1")); + } + + @Test(expected = NullPointerException.class) + public void allowNullValue_In_ConcurrentHasMap() { + Map map = new ConcurrentHashMap<>(); + map.put("1", null); + } + +} \ No newline at end of file From 06bebff4cbe64a12cc71dfc314155f6a8dd307c6 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Tue, 1 Dec 2020 08:18:26 +0100 Subject: [PATCH 261/590] BAEL-4706 - Spring Boot with Spring Batch (#10292) Co-authored-by: Jonathan Cook --- pom.xml | 3 +- spring-batch-2/pom.xml | 57 +++++++++++++ .../baeldung/batch/BatchConfiguration.java | 81 +++++++++++++++++++ .../main/java/com/baeldung/batch/Coffee.java | 47 +++++++++++ .../baeldung/batch/CoffeeItemProcessor.java | 24 ++++++ .../JobCompletionNotificationListener.java | 34 ++++++++ .../SpringBootBatchProcessingApplication.java | 13 +++ .../src/main/resources/application.properties | 1 + .../src/main/resources/coffee-list.csv | 3 + spring-batch-2/src/main/resources/logback.xml | 13 +++ .../src/main/resources/schema-all.sql | 8 ++ .../batch/SpringBootBatchIntegrationTest.java | 49 +++++++++++ 12 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 spring-batch-2/pom.xml create mode 100644 spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java create mode 100644 spring-batch-2/src/main/java/com/baeldung/batch/Coffee.java create mode 100644 spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java create mode 100644 spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java create mode 100644 spring-batch-2/src/main/java/com/baeldung/batch/SpringBootBatchProcessingApplication.java create mode 100644 spring-batch-2/src/main/resources/application.properties create mode 100644 spring-batch-2/src/main/resources/coffee-list.csv create mode 100644 spring-batch-2/src/main/resources/logback.xml create mode 100644 spring-batch-2/src/main/resources/schema-all.sql create mode 100644 spring-batch-2/src/test/java/com/baeldung/batch/SpringBootBatchIntegrationTest.java diff --git a/pom.xml b/pom.xml index 3fca452552..17e4fe1584 100644 --- a/pom.xml +++ b/pom.xml @@ -617,7 +617,8 @@ spring-aop spring-apache-camel - spring-batch + spring-batch + spring-batch-2 spring-bom spring-boot-modules spring-boot-rest diff --git a/spring-batch-2/pom.xml b/spring-batch-2/pom.xml new file mode 100644 index 0000000000..54df6d43e8 --- /dev/null +++ b/spring-batch-2/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + spring-batch-2 + 0.1-SNAPSHOT + spring-batch-2 + jar + http://maven.apache.org + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-batch + 2.3.6.RELEASE + + + org.hsqldb + hsqldb + ${hsqldb.version} + runtime + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.batch.version} + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.springframework.batch + spring-batch-test + ${spring.batch.test.version} + test + + + + + 2.3.6.RELEASE + 4.2.4.RELEASE + 2.5.1 + + + diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java b/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java new file mode 100644 index 0000000000..0c053dd86c --- /dev/null +++ b/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java @@ -0,0 +1,81 @@ +package com.baeldung.batch; + +import javax.sql.DataSource; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; +import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.launch.support.RunIdIncrementer; +import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider; +import org.springframework.batch.item.database.JdbcBatchItemWriter; +import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder; +import org.springframework.batch.item.file.FlatFileItemReader; +import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder; +import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; + +@Configuration +@EnableBatchProcessing +public class BatchConfiguration { + + @Autowired + public JobBuilderFactory jobBuilderFactory; + + @Autowired + public StepBuilderFactory stepBuilderFactory; + + @Value("${file.input}") + private String fileInput; + + @Bean + public FlatFileItemReader reader() { + return new FlatFileItemReaderBuilder().name("coffeeItemReader") + .resource(new ClassPathResource(fileInput)) + .delimited() + .names(new String[] { "brand", "origin", "characteristics" }) + .fieldSetMapper(new BeanWrapperFieldSetMapper() {{ + setTargetType(Coffee.class); + }}) + .build(); + } + + @Bean + public CoffeeItemProcessor processor() { + return new CoffeeItemProcessor(); + } + + @Bean + public JdbcBatchItemWriter writer(DataSource dataSource) { + return new JdbcBatchItemWriterBuilder().itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>()) + .sql("INSERT INTO coffee (brand, origin, characteristics) VALUES (:brand, :origin, :characteristics)") + .dataSource(dataSource) + .build(); + } + + @Bean + public Job importUserJob(JobCompletionNotificationListener listener, Step step1) { + return jobBuilderFactory.get("importUserJob") + .incrementer(new RunIdIncrementer()) + .listener(listener) + .flow(step1) + .end() + .build(); + } + + @Bean + public Step step1(JdbcBatchItemWriter writer) { + return stepBuilderFactory.get("step1") + . chunk(10) + .reader(reader()) + .processor(processor()) + .writer(writer) + .build(); + } + +} diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/Coffee.java b/spring-batch-2/src/main/java/com/baeldung/batch/Coffee.java new file mode 100644 index 0000000000..4dfcd9959c --- /dev/null +++ b/spring-batch-2/src/main/java/com/baeldung/batch/Coffee.java @@ -0,0 +1,47 @@ +package com.baeldung.batch; + +public class Coffee { + + private String brand; + private String origin; + private String characteristics; + + public Coffee() { + } + + public Coffee(String brand, String origin, String characteristics) { + this.brand = brand; + this.origin = origin; + this.characteristics = characteristics; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + + public String getCharacteristics() { + return characteristics; + } + + public void setCharacteristics(String characteristics) { + this.characteristics = characteristics; + } + + @Override + public String toString() { + return "Coffee [brand=" + getBrand() + ", origin=" + getOrigin() + ", characteristics=" + getCharacteristics() + "]"; + } + +} diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java b/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java new file mode 100644 index 0000000000..b154b80453 --- /dev/null +++ b/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java @@ -0,0 +1,24 @@ +package com.baeldung.batch; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.batch.item.ItemProcessor; + +public class CoffeeItemProcessor implements ItemProcessor { + + private static final Logger LOGGER = LoggerFactory.getLogger(CoffeeItemProcessor.class); + + @Override + public Coffee process(final Coffee coffee) throws Exception { + String brand = coffee.getBrand().toUpperCase(); + String origin = coffee.getOrigin().toUpperCase(); + String chracteristics = coffee.getCharacteristics().toUpperCase(); + + Coffee transformedCoffee = new Coffee(brand, origin, chracteristics); + LOGGER.info("Converting ( {} ) into ( {} )", coffee, transformedCoffee); + + return transformedCoffee; + } + +} diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java b/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java new file mode 100644 index 0000000000..ca1de40aea --- /dev/null +++ b/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java @@ -0,0 +1,34 @@ +package com.baeldung.batch; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.listener.JobExecutionListenerSupport; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; + +@Component +public class JobCompletionNotificationListener extends JobExecutionListenerSupport { + + private static final Logger LOGGER = LoggerFactory.getLogger(JobCompletionNotificationListener.class); + + private final JdbcTemplate jdbcTemplate; + + @Autowired + public JobCompletionNotificationListener(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public void afterJob(JobExecution jobExecution) { + if (jobExecution.getStatus() == BatchStatus.COMPLETED) { + LOGGER.info("!!! JOB FINISHED! Time to verify the results"); + + String query = "SELECT brand, origin, characteristics FROM coffee"; + jdbcTemplate.query(query, (rs, row) -> new Coffee(rs.getString(1), rs.getString(2), rs.getString(3))) + .forEach(coffee -> LOGGER.info("Found < {} > in the database.", coffee)); + } + } +} diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/SpringBootBatchProcessingApplication.java b/spring-batch-2/src/main/java/com/baeldung/batch/SpringBootBatchProcessingApplication.java new file mode 100644 index 0000000000..7682124b8d --- /dev/null +++ b/spring-batch-2/src/main/java/com/baeldung/batch/SpringBootBatchProcessingApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.batch; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootBatchProcessingApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootBatchProcessingApplication.class, args); + } + +} diff --git a/spring-batch-2/src/main/resources/application.properties b/spring-batch-2/src/main/resources/application.properties new file mode 100644 index 0000000000..0b8c56d3f8 --- /dev/null +++ b/spring-batch-2/src/main/resources/application.properties @@ -0,0 +1 @@ +file.input=coffee-list.csv \ No newline at end of file diff --git a/spring-batch-2/src/main/resources/coffee-list.csv b/spring-batch-2/src/main/resources/coffee-list.csv new file mode 100644 index 0000000000..6ceef00556 --- /dev/null +++ b/spring-batch-2/src/main/resources/coffee-list.csv @@ -0,0 +1,3 @@ +Blue Mountain,Jamaica,Fruity +Lavazza,Colombia,Strong +Folgers,America,Smokey \ No newline at end of file diff --git a/spring-batch-2/src/main/resources/logback.xml b/spring-batch-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-batch-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-batch-2/src/main/resources/schema-all.sql b/spring-batch-2/src/main/resources/schema-all.sql new file mode 100644 index 0000000000..9f698f7d81 --- /dev/null +++ b/spring-batch-2/src/main/resources/schema-all.sql @@ -0,0 +1,8 @@ +DROP TABLE coffee IF EXISTS; + +CREATE TABLE coffee ( + coffee_id BIGINT IDENTITY NOT NULL PRIMARY KEY, + brand VARCHAR(20), + origin VARCHAR(20), + characteristics VARCHAR(30) +); \ No newline at end of file diff --git a/spring-batch-2/src/test/java/com/baeldung/batch/SpringBootBatchIntegrationTest.java b/spring-batch-2/src/test/java/com/baeldung/batch/SpringBootBatchIntegrationTest.java new file mode 100644 index 0000000000..ba2b8a6a13 --- /dev/null +++ b/spring-batch-2/src/test/java/com/baeldung/batch/SpringBootBatchIntegrationTest.java @@ -0,0 +1,49 @@ +package com.baeldung.batch; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.ExitStatus; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobInstance; +import org.springframework.batch.test.JobLauncherTestUtils; +import org.springframework.batch.test.JobRepositoryTestUtils; +import org.springframework.batch.test.context.SpringBatchTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.PropertySource; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBatchTest +@SpringBootTest +@DirtiesContext +@PropertySource("classpath:application.properties") +@RunWith(SpringRunner.class) +public class SpringBootBatchIntegrationTest { + + @Autowired + private JobLauncherTestUtils jobLauncherTestUtils; + + @Autowired + private JobRepositoryTestUtils jobRepositoryTestUtils; + + @After + public void cleanUp() { + jobRepositoryTestUtils.removeJobExecutions(); + } + + @Test + public void givenCoffeeList_whenJobExecuted_thenSuccess() throws Exception { + JobExecution jobExecution = jobLauncherTestUtils.launchJob(); + JobInstance jobInstance = jobExecution.getJobInstance(); + ExitStatus jobExitStatus = jobExecution.getExitStatus(); + + assertThat(jobInstance.getJobName(), is("importUserJob")); + assertThat(jobExitStatus.getExitCode(), is("COMPLETED")); + } + +} From cd6f187e0a9ba23bec14e4485a1b9a9c00aeb747 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa <70507913+emyasa@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:22:46 +0800 Subject: [PATCH 262/590] [BAEL-4056] Guide to MultipleBagFetchException (#10294) * Adds Domain Models * Adds Integration Tests --- .../jpa/multiplebagfetchexception/Album.java | 52 ++++++++ .../jpa/multiplebagfetchexception/Artist.java | 56 ++++++++ .../DummyEntity.java | 43 ++++++ .../FavoriteSong.java | 52 ++++++++ .../jpa/multiplebagfetchexception/Offer.java | 46 +++++++ .../multiplebagfetchexception/Playlist.java | 47 +++++++ .../jpa/multiplebagfetchexception/Song.java | 55 ++++++++ .../jpa/multiplebagfetchexception/User.java | 74 +++++++++++ .../main/resources/META-INF/persistence.xml | 23 ++++ ...tipleBagFetchExceptionIntegrationTest.java | 124 ++++++++++++++++++ 10 files changed, 572 insertions(+) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Album.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Artist.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/FavoriteSong.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Offer.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Playlist.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Song.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/User.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Album.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Album.java new file mode 100644 index 0000000000..96615b4ee2 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Album.java @@ -0,0 +1,52 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +@Entity +class Album { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @OneToMany(mappedBy = "album") + private List songs; + + @ManyToMany(mappedBy = "followingAlbums") + private Set followers; + + Album(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Album album = (Album) o; + + return Objects.equals(id, album.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Album() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Artist.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Artist.java new file mode 100644 index 0000000000..b87de27629 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Artist.java @@ -0,0 +1,56 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +@Entity +class Artist { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @OneToMany(mappedBy = "artist") + private List songs; + + @OneToMany(mappedBy = "artist", cascade = CascadeType.PERSIST) + private List offers; + + Artist(String name) { + this.name = name; + this.offers = new ArrayList<>(); + } + + void createOffer(String description) { + this.offers.add(new Offer(description, this)); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Artist artist = (Artist) o; + + return Objects.equals(id, artist.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Artist() { + } +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java new file mode 100644 index 0000000000..8eb9c95724 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java @@ -0,0 +1,43 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.List; +import java.util.Objects; + +@Entity +class DummyEntity { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ElementCollection + private List collection1; + + @ElementCollection + private List collection2; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + DummyEntity that = (DummyEntity) o; + + return Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected DummyEntity() { + } +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/FavoriteSong.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/FavoriteSong.java new file mode 100644 index 0000000000..43bd39487e --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/FavoriteSong.java @@ -0,0 +1,52 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import java.util.Objects; + +@Entity +class FavoriteSong { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne + private Song song; + + @ManyToOne + private User user; + + @Column(name = "arrangement_index", nullable = false) + private int arrangementIndex; + + FavoriteSong(Song song, User user) { + this.song = song; + this.user = user; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + FavoriteSong likedSong = (FavoriteSong) o; + + return Objects.equals(id, likedSong.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected FavoriteSong() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Offer.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Offer.java new file mode 100644 index 0000000000..54f355dfff --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Offer.java @@ -0,0 +1,46 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +class Offer { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @ManyToOne + private Artist artist; + + Offer(String name, Artist artist) { + this.name = name; + this.artist = artist; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Offer offer = (Offer) o; + + return id != null ? id.equals(offer.id) : offer.id == null; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Offer() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Playlist.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Playlist.java new file mode 100644 index 0000000000..7fa96c3355 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Playlist.java @@ -0,0 +1,47 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import java.util.Objects; + +@Entity +class Playlist { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @ManyToOne + private User createdBy; + + Playlist(String name, User createdBy) { + this.name = name; + this.createdBy = createdBy; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Playlist playlist = (Playlist) o; + + return Objects.equals(id, playlist.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Playlist() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Song.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Song.java new file mode 100644 index 0000000000..8cb4ca0ae4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/Song.java @@ -0,0 +1,55 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import java.util.Objects; + +@Entity +class Song { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @ManyToOne + private Album album; + + @ManyToOne + private Artist artist; + + Song(String name, Artist artist) { + this.name = name; + this.artist = artist; + } + + void assignToAlbum(Album album) { + this.album = album; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Song song = (Song) o; + + return Objects.equals(id, song.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Song() { + } + +} + \ No newline at end of file diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/User.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/User.java new file mode 100644 index 0000000000..d475baddab --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/User.java @@ -0,0 +1,74 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import javax.persistence.OrderColumn; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +@Entity +class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @OneToMany(mappedBy = "createdBy", cascade = CascadeType.PERSIST) + private List playlists; + + @OneToMany(mappedBy = "user", cascade = CascadeType.PERSIST) + @OrderColumn(name = "arrangement_index") + private List favoriteSongs; + + @ManyToMany + private Set followingAlbums; + + User(String name) { + this.name = name; + this.playlists = new ArrayList<>(); + this.favoriteSongs = new ArrayList<>(); + this.followingAlbums = new HashSet<>(); + } + + void followAlbum(Album album) { + this.followingAlbums.add(album); + } + + void createPlaylist(String name) { + this.playlists.add(new Playlist(name, this)); + } + + void addSongToFavorites(Song song) { + this.favoriteSongs.add(new FavoriteSong(song, this)); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + User user = (User) o; + + return Objects.equals(id, user.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected User() { + } +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 1a53fb8e82..46090c51d7 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -55,4 +55,27 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.multiplebagfetchexception.DummyEntity + com.baeldung.jpa.multiplebagfetchexception.Album + com.baeldung.jpa.multiplebagfetchexception.Song + com.baeldung.jpa.multiplebagfetchexception.User + com.baeldung.jpa.multiplebagfetchexception.Artist + com.baeldung.jpa.multiplebagfetchexception.Offer + com.baeldung.jpa.multiplebagfetchexception.Playlist + com.baeldung.jpa.multiplebagfetchexception.FavoriteSong + true + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java new file mode 100644 index 0000000000..f607bbeae4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java @@ -0,0 +1,124 @@ +package com.baeldung.jpa.multiplebagfetchexception; + +import org.hibernate.jpa.QueryHints; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.Query; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MultipleBagFetchExceptionIntegrationTest { + + private static EntityManager entityManager; + + @BeforeAll + public static void setup() { + EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-multiple-bag-fetch-exception"); + entityManager = factory.createEntityManager(); + populateH2DB(); + } + + @Test + public void whenFetchingMoreThanOneBag_thenThrowAnException() { + IllegalArgumentException exception = + assertThrows(IllegalArgumentException.class, () -> { + String jpql = "SELECT dummy FROM DummyEntity dummy " + + "JOIN FETCH dummy.collection1 " + + "JOIN FETCH dummy.collection2 "; + + entityManager.createQuery(jpql); + }); + + final String expectedMessagePart = "MultipleBagFetchException"; + final String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessagePart)); + } + + @Test + public void whenFetchingOneBagAndSet_thenRetrieveSuccess() { + String jpql = "SELECT DISTINCT album FROM Album album " + + "LEFT JOIN FETCH album.songs " + + "LEFT JOIN FETCH album.followers " + + "WHERE album.id = 1"; + + Query query = entityManager.createQuery(jpql) + .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false); + + assertEquals(1, query.getResultList().size()); + } + + @Test + public void whenUsingMultipleQueries_thenRetrieveSuccess() { + String jpql = "SELECT DISTINCT artist FROM Artist artist " + + "LEFT JOIN FETCH artist.songs "; + + List artists = entityManager.createQuery(jpql, Artist.class) + .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false) + .getResultList(); + + jpql = "SELECT DISTINCT artist FROM Artist artist " + + "LEFT JOIN FETCH artist.offers " + + "WHERE artist IN :artists "; + + artists = entityManager.createQuery(jpql, Artist.class) + .setParameter("artists", artists) + .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false) + .getResultList(); + + assertEquals(2, artists.size()); + } + + @Test + public void whenFetchingOneBagAndOneList_thenRetrieveSuccess() { + String jpql = "SELECT DISTINCT user FROM User user " + + "LEFT JOIN FETCH user.playlists " + + "LEFT JOIN FETCH user.favoriteSongs "; + + List users = entityManager.createQuery(jpql, User.class) + .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false) + .getResultList(); + + assertEquals(3, users.size()); + } + + private static void populateH2DB() { + entityManager.getTransaction().begin(); + + Album album = new Album("album-name"); + Artist artist1 = new Artist("artist-name-1"); + Artist artist2 = new Artist("artist-name-2"); + artist2.createOffer("offer-name-1"); + artist2.createOffer("offer-name-2"); + entityManager.persist(album); + entityManager.persist(artist1); + entityManager.persist(artist2); + + Song song1 = new Song("song-name-1", artist2); + song1.assignToAlbum(album); + entityManager.persist(song1); + + User user1 = new User("user-name-1"); + user1.followAlbum(album); + entityManager.persist(user1); + + User user2 = new User("user-name-2"); + user2.followAlbum(album); + entityManager.persist(user2); + + User user3 = new User("user-name-3"); + user3.createPlaylist("playlist-name"); + user3.addSongToFavorites(song1); + entityManager.persist(user3); + + entityManager.getTransaction().commit(); + } + +} From 5ee88c852e72d2888ba26be0dd91f8a524407746 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Wed, 2 Dec 2020 03:30:42 +0100 Subject: [PATCH 263/590] BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed (#10298) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed Co-authored-by: Jonathan Cook --- .../test/java/com/baeldung/SpringContextTest.java | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 spring-batch/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-batch/src/test/java/com/baeldung/SpringContextTest.java b/spring-batch/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index b82bb35daf..0000000000 --- a/spring-batch/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung; - -import com.baeldung.batch.App; -import org.junit.Test; - -public class SpringContextTest { - - @Test - public void testMain() throws Exception { - App.main(null); - } -} From 941b7bd3c89f2fc58d7349003149e6b9b60740a9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:11:06 +0800 Subject: [PATCH 264/590] 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 78491e5bfa..757806c8f6 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -9,4 +9,5 @@ This module contains articles about core features in the Java language - [The Difference Between a.getClass() and A.class in Java](https://www.baeldung.com/java-getclass-vs-class) - [Constants in Java: Patterns and Anti-Patterns](https://www.baeldung.com/java-constants-good-practices) - [The transient Keyword in Java](https://www.baeldung.com/java-transient-keyword) +- [How to Access an Iteration Counter in a For Each Loop](https://www.baeldung.com/java-foreach-counter) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From 623a13b0a9eeffea8d575ff74cc9122fe44d240e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:14:12 +0800 Subject: [PATCH 265/590] Update README.md --- testing-modules/testing-libraries-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-libraries-2/README.md b/testing-modules/testing-libraries-2/README.md index 3325600b5e..f8361904b8 100644 --- a/testing-modules/testing-libraries-2/README.md +++ b/testing-modules/testing-libraries-2/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Guide to the System Rules Library](https://www.baeldung.com/java-system-rules-junit) +- [Guide to the System Stubs Library](https://www.baeldung.com/java-system-stubs) From 61f0a1b720ddfb5dc52d867affd00c1d81324fd4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:17:18 +0800 Subject: [PATCH 266/590] Update README.md --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index 03a5a94acc..b982a753cf 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -12,4 +12,5 @@ This module contains articles about core Java Security - [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) - [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms) - [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates) +- [Security Context Basics: User, Subject and Principal](https://www.baeldung.com/security-context-basics) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From 9d94f7f0955414ac5834a69ba1cb15c397bcc8b1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:19:21 +0800 Subject: [PATCH 267/590] 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 8bb8861daf..048b48d39f 100644 --- a/spring-thymeleaf-3/README.md +++ b/spring-thymeleaf-3/README.md @@ -9,3 +9,4 @@ This module contains articles about Spring with Thymeleaf - [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) +- [Thymeleaf Variables](https://www.baeldung.com/thymeleaf-variables) From 5cd294b635393cc7b7a340c8c69faaced9f1676a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:21:09 +0800 Subject: [PATCH 268/590] 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 8a59d6a229..e1372381a8 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -7,3 +7,4 @@ - [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) - [Localizing Exception Messages in Java](https://www.baeldung.com/java-localize-exception-messages) - [Explanation of ClassCastException in Java](https://www.baeldung.com/java-classcastexception) +- [NoSuchFieldError in Java](https://www.baeldung.com/java-nosuchfielderror) From 6d0a360bb45dc3a67debd893e2568aa209aa0532 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:27:13 +0800 Subject: [PATCH 269/590] Update README.md --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index b982a753cf..bb5e204c98 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -13,4 +13,5 @@ This module contains articles about core Java Security - [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms) - [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates) - [Security Context Basics: User, Subject and Principal](https://www.baeldung.com/security-context-basics) +- [Java AES Encryption and Decryption](https://www.baeldung.com/java-aes-encryption-decryption) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From e3946da6746fe5010ced37028897a27ee6a0bb84 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:28:40 +0800 Subject: [PATCH 270/590] Update README.md --- spring-mvc-xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index 0adf127aaa..3fbea3626b 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -17,6 +17,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml) - [Validating RequestParams and PathVariables in Spring](https://www.baeldung.com/spring-validate-requestparam-pathvariable) - [Debugging the Spring MVC 404 “No mapping found for HTTP request” Error](https://www.baeldung.com/spring-mvc-404-error) +- [Introduction to Servlets and Servlet Containers](https://www.baeldung.com/java-servlets-containers-intro) ## Spring MVC with XML Configuration Example Project From 73af581e18c1a374a19a0601cc384156e605aaa2 Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Wed, 2 Dec 2020 13:40:38 +0000 Subject: [PATCH 271/590] BAEL-4071 - Get advised method info in Spring AOP --- .../com/baeldung/method/info/Account.java | 31 +++++++++++ .../method/info/AccountOperation.java | 12 +++++ .../method/info/BankAccountAspect.java | 53 +++++++++++++++++++ .../method/info/BankAccountService.java | 30 +++++++++++ .../method/info/WithdrawLimitException.java | 7 +++ .../BankAccountServiceIntegrationTest.java | 48 +++++++++++++++++ 6 files changed, 181 insertions(+) create mode 100644 spring-aop/src/main/java/com/baeldung/method/info/Account.java create mode 100644 spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java create mode 100644 spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java create mode 100644 spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java create mode 100644 spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java create mode 100644 spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java diff --git a/spring-aop/src/main/java/com/baeldung/method/info/Account.java b/spring-aop/src/main/java/com/baeldung/method/info/Account.java new file mode 100644 index 0000000000..1c946501fd --- /dev/null +++ b/spring-aop/src/main/java/com/baeldung/method/info/Account.java @@ -0,0 +1,31 @@ +package com.baeldung.method.info; + +public class Account { + + private String accountNumber; + private double balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public double getBalance() { + return balance; + } + + public void setBalance(double balance) { + this.balance = balance; + } + + @Override + public String toString() { + return "Account{" + + "accountNumber='" + accountNumber + '\'' + + ", balance=" + balance + + '}'; + } +} diff --git a/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java b/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java new file mode 100644 index 0000000000..db725a724f --- /dev/null +++ b/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java @@ -0,0 +1,12 @@ +package com.baeldung.method.info; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface AccountOperation { + String operation(); +} diff --git a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java new file mode 100644 index 0000000000..6c8ef9d8d6 --- /dev/null +++ b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java @@ -0,0 +1,53 @@ +package com.baeldung.method.info; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +@Aspect +@Component +public class BankAccountAspect { + + @Before(value="@annotation(com.baeldung.method.info.AccountOperation)") + public void getAccountOperationInfo(JoinPoint joinPoint) { + + //Method Information + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + + System.out.println("full method description: " + signature.getMethod()); + + System.out.println("method name: " + signature.getMethod().getName()); + + System.out.println("declaring type: " + signature.getDeclaringType()); + + //Method args + System.out.println("Method args names:"); + Arrays.stream(signature.getParameterNames()).forEach(s -> System.out.println("arg name: " + s)); + + System.out.println("Method args types:"); + Arrays.stream(signature.getParameterTypes()).forEach(s -> System.out.println("arg type: " + s)); + + System.out.println("Method args values:"); + Arrays.stream(joinPoint.getArgs()).forEach(o -> System.out.println("arg value: " + o.toString())); + + //Additional Information + System.out.println("returning type: " + signature.getReturnType()); + System.out.println("method modifier: " + Modifier.toString(signature.getModifiers())); + Arrays.stream(signature.getExceptionTypes()) + .forEach(aClass -> System.out.println("exception type: " + aClass)); + + //Method annotation + Method method = signature.getMethod(); + AccountOperation accountOperation = method.getAnnotation(AccountOperation.class); + System.out.println("Account operation annotation: " + accountOperation); + System.out.println("Account operation value: " + accountOperation.operation()); + + } +} + diff --git a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java new file mode 100644 index 0000000000..4c7d0e3cac --- /dev/null +++ b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java @@ -0,0 +1,30 @@ +package com.baeldung.method.info; + +import org.apache.commons.lang3.RandomUtils; +import org.springframework.stereotype.Component; + +@Component +public class BankAccountService { + + @AccountOperation(operation = "deposit") + public void deposit(Account account, Double amount) { + account.setBalance(account.getBalance() + amount); + } + + @AccountOperation(operation = "withdraw") + public void withdraw(Account account, Double amount) throws WithdrawLimitException { + + if(amount > 500.0) { + throw new WithdrawLimitException("Withdraw limit exceeded."); + } + + account.setBalance(account.getBalance() - amount); + + } + + public double getBalance() { + return RandomUtils.nextDouble(); + } + + +} diff --git a/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java b/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java new file mode 100644 index 0000000000..85b0b4acfb --- /dev/null +++ b/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java @@ -0,0 +1,7 @@ +package com.baeldung.method.info; + +public class WithdrawLimitException extends RuntimeException { + public WithdrawLimitException(String message) { + super(message); + } +} diff --git a/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java b/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java new file mode 100644 index 0000000000..9e0ebfa903 --- /dev/null +++ b/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java @@ -0,0 +1,48 @@ +package com.baeldung.method.info; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest +class BankAccountServiceIntegrationTest { + + private Account account; + + @BeforeEach + public void setup() { + account = new Account(); + account.setAccountNumber("12345"); + account.setBalance(2000.0); + } + + @Autowired + BankAccountService bankAccountService; + + @Test + void withdraw() { + bankAccountService.withdraw(account, 500.0); + assertTrue(account.getBalance() == 1500.0); + } + + @Test + void withdrawWhenLimitReached() { + Assertions.assertThatExceptionOfType(WithdrawLimitException.class).isThrownBy(() -> bankAccountService.withdraw(account, 600.0)); + assertTrue(account.getBalance() == 2000.0); + } + + @Test + void deposit() { + bankAccountService.deposit(account, 500.0); + assertTrue(account.getBalance() == 2500.0); + } + + @Test + void getBalance() { + bankAccountService.getBalance(); + } +} From f4390801ca49ef5b6f4f3b1fd323b071fe06a8ba Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 3 Dec 2020 12:51:02 +0200 Subject: [PATCH 272/590] fix illegal monitor test --- .../IllegalMonitorStateExceptionUnitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java index a729facdbd..82c00bc72f 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java @@ -20,6 +20,8 @@ public class IllegalMonitorStateExceptionUnitTest { senderThread.join(1000); receiverThread.join(1000); + + Thread.sleep(2000); assertEquals("test", receiver.getMessage()); assertFalse(sender.hasIllegalMonitorStateExceptionOccurred()); From e62e7133938d09ab2b21b114a830637fb26eecf5 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 3 Dec 2020 14:18:15 +0200 Subject: [PATCH 273/590] fix string comparison --- .../com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java b/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java index 152008e5e2..35357dec77 100644 --- a/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java +++ b/java-native/src/test/java/com/baeldung/jvmbitversion/JVMBitVersionUnitTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.Before; import org.junit.Test; -import com.baeldung.jvmbitversion.JVMBitVersion; import com.sun.jna.Platform; public class JVMBitVersionUnitTest { @@ -19,9 +18,9 @@ public class JVMBitVersionUnitTest { @Test public void whenUsingSystemClass_thenOutputIsAsExpected() { - if (System.getProperty("sun.arch.data.model") == "64") { + if ("64".equals(System.getProperty("sun.arch.data.model"))) { assertEquals("64-bit", jvmVersion.getUsingSystemClass()); - } else if (System.getProperty("sun.arch.data.model") == "32") { + } else if ("32".equals(System.getProperty("sun.arch.data.model"))) { assertEquals("32-bit", jvmVersion.getUsingSystemClass()); } } From c19b868d3b92fd2911ea9b5a89e21677550294b4 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Fri, 4 Dec 2020 19:55:44 +0200 Subject: [PATCH 274/590] BAEL-4687: renamed project from jackson to data 2 --- spring-boot-modules/pom.xml | 2 +- .../{spring-boot-jackson => spring-boot-data-2}/pom.xml | 6 +++--- .../java/com/baeldung/boot/jackson/app/Application.java | 0 .../com/baeldung/boot/jackson/config/CoffeeConstants.java | 0 .../boot/jackson/config/CoffeeCustomizerConfig.java | 0 .../jackson/config/CoffeeHttpConverterConfiguration.java | 0 .../boot/jackson/config/CoffeeJacksonBuilderConfig.java | 0 .../boot/jackson/config/CoffeeObjectMapperConfig.java | 0 .../boot/jackson/config/CoffeeRegisterModuleConfig.java | 0 .../baeldung/boot/jackson/controller/CoffeeController.java | 0 .../main/java/com/baeldung/boot/jackson/model/Coffee.java | 0 .../src/main/resources/coffee.properties | 0 .../boot/jackson/app/AbstractCoffeeIntegrationTest.java | 0 .../boot/jackson/app/CoffeeCustomizerIntegrationTest.java | 0 .../jackson/app/CoffeeHttpConverterIntegrationTest.java | 0 .../jackson/app/CoffeeJacksonBuilderIntegrationTest.java | 0 .../boot/jackson/app/CoffeeObjectMapperIntegrationTest.java | 0 .../jackson/app/CoffeeRegisterModuleIntegrationTest.java | 0 18 files changed, 4 insertions(+), 4 deletions(-) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/pom.xml (77%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/app/Application.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/java/com/baeldung/boot/jackson/model/Coffee.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/main/resources/coffee.properties (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-jackson => spring-boot-data-2}/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java (100%) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 3d721d7147..4ff825309a 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -68,7 +68,7 @@ spring-boot-vue spring-boot-xml spring-boot-actuator - spring-boot-jackson + spring-boot-data-2 diff --git a/spring-boot-modules/spring-boot-jackson/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml similarity index 77% rename from spring-boot-modules/spring-boot-jackson/pom.xml rename to spring-boot-modules/spring-boot-data-2/pom.xml index 1b2e55839a..199a204500 100644 --- a/spring-boot-modules/spring-boot-jackson/pom.xml +++ b/spring-boot-modules/spring-boot-data-2/pom.xml @@ -1,6 +1,6 @@ - com.baeldung.spring-boot-modules @@ -10,7 +10,7 @@ 4.0.0 - spring-boot-jackson + spring-boot-data-2 org.springframework.boot diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/app/Application.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/app/Application.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/app/Application.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/app/Application.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/model/Coffee.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/model/Coffee.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/model/Coffee.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties b/spring-boot-modules/spring-boot-data-2/src/main/resources/coffee.properties similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/main/resources/coffee.properties rename to spring-boot-modules/spring-boot-data-2/src/main/resources/coffee.properties diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeCustomizerIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeHttpConverterIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeJacksonBuilderIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeObjectMapperIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jackson/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/CoffeeRegisterModuleIntegrationTest.java From 65e9e80f0c0f1ccefbfe858eed02e52ca0d62682 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Fri, 4 Dec 2020 20:01:12 +0200 Subject: [PATCH 275/590] BAEL-4687: formatted code with eclipse formatter --- .../boot/jackson/config/CoffeeConstants.java | 4 ++-- .../jackson/config/CoffeeCustomizerConfig.java | 5 +++-- .../config/CoffeeHttpConverterConfiguration.java | 5 +++-- .../config/CoffeeJacksonBuilderConfig.java | 5 +++-- .../jackson/config/CoffeeObjectMapperConfig.java | 14 +++++++------- .../config/CoffeeRegisterModuleConfig.java | 7 ++++--- .../boot/jackson/controller/CoffeeController.java | 15 +++++++-------- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java index 7e7d7b8bc2..90cad011ae 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java @@ -1,9 +1,9 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; - import java.time.format.DateTimeFormatter; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; + public class CoffeeConstants { public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java index c13615e702..363c67fd9a 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java @@ -1,11 +1,12 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; +import com.fasterxml.jackson.annotation.JsonInclude; @Configuration public class CoffeeCustomizerConfig { diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java index 83474a5c1f..b67f215816 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java @@ -1,12 +1,13 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; +import com.fasterxml.jackson.annotation.JsonInclude; @Configuration public class CoffeeHttpConverterConfiguration { diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java index 7a7b3e48bf..ec4de1d353 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java @@ -1,12 +1,13 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; +import com.fasterxml.jackson.annotation.JsonInclude; @Configuration public class CoffeeJacksonBuilderConfig { diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java index 5697928cc5..3754de018a 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java @@ -1,13 +1,14 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; @Configuration public class CoffeeObjectMapperConfig { @@ -17,8 +18,7 @@ public class CoffeeObjectMapperConfig { public ObjectMapper objectMapper() { JavaTimeModule module = new JavaTimeModule(); module.addSerializer(localDateTimeSerializer); - return new ObjectMapper() - .setSerializationInclusion(JsonInclude.Include.NON_NULL) - .registerModule(module); + return new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL) + .registerModule(module); } } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java index 855bc84966..ea00e5a58e 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java @@ -1,12 +1,13 @@ package com.baeldung.boot.jackson.config; -import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; @Configuration @PropertySource("classpath:coffee.properties") diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java index 075126de67..a960dafd89 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java @@ -1,21 +1,20 @@ package com.baeldung.boot.jackson.controller; -import com.baeldung.boot.jackson.model.Coffee; +import java.time.LocalDateTime; + import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; +import com.baeldung.boot.jackson.model.Coffee; @RestController public class CoffeeController { @GetMapping("/coffee") - public Coffee getCoffee(@RequestParam(required = false) String brand, - @RequestParam(required = false) String name) { - return new Coffee() - .setBrand(brand) - .setDate(LocalDateTime.now()) - .setName(name); + public Coffee getCoffee(@RequestParam(required = false) String brand, @RequestParam(required = false) String name) { + return new Coffee().setBrand(brand) + .setDate(LocalDateTime.now()) + .setName(name); } } From 2700958ec07cb5afcd58f83e4acc56b7ed1109c0 Mon Sep 17 00:00:00 2001 From: majajoksovic Date: Sat, 5 Dec 2020 03:38:42 +0100 Subject: [PATCH 276/590] BAEL-4445 (#10291) * initial commit * changed test method names to follow convention --- .../httpclient/HttpClientParamsLiveTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientParamsLiveTest.java diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientParamsLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientParamsLiveTest.java new file mode 100644 index 0000000000..f3ea9be089 --- /dev/null +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientParamsLiveTest.java @@ -0,0 +1,111 @@ +package com.baeldung.httpclient; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.NameValuePair; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; +import org.junit.Before; +import org.junit.Test; + +public class HttpClientParamsLiveTest { + + private CloseableHttpClient client; + + private CloseableHttpResponse response; + + private List nameValuePairs; + + @Before + public void setUp() { + client = HttpClientBuilder.create() + .build(); + nameValuePairs = new ArrayList(); + NameValuePair param1NameValuePair = new BasicNameValuePair("param1", "value1"); + NameValuePair param2NameValuePair = new BasicNameValuePair("param2", "value2"); + nameValuePairs.add(param1NameValuePair); + nameValuePairs.add(param2NameValuePair); + } + + @Test + public void givenStringNameValuePairParams_whenGetRequest_thenResponseOk() throws URISyntaxException, ClientProtocolException, IOException { + HttpGet httpGet = new HttpGet("https://postman-echo.com/get"); + URI uri = new URIBuilder(httpGet.getURI()).addParameter("param1", "value1") + .addParameter("param2", "value2") + .build(); + ((HttpRequestBase) httpGet).setURI(uri); + response = client.execute(httpGet); + + assertThat(response.getStatusLine() + .getStatusCode(), equalTo(200)); + client.close(); + } + + @Test + public void givenStringNameValuePairParams_whenPostRequest_thenResponseOk() throws URISyntaxException, ClientProtocolException, IOException { + HttpPost httpPost = new HttpPost("https://postman-echo.com/post"); + URI uri = new URIBuilder(httpPost.getURI()).addParameter("param1", "value1") + .addParameter("param2", "value2") + .build(); + ((HttpRequestBase) httpPost).setURI(uri); + response = client.execute(httpPost); + + assertThat(response.getStatusLine() + .getStatusCode(), equalTo(200)); + client.close(); + } + + @Test + public void givenNameValuePairParams_whenGetRequest_thenResponseOk() throws URISyntaxException, ClientProtocolException, IOException { + HttpGet httpGet = new HttpGet("https://postman-echo.com/get"); + URI uri = new URIBuilder(httpGet.getURI()).addParameters(nameValuePairs) + .build(); + ((HttpRequestBase) httpGet).setURI(uri); + response = client.execute(httpGet); + + assertThat(response.getStatusLine() + .getStatusCode(), equalTo(200)); + client.close(); + } + + @Test + public void givenNameValuePairsParams_whenPostRequest_thenResponseOk() throws URISyntaxException, ClientProtocolException, IOException { + HttpPost httpPost = new HttpPost("https://postman-echo.com/post"); + URI uri = new URIBuilder(httpPost.getURI()).addParameters(nameValuePairs) + .build(); + ((HttpRequestBase) httpPost).setURI(uri); + response = client.execute(httpPost); + + assertThat(response.getStatusLine() + .getStatusCode(), equalTo(200)); + client.close(); + } + + @Test + public void givenUrlEncodedEntityParams_whenPostRequest_thenResponseOk() throws URISyntaxException, ClientProtocolException, IOException { + HttpPost httpPost = new HttpPost("https://postman-echo.com/post"); + httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8)); + response = client.execute(httpPost); + + assertThat(response.getStatusLine() + .getStatusCode(), equalTo(200)); + client.close(); + } + +} From bc281bde2ffdd91adfdad9eff0929d5d1bcea0d8 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa <70507913+emyasa@users.noreply.github.com> Date: Sat, 5 Dec 2020 10:44:40 +0800 Subject: [PATCH 277/590] [BAEL-4056] Guide to MultipleBagFetchException (#10304) * Removes DummyEntity * Uses Artist Entity instead of DummyEntity --- .../DummyEntity.java | 43 ------------------- .../main/resources/META-INF/persistence.xml | 1 - ...tipleBagFetchExceptionIntegrationTest.java | 6 +-- 3 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java deleted file mode 100644 index 8eb9c95724..0000000000 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/multiplebagfetchexception/DummyEntity.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.jpa.multiplebagfetchexception; - -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import java.util.List; -import java.util.Objects; - -@Entity -class DummyEntity { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - @ElementCollection - private List collection1; - - @ElementCollection - private List collection2; - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - DummyEntity that = (DummyEntity) o; - - return Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } - - protected DummyEntity() { - } -} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index 46090c51d7..f428fea07b 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -57,7 +57,6 @@ org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.multiplebagfetchexception.DummyEntity com.baeldung.jpa.multiplebagfetchexception.Album com.baeldung.jpa.multiplebagfetchexception.Song com.baeldung.jpa.multiplebagfetchexception.User diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java index f607bbeae4..648650ad8a 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/multiplebagfetchexception/MultipleBagFetchExceptionIntegrationTest.java @@ -29,9 +29,9 @@ public class MultipleBagFetchExceptionIntegrationTest { public void whenFetchingMoreThanOneBag_thenThrowAnException() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { - String jpql = "SELECT dummy FROM DummyEntity dummy " - + "JOIN FETCH dummy.collection1 " - + "JOIN FETCH dummy.collection2 "; + String jpql = "SELECT artist FROM Artist artist " + + "JOIN FETCH artist.songs " + + "JOIN FETCH artist.offers "; entityManager.createQuery(jpql); }); From c02a2052205d634961a4bf6d9c0d037ad46f62cf Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 5 Dec 2020 09:52:32 +0100 Subject: [PATCH 278/590] BAEL-4717: add new module to parent pom --- core-java-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index a6aecef741..a12b3548f9 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -33,6 +33,7 @@ core-java-collections core-java-collections-2 core-java-collections-3 + core-java-collections-4 core-java-collections-array-list core-java-collections-list core-java-collections-list-2 From 32dba7dd0699f7581b3f871cd21ff74e1d0d526f Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Wed, 25 Nov 2020 00:03:34 +0100 Subject: [PATCH 279/590] remove file extensions --- .../MyFilenameUtil.java | 14 ++++ .../FileNameDelExtensionUnitTest.java | 72 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/filenamewithoutextension/FileNameDelExtensionUnitTest.java diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java new file mode 100644 index 0000000000..102c454c49 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java @@ -0,0 +1,14 @@ +package com.baeldung.filenamewithoutextension; + +public class MyFilenameUtil { + private MyFilenameUtil() {} + + public static String removeFileExtension(String filename, boolean removeAllExtensions) { + if (filename == null || filename.isEmpty()) { + return filename; + } + + String extPattern = "(? Date: Mon, 7 Dec 2020 07:41:10 +0000 Subject: [PATCH 280/590] BAEL-4652: Running Spring Boot with PostgreSQL in Docker Compose (#10297) --- docker/docker-spring-boot-postgres/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/docker-spring-boot-postgres/pom.xml b/docker/docker-spring-boot-postgres/pom.xml index f409ca7d92..0b359138f6 100644 --- a/docker/docker-spring-boot-postgres/pom.xml +++ b/docker/docker-spring-boot-postgres/pom.xml @@ -9,9 +9,9 @@ com.baeldung.docker - spring-boot-postgres-docker + docker-spring-boot-postgres 0.0.1-SNAPSHOT - spring-boot-postgres-docker + docker-spring-boot-postgres Demo project showing Spring Boot, PostgreSQL, and Docker @@ -45,4 +45,4 @@ - + \ No newline at end of file From 77ca7cffa58553a29419da6e9ad0af062adcbabe Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:13:04 +0800 Subject: [PATCH 281/590] Update README.md --- docker/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/README.md b/docker/README.md index fcace3978f..ce7fe261c2 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,3 +2,4 @@ - [Introduction to Docker Compose](https://www.baeldung.com/docker-compose) - [Reusing Docker Layers with Spring Boot](https://www.baeldung.com/docker-layers-spring-boot) +- [Running Spring Boot with PostgreSQL in Docker Compose](https://www.baeldung.com/spring-boot-postgresql-docker) From 3d0bd4a844f34389d78ff27eb8f977afe16dc591 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:15:40 +0800 Subject: [PATCH 282/590] Create README.md --- spring-batch-2/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-batch-2/README.md diff --git a/spring-batch-2/README.md b/spring-batch-2/README.md new file mode 100644 index 0000000000..08bf1933db --- /dev/null +++ b/spring-batch-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Boot With Spring Batch](https://www.baeldung.com/spring-boot-spring-batch) From 3b04af5f0503a83bf7988fcd84a4b996c105b318 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:17:32 +0800 Subject: [PATCH 283/590] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index 50ea75d995..1949207364 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -8,3 +8,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [Ignoring Fields With the JPA @Transient Annotation](https://www.baeldung.com/jpa-transient-ignore-field) - [Defining Indexes in JPA](https://www.baeldung.com/jpa-indexes) - [JPA CascadeType.REMOVE vs orphanRemoval](https://www.baeldung.com/jpa-cascade-remove-vs-orphanremoval) +- [A Guide to MultipleBagFetchException in Hibernate](https://www.baeldung.com/java-hibernate-multiplebagfetchexception) From 59b090e4a832225e0d1cc7cda7db40aa96f84f91 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:20:01 +0800 Subject: [PATCH 284/590] 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 18caabc784..36617a210e 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -12,4 +12,5 @@ This module contains articles about core Java input and output (IO) - [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) - [Find the Last Modified File in a Directory with Java](https://www.baeldung.com/java-last-modified-file) +- [Get a Filename Without the Extension in Java](https://www.baeldung.com/java-filename-without-extension) - [[<-- Prev]](/core-java-modules/core-java-io-2) From dbf7a4cdc8a349834aabc5a4992fbc7feeca6b6b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:21:31 +0800 Subject: [PATCH 285/590] 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 757806c8f6..5279cc23b0 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -10,4 +10,5 @@ This module contains articles about core features in the Java language - [Constants in Java: Patterns and Anti-Patterns](https://www.baeldung.com/java-constants-good-practices) - [The transient Keyword in Java](https://www.baeldung.com/java-transient-keyword) - [How to Access an Iteration Counter in a For Each Loop](https://www.baeldung.com/java-foreach-counter) +- [Comparing Doubles in Java](https://www.baeldung.com/java-comparing-doubles) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From df1ee124a6470a09b4714a3390c71dfb2d1802aa Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:23:53 +0800 Subject: [PATCH 286/590] Update README.md --- httpclient-simple/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index 098d5f278e..93fb22ac1e 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -11,6 +11,7 @@ This module contains articles about HTTPClient that are part of the HTTPClient E - [Custom HTTP Header with the HttpClient](https://www.baeldung.com/httpclient-custom-http-header) - [HttpClient Basic Authentication](https://www.baeldung.com/httpclient-4-basic-authentication) - [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request) +- [Adding Parameters to HttpClient Requests](https://www.baeldung.com/java-httpclient-parameters) ### Running the Tests From 2f42035fb5d2477f0b47f65d819922d8b5fb86f5 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Wed, 9 Dec 2020 17:45:25 +0530 Subject: [PATCH 287/590] BAEL-4686: Added some more test cases for TreeMap and LinkedHashMap --- .../ConcurrentModificationErrorUnitTest.java | 29 +++++++++++++++ .../NullAllowInMapUnitTest.java | 37 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java index 899c902fb0..4264e613f2 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/ConcurrentModificationErrorUnitTest.java @@ -4,8 +4,10 @@ import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import org.junit.Assert; @@ -25,7 +27,34 @@ public class ConcurrentModificationErrorUnitTest { iterator.next(); } } + + @Test(expected = ConcurrentModificationException.class) + public void whenRemoveAndAddOnTreeMap_thenConcurrentModificationError() { + Map map = new TreeMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Map synchronizedMap = Collections.synchronizedMap(map); + Iterator> iterator = synchronizedMap.entrySet().iterator(); + while (iterator.hasNext()) { + synchronizedMap.put(3, "Modification"); + iterator.next(); + } + } + + @Test(expected = ConcurrentModificationException.class) + public void whenRemoveAndAddOnLinkedHashMap_thenConcurrentModificationError() { + Map map = new LinkedHashMap<>(); + map.put(1, "baeldung"); + map.put(2, "HashMap"); + Map synchronizedMap = Collections.synchronizedMap(map); + Iterator> iterator = synchronizedMap.entrySet().iterator(); + while (iterator.hasNext()) { + synchronizedMap.put(3, "Modification"); + iterator.next(); + } + } + @Test public void whenRemoveAndAddOnConcurrentHashMap_thenNoError() { Map map = new ConcurrentHashMap<>(); map.put(1, "baeldung"); diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java index 60e293f4b3..c5fc57d8ce 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java @@ -2,7 +2,9 @@ package com.baeldung.map.concurrenthashmap; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import org.junit.Assert; @@ -11,13 +13,29 @@ import org.junit.Test; public class NullAllowInMapUnitTest { @Test - public void allowNullKey_In_SynchronizedMap() { + public void allowNullKey_In_HashMapBackedSynchronizedMap() { Map map = Collections .synchronizedMap(new HashMap()); map.put(null, 1); Assert.assertTrue(map.get(null).equals(1)); } + + @Test(expected = NullPointerException.class) + public void allowNullKey_In_TreeMapBackedSynchronizedMap() { + Map map = Collections.synchronizedMap(new TreeMap()); + map.put(null, 1); + Assert.assertTrue(map.get(null).equals(1)); + } + + @Test + public void allowNullKey_In_LinkedHashMapBackedSynchronizedMap() { + Map map = Collections + .synchronizedMap(new LinkedHashMap()); + map.put(null, 1); + Assert.assertTrue(map.get(null).equals(1)); + } + @Test(expected = NullPointerException.class) public void allowNullKey_In_ConcurrentHasMap() { Map map = new ConcurrentHashMap<>(); @@ -25,12 +43,27 @@ public class NullAllowInMapUnitTest { } @Test - public void allowNullValue_In_SynchronizedMap() { + public void allowNullValue_In_HashMapBackedSynchronizedMap() { Map map = Collections.synchronizedMap(new HashMap()); map.put("1", null); Assert.assertNull(map.get("1")); } + @Test + public void allowNullValue_In_TreeMapBackedSynchronizedMap() { + Map map = Collections.synchronizedMap(new TreeMap()); + map.put("1", null); + Assert.assertNull(map.get("1")); + } + + @Test + public void allowNullValue_In_LinkedHashSynchronizedMap() { + Map map = Collections + .synchronizedMap(new LinkedHashMap()); + map.put("1", null); + Assert.assertNull(map.get("1")); + } + @Test(expected = NullPointerException.class) public void allowNullValue_In_ConcurrentHasMap() { Map map = new ConcurrentHashMap<>(); From 2d09274e409b51251a39b7ed96e4171c3af265c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 11:45:02 +0100 Subject: [PATCH 288/590] JAVA-3570: Upgrade parent-boot-2 to Spring Boot 2.4.0 --- parent-boot-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index dab9f015b3..2ee4f1483b 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -82,7 +82,7 @@ 3.3.0 1.0.22.RELEASE - 2.3.3.RELEASE + 2.4.0 1.9.1 From 212f1ed72dc752ea368c651a4dfa35b3720baa53 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 12:06:43 +0100 Subject: [PATCH 289/590] JAVA-3570: Keep spring-data-rest on Spring Boot 2.3.3 --- spring-data-rest/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index 63a42857f4..dd96182264 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -99,6 +99,7 @@ com.baeldung.books.SpringDataRestApplication 1.0 + 2.3.3.RELEASE \ No newline at end of file From 50c668c300345ce9ab548c750ccb37f297a53d8d Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 12:16:24 +0100 Subject: [PATCH 290/590] JAVA-3570: Fix spring-security-oauth2 version in libraries-security --- libraries-security/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries-security/pom.xml b/libraries-security/pom.xml index 202b3b8763..3b812f0d2c 100644 --- a/libraries-security/pom.xml +++ b/libraries-security/pom.xml @@ -21,7 +21,7 @@ org.springframework.security.oauth spring-security-oauth2 - ${spring-boot.version} + ${spring-security-oauth2.version} org.springframework @@ -88,6 +88,7 @@ 1.58 0.1.55 2.5.1 + 2.4.0.RELEASE From 8f5f322273fb2ca0eb258b94906135506be45dc8 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 13:05:54 +0100 Subject: [PATCH 291/590] JAVA-3570: Keep spring-5-reactive-client on Spring Boot 2.3.3 --- spring-5-reactive-client/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index 7ae7ba6edd..5b773cc63f 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -176,6 +176,7 @@ 4.1 1.0.3 4.0.1 + 2.3.3.RELEASE From 8a264a9981db9413b51f7a571e0a303c909dd1d8 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 13:16:09 +0100 Subject: [PATCH 292/590] JAVA-3570: Fix unit tests in persistence-modules/redis --- .../configuration/controller/BooksControllerUnitTest.java | 4 ++-- .../configuration/repository/BooksRepositoryUnitTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/controller/BooksControllerUnitTest.java b/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/controller/BooksControllerUnitTest.java index a5c3340065..757b32385b 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/controller/BooksControllerUnitTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/controller/BooksControllerUnitTest.java @@ -10,15 +10,15 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.redis.configuration.entity.Book; import com.baeldung.spring.redis.configuration.repository.BooksRepository; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(MockitoJUnitRunner.class) public class BooksControllerUnitTest { - @Spy @InjectMocks private BooksController booksController; diff --git a/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/repository/BooksRepositoryUnitTest.java b/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/repository/BooksRepositoryUnitTest.java index 1edf9c7e89..f32800e165 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/repository/BooksRepositoryUnitTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/spring/redis/configuration/repository/BooksRepositoryUnitTest.java @@ -11,16 +11,16 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.redis.configuration.entity.Book; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(MockitoJUnitRunner.class) public class BooksRepositoryUnitTest { - @Spy @InjectMocks private BooksRepository booksRepository; From ee0d98b8a56d6fef4a774b0f3156640a7bbafe9e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 13:38:50 +0100 Subject: [PATCH 293/590] JAVA-3570: Keep spring-5-webflux on Spring Boot 2.3.3 --- spring-5-webflux/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml index 292e4d7ad9..48b5b823fb 100644 --- a/spring-5-webflux/pom.xml +++ b/spring-5-webflux/pom.xml @@ -64,4 +64,8 @@ + + 2.3.3.RELEASE + + From e6a310c4fb94132dd9d910b6d9a90412561d44cf Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 14:14:59 +0100 Subject: [PATCH 294/590] JAVA-3570: Keep spring-boot-admin on Spring Boot 2.3.3 --- .../spring-boot-admin/spring-boot-admin-server/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/pom.xml b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/pom.xml index 4c1dcdef6b..558aed8b26 100644 --- a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/pom.xml +++ b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/pom.xml @@ -86,5 +86,6 @@ 2.2.2 1.5.7 2.0.4.RELEASE + 2.3.3.RELEASE From c008e43ea817b79547f9039fa4c9db05f80e44b0 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 21:56:46 +0100 Subject: [PATCH 295/590] JAVA-3570: Update Kotlin version in spring-boot-springdoc --- spring-boot-modules/spring-boot-springdoc/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml index ed272200da..d4622e0595 100644 --- a/spring-boot-modules/spring-boot-springdoc/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/pom.xml @@ -81,7 +81,7 @@ org.jetbrains.kotlin - kotlin-stdlib-jre8 + kotlin-stdlib-jdk8 ${kotlin.version} @@ -173,7 +173,7 @@ 5.2.10.Final 1.2.32 1.5.6 - 1.2.71 + 1.4.0 ${project.build.directory}/generated-snippets @@ -185,7 +185,7 @@ org.springframework.boot spring-boot-maven-plugin - 2.2.2.RELEASE + ${spring-boot.version} pre-integration-test From 19ab1ccf2b3cda5a0fdfdaf3b4d74a2d38c0af6d Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 11 Dec 2020 22:17:40 +0100 Subject: [PATCH 296/590] JAVA-3570: Use Spring Boot starters in spring-security-web-mvc --- .../spring-security-web-mvc/pom.xml | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/spring-security-modules/spring-security-web-mvc/pom.xml b/spring-security-modules/spring-security-web-mvc/pom.xml index 2651b3a0f2..b1e94b2db3 100644 --- a/spring-security-modules/spring-security-web-mvc/pom.xml +++ b/spring-security-modules/spring-security-web-mvc/pom.xml @@ -61,27 +61,6 @@ spring-boot-starter-test test - - org.springframework.security - spring-security-test - ${spring.mvc.version} - test - - - org.springframework.security - spring-security-web - ${spring.mvc.version} - - - org.springframework.security - spring-security-config - ${spring.mvc.version} - - - org.springframework - spring-webmvc - ${spring.mvc.version} - javax.servlet javax.servlet-api @@ -104,7 +83,6 @@ - 5.2.2.RELEASE 4.0.1 From 18727de7c5c94b03cf713039a151a7b42f384644 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Sat, 12 Dec 2020 00:44:55 +0200 Subject: [PATCH 297/590] Determine if an Integer's Square Root Is an Integer in Java Article by Abdallah Sawan --- .../baeldung/perfectsquare/PerfectSquareUnitTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java index 334b95ea9d..83fce31047 100644 --- a/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java +++ b/java-numbers-4/src/test/java/com/baeldung/perfectsquare/PerfectSquareUnitTest.java @@ -6,22 +6,21 @@ import static org.junit.Assert.assertEquals; public class PerfectSquareUnitTest { @Test - public void test0xFFAssignedToInteger() { + public void testIsNumberPerfectSquare() { long n = 18676209273604L; //‬ 18676209273604 = 43621598 * 43621598 boolean expectedValue = true; assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n)); - } - @Test - public void test0xFFAssignedToByte() { - long n = 549790047707L; // prime number - boolean expectedValue = false; + n = 549790047707L; // prime number + expectedValue = false; assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n)); assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n)); } + + } From 0d8d1d3a09978e35233ee5484306393f8d8dfb7b Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 13 Dec 2020 10:33:53 +0100 Subject: [PATCH 298/590] BAEL-4717: Fix artifactId --- core-java-modules/core-java-collections-4/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-4/pom.xml b/core-java-modules/core-java-collections-4/pom.xml index 23baa51d0d..0e3cabf40e 100644 --- a/core-java-modules/core-java-collections-4/pom.xml +++ b/core-java-modules/core-java-collections-4/pom.xml @@ -4,9 +4,9 @@ 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 - core-java-collections-3 + core-java-collections-4 0.1.0-SNAPSHOT - core-java-collections-3 + core-java-collections-4 jar com.baeldung.core-java-modules From 7afdb4cba720a08b603dd049b562ca832d923549 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sun, 13 Dec 2020 17:22:09 +0100 Subject: [PATCH 299/590] [BAEL-4497] jdbc url --- .../core-java-persistence-2/pom.xml | 35 +++++++- .../jdbcurlformat/JdbcUrlFormatLiveTest.java | 86 +++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/core-java-persistence-2/src/test/java/com/baeldung/jdbcurlformat/JdbcUrlFormatLiveTest.java diff --git a/persistence-modules/core-java-persistence-2/pom.xml b/persistence-modules/core-java-persistence-2/pom.xml index 9845d5009d..a1088b0801 100644 --- a/persistence-modules/core-java-persistence-2/pom.xml +++ b/persistence-modules/core-java-persistence-2/pom.xml @@ -20,10 +20,43 @@ h2 ${h2.version} + + org.postgresql + postgresql + ${postgresql.version} + test + + + mysql + mysql-connector-java + ${mysql.driver.version} + + + + com.microsoft.sqlserver + mssql-jdbc + ${mssql.driver.version} + + 1.4.200 + 42.2.5.jre7 + 8.4.1.jre11 + 10.2.0.4.0 + 8.0.22 - \ No newline at end of file + diff --git a/persistence-modules/core-java-persistence-2/src/test/java/com/baeldung/jdbcurlformat/JdbcUrlFormatLiveTest.java b/persistence-modules/core-java-persistence-2/src/test/java/com/baeldung/jdbcurlformat/JdbcUrlFormatLiveTest.java new file mode 100644 index 0000000000..fc00119704 --- /dev/null +++ b/persistence-modules/core-java-persistence-2/src/test/java/com/baeldung/jdbcurlformat/JdbcUrlFormatLiveTest.java @@ -0,0 +1,86 @@ +package com.baeldung.jdbcurlformat; + +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import static org.junit.Assert.assertNotNull; + +public class JdbcUrlFormatLiveTest { + @Test + public void givenOracleSID_thenCreateConnectionObject() { + String oracleJdbcUrl = "jdbc:oracle:thin:@myoracle.db.server:1521:my_sid"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(oracleJdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } + + @Test + public void givenOracleServiceName_thenCreateConnectionObject() { + String oracleJdbcUrl = "jdbc:oracle:thin:@//myoracle.db.server:1521/my_servicename"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(oracleJdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } + + @Test + public void givenOracleTnsnames_thenCreateConnectionObject() { + String oracleJdbcUrl = "jdbc:oracle:thin:@" + + "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" + + "(HOST=myoracle.db.server)(PORT=1521))" + + "(CONNECT_DATA=(SERVICE_NAME=my_servicename)))"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(oracleJdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } + + @Test + public void givenMysqlDb_thenCreateConnectionObject() { + String jdbcUrl = "jdbc:mysql://mysql.db.server:3306/my_database?useSSL=false&serverTimezone=UTC"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(jdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } + + @Test + public void givenMssqlDb_thenCreateConnectionObject() { + String jdbcUrl = "jdbc:sqlserver://mssql.db.server\\mssql_instance;databaseName=my_database"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(jdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } + + @Test + public void givenPostgreSqlDb_thenCreateConnectionObject() { + String jdbcUrl = "jdbc:postgresql://postgresql.db.server:5430/my_database?ssl=true&loglevel=2"; + String username = "dbUser"; + String password = "1234567"; + try (Connection conn = DriverManager.getConnection(jdbcUrl, username, password)) { + assertNotNull(conn); + } catch (SQLException e) { + System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage()); + } + } +} From 1f8efc0c144814a054ff6833803996e9680897b5 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 10:18:38 +0100 Subject: [PATCH 300/590] JAVA-3570: Keep spring-boot-environment on Spring Boot 2.3.3 [cloud] --- spring-boot-modules/spring-boot-environment/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index 694e17fd72..d34bbd18c0 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -144,6 +144,7 @@ 3.1.7 2.0.2.RELEASE 4.5.8 + 2.3.3.RELEASE From 1a3ec076dca9c7c577c8ad4b0bd0fee12f5e0c5e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 10:21:03 +0100 Subject: [PATCH 301/590] JAVA-3570: Keep spring-boot-deployment on Spring Boot 2.3.3 [cloud] --- spring-boot-modules/spring-boot-deployment/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-deployment/pom.xml b/spring-boot-modules/spring-boot-deployment/pom.xml index 6b5e75bd62..94a4018103 100644 --- a/spring-boot-modules/spring-boot-deployment/pom.xml +++ b/spring-boot-modules/spring-boot-deployment/pom.xml @@ -197,6 +197,7 @@ 3.1.7 2.0.2.RELEASE 4.5.8 + 2.3.3.RELEASE From adbd9ecfb97ca9facc72c596ef26bf18bb3b4864 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 10:23:23 +0100 Subject: [PATCH 302/590] JAVA-3570: Keep spring-cloud on Spring Boot 2.3.3 [cloud] --- spring-cloud/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index c0e452afaf..c7f6dc56a0 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -84,7 +84,7 @@ 1.4.7.RELEASE 1.4.7.RELEASE 3.0.6.RELEASE - + 2.3.3.RELEASE From 9e957f2fd03be867521d5d20107a34f87011e552 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 10:41:20 +0100 Subject: [PATCH 303/590] JAVA-3570: themeResolver bean can no longer be configured without enabling bean overriding --- spring-mvc-basics/src/main/resources/application.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-mvc-basics/src/main/resources/application.properties b/spring-mvc-basics/src/main/resources/application.properties index b8a9be0b40..cf26fbfb60 100644 --- a/spring-mvc-basics/src/main/resources/application.properties +++ b/spring-mvc-basics/src/main/resources/application.properties @@ -5,3 +5,6 @@ spring.mvc.pathmatch.use-suffix-pattern=true #spring.mvc.contentnegotiation.favor-path-extension=true #spring.mvc.contentnegotiation.favor-parameter=true #spring.mvc.contentnegotiation.parameter-name=mediaType + +# https://github.com/spring-projects/spring-boot/issues/24207 +spring.main.allow-bean-definition-overriding=true From 07276b1aaa00824f55f3d88d4eacc37cbb52586d Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 10:59:45 +0100 Subject: [PATCH 304/590] JAVA-3570: Upgrade Spring framework to version compatible with Spring Boot 2.4 in spring-testing --- testing-modules/spring-testing/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index f26b0f27ec..9fe0fd8895 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -114,7 +114,7 @@ 3.1.6 5.7.0 1.7.0 - 5.2.8.RELEASE + 5.3.0 4.0.1 2.1.1 From 127a377b81f7fee82bc2b8ad32b08e1866035c38 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 11:00:28 +0100 Subject: [PATCH 305/590] Revert "JAVA-3570: Keep spring-cloud on Spring Boot 2.3.3 [cloud]" This reverts commit adbd9ecfb97ca9facc72c596ef26bf18bb3b4864. --- spring-cloud/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index c7f6dc56a0..c0e452afaf 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -84,7 +84,7 @@ 1.4.7.RELEASE 1.4.7.RELEASE 3.0.6.RELEASE - 2.3.3.RELEASE + From b4ccf851d315acdb38056b69961435ce28929861 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 11:02:50 +0100 Subject: [PATCH 306/590] JAVA-3570: Keep spring-cloud-zuul on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-zuul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-zuul/pom.xml b/spring-cloud/spring-cloud-zuul/pom.xml index b8db1f2fc7..6035ba7e59 100644 --- a/spring-cloud/spring-cloud-zuul/pom.xml +++ b/spring-cloud/spring-cloud-zuul/pom.xml @@ -80,7 +80,7 @@ Hoxton.SR4 - + 2.3.3.RELEASE From a0ec0f3d5ca376ffa6d16eee91ce6361dda67e5b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 12:03:21 +0100 Subject: [PATCH 307/590] JAVA-3570: Keep spring-cloud-config on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-config/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-config/pom.xml b/spring-cloud/spring-cloud-config/pom.xml index 7fb0c1fd68..5db18a7245 100644 --- a/spring-cloud/spring-cloud-config/pom.xml +++ b/spring-cloud/spring-cloud-config/pom.xml @@ -34,7 +34,7 @@ Hoxton.SR4 - + 2.3.3.RELEASE From d3770851b0fc8fb4133eb73de66a26659b75304e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 14 Dec 2020 12:05:56 +0100 Subject: [PATCH 308/590] JAVA-3570: Keep spring-cloud-zookeeper on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-zookeeper/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-zookeeper/pom.xml b/spring-cloud/spring-cloud-zookeeper/pom.xml index 244ccbd957..e3241da02c 100644 --- a/spring-cloud/spring-cloud-zookeeper/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/pom.xml @@ -20,6 +20,7 @@ 5.2.7.RELEASE 1.0.3.RELEASE + 2.3.3.RELEASE \ No newline at end of file From eb29a0a084435ee8c318978321acf027e6c0ca61 Mon Sep 17 00:00:00 2001 From: Amy DeGregorio Date: Mon, 14 Dec 2020 12:15:23 -0500 Subject: [PATCH 309/590] BAEL-4721 (#10272) * BAEL-4721 Examples * BAEL-4721 Requested edits * Fix formatting issues * Correct unit test name --- .../WriteByteArrayUnitTest.java | 77 ++++++++++++++++++ .../src/test/resources/example-image.jpg | Bin 0 -> 39665 bytes 2 files changed, 77 insertions(+) create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/resources/example-image.jpg diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java new file mode 100644 index 0000000000..ef8c8e2470 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java @@ -0,0 +1,77 @@ +package com.baeldung.writebytearray; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.google.common.io.ByteSink; +import com.google.common.io.MoreFiles; + +public class WriteByteArrayUnitTest { + private static byte[] dataForWriting; + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @BeforeClass + public static void setup() throws IOException { + dataForWriting = Files.readAllBytes(Paths.get("src/test/resources/example-image.jpg")); + } + + @Test + public void whenUsingFileOutputStream_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-fos.jpg"); + try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { + outputStream.write(dataForWriting); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } + } + + @Test + public void whenUsingNioFiles_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-nio-files.jpg"); + Files.write(outputFile.toPath(), dataForWriting); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } + + @Test + public void whenUsingGuavaFiles_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-guava-files.jpg"); + com.google.common.io.Files.write(dataForWriting, outputFile); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } + + @Test + public void whenUsingGuavaByteSink_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-guava-bs.jpg"); + ByteSink byteSink = com.google.common.io.Files.asByteSink(outputFile); + byteSink.write(dataForWriting); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } + + @Test + public void whenUsingGuavaByteSinkMoreFiles_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-guava-bs.jpg"); + ByteSink byteSink = MoreFiles.asByteSink(outputFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); + byteSink.write(dataForWriting); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } + + @Test + public void whenUsingCommonsIo_thenByteArrayIsWritten() throws IOException { + File outputFile = tempFolder.newFile("example-file-utils.jpg"); + FileUtils.writeByteArrayToFile(outputFile, dataForWriting); + assertThat(outputFile).hasBinaryContent(dataForWriting); + } +} diff --git a/core-java-modules/core-java-io-3/src/test/resources/example-image.jpg b/core-java-modules/core-java-io-3/src/test/resources/example-image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..43b8962793fc7289bb9291fe2161e9b3c623f515 GIT binary patch literal 39665 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

    {|wNqGFUU2mnMZ}vT@;YW;e94rGGA6OZs}o7> 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 Date: Mon, 14 Dec 2020 19:24:02 +0100 Subject: [PATCH 310/590] update indentation --- .../baeldung/spring/cloud/client/BookMocks.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BookMocks.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BookMocks.java index 0a64156ba8..2cce72e6cb 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BookMocks.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/BookMocks.java @@ -14,13 +14,14 @@ public class BookMocks { public static void setupMockBooksResponse(WireMockServer mockService) throws IOException { mockService.stubFor(WireMock.get(WireMock.urlEqualTo("/books")) - .willReturn(WireMock.aResponse() - .withStatus(HttpStatus.OK.value()) - .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) - .withBody( - copyToString( - BookMocks.class.getClassLoader().getResourceAsStream("payload/get-books-response.json"), - defaultCharset())))); + .willReturn( + WireMock.aResponse() + .withStatus(HttpStatus.OK.value()) + .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) + .withBody( + copyToString( + BookMocks.class.getClassLoader().getResourceAsStream("payload/get-books-response.json"), + defaultCharset())))); } } From 5e8cf2618a8fb08513b5524b237535c5205ac6b4 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 14 Dec 2020 19:37:05 +0100 Subject: [PATCH 311/590] BAEL-4736 - Convert JSONArray to List of Object using camel-jackson (#10316) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson Co-authored-by: Jonathan Cook --- spring-apache-camel/pom.xml | 11 ++++ .../com/baeldung/camel/jackson/Fruit.java | 24 ++++++++ .../com/baeldung/camel/jackson/FruitList.java | 17 ++++++ .../FruitArrayJacksonUnmarshalUnitTest.java | 60 +++++++++++++++++++ .../FruitListJacksonUnmarshalUnitTest.java | 59 ++++++++++++++++++ .../src/test/resources/json/fruit-array.json | 10 ++++ .../src/test/resources/json/fruit-list.json | 12 ++++ 7 files changed, 193 insertions(+) create mode 100644 spring-apache-camel/src/main/java/com/baeldung/camel/jackson/Fruit.java create mode 100644 spring-apache-camel/src/main/java/com/baeldung/camel/jackson/FruitList.java create mode 100644 spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java create mode 100644 spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java create mode 100644 spring-apache-camel/src/test/resources/json/fruit-array.json create mode 100644 spring-apache-camel/src/test/resources/json/fruit-list.json diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml index 2d0d632546..9c7cc14381 100644 --- a/spring-apache-camel/pom.xml +++ b/spring-apache-camel/pom.xml @@ -47,6 +47,17 @@ camel-spring-javaconfig ${env.camel.version} + + org.apache.camel + camel-jackson + ${env.camel.version} + + + org.apache.camel + camel-test + ${env.camel.version} + test + diff --git a/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/Fruit.java b/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/Fruit.java new file mode 100644 index 0000000000..1932131ddd --- /dev/null +++ b/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/Fruit.java @@ -0,0 +1,24 @@ +package com.baeldung.camel.jackson; + +public class Fruit { + + private String name; + private int id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + +} diff --git a/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/FruitList.java b/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/FruitList.java new file mode 100644 index 0000000000..02f2b6feb0 --- /dev/null +++ b/spring-apache-camel/src/main/java/com/baeldung/camel/jackson/FruitList.java @@ -0,0 +1,17 @@ +package com.baeldung.camel.jackson; + +import java.util.List; + +public class FruitList { + + private List fruits; + + public List getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } + +} diff --git a/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java new file mode 100644 index 0000000000..4810d7370e --- /dev/null +++ b/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.camel.jackson; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.ListJacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { + + @Test + public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = readJsonFromFile("/json/fruit-array.json"); + template.sendBody("direct:jsonInput", json); + assertMockEndpointsSatisfied(); + + @SuppressWarnings("unchecked") + List fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull("Fruit lists should not be null", fruitList); + + assertEquals("There should be two fruits", 2, fruitList.size()); + + Fruit fruit = fruitList.get(0); + assertEquals("Fruit name", "Banana", fruit.getName()); + assertEquals("Fruit id", 100, fruit.getId()); + + fruit = fruitList.get(1); + assertEquals("Fruit name", "Apple", fruit.getName()); + assertEquals("Fruit id", 101, fruit.getId()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + + from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) + .to("mock:marshalledObject"); + } + }; + } + + private String readJsonFromFile(String path) throws URISyntaxException, IOException { + URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path); + return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + } + +} diff --git a/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java new file mode 100644 index 0000000000..b5647f02f9 --- /dev/null +++ b/spring-apache-camel/src/test/java/com/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.camel.jackson; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { + + @Test + public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(FruitList.class); + + String json = readJsonFromFile("/json/fruit-list.json"); + template.sendBody("direct:jsonInput", json); + assertMockEndpointsSatisfied(); + + FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class); + assertNotNull("Fruit lists should not be null", fruitList); + + List fruits = fruitList.getFruits(); + assertEquals("There should be two fruits", 2, fruits.size()); + + Fruit fruit = fruits.get(0); + assertEquals("Fruit name", "Banana", fruit.getName()); + assertEquals("Fruit id", 100, fruit.getId()); + + fruit = fruits.get(1); + assertEquals("Fruit name", "Apple", fruit.getName()); + assertEquals("Fruit id", 101, fruit.getId()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); + } + }; + } + + private String readJsonFromFile(String path) throws URISyntaxException, IOException { + URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path); + return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + } + +} diff --git a/spring-apache-camel/src/test/resources/json/fruit-array.json b/spring-apache-camel/src/test/resources/json/fruit-array.json new file mode 100644 index 0000000000..0bd917c53f --- /dev/null +++ b/spring-apache-camel/src/test/resources/json/fruit-array.json @@ -0,0 +1,10 @@ +[ + { + "id": 100, + "name": "Banana" + }, + { + "id": 101, + "name": "Apple" + } +] \ No newline at end of file diff --git a/spring-apache-camel/src/test/resources/json/fruit-list.json b/spring-apache-camel/src/test/resources/json/fruit-list.json new file mode 100644 index 0000000000..357e08f7d5 --- /dev/null +++ b/spring-apache-camel/src/test/resources/json/fruit-list.json @@ -0,0 +1,12 @@ +{ + "fruits": [ + { + "id": 100, + "name": "Banana" + }, + { + "id": 101, + "name": "Apple" + } + ] +} \ No newline at end of file From abfc9637073d44f6f83a86000786264496ecf646 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Dec 2020 17:21:52 +0800 Subject: [PATCH 312/590] Update README.md --- core-java-modules/core-java-collections-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-4/README.md b/core-java-modules/core-java-collections-4/README.md index 1c680b86ba..6e117c98b1 100644 --- a/core-java-modules/core-java-collections-4/README.md +++ b/core-java-modules/core-java-collections-4/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: -- TODO: add article links here +- [ArrayList vs. LinkedList vs. HashMap in Java](https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap) From 42604275ff2b848400545a44e394319567ee790b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Dec 2020 17:24:51 +0800 Subject: [PATCH 313/590] Update README.md --- persistence-modules/core-java-persistence-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/core-java-persistence-2/README.md b/persistence-modules/core-java-persistence-2/README.md index 467de757ce..36c33cc6e1 100644 --- a/persistence-modules/core-java-persistence-2/README.md +++ b/persistence-modules/core-java-persistence-2/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Getting Database URL From JDBC Connection Object](https://www.baeldung.com/jdbc-get-url-from-connection) +- [JDBC URL Format For Different Databases](https://www.baeldung.com/java-jdbc-url-format) From 11cd12ffb58ce125dbd8288706538cfb49609842 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Dec 2020 17:39:28 +0800 Subject: [PATCH 314/590] Update README.md --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index bb5e204c98..9b99d624c9 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -14,4 +14,5 @@ This module contains articles about core Java Security - [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates) - [Security Context Basics: User, Subject and Principal](https://www.baeldung.com/security-context-basics) - [Java AES Encryption and Decryption](https://www.baeldung.com/java-aes-encryption-decryption) +- [InvalidAlgorithmParameterException: Wrong IV Length](https://www.baeldung.com/java-invalidalgorithmparameter-exception) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From c6dd691407d8c9a49d3853f32a118d5f8cf788d1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Dec 2020 17:41:24 +0800 Subject: [PATCH 315/590] 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 36617a210e..d0ac5387a8 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -13,4 +13,5 @@ This module contains articles about core Java input and output (IO) - [Reading a Line at a Given Line Number From a File in Java](https://www.baeldung.com/java-read-line-at-number) - [Find the Last Modified File in a Directory with Java](https://www.baeldung.com/java-last-modified-file) - [Get a Filename Without the Extension in Java](https://www.baeldung.com/java-filename-without-extension) +- [Writing byte[] to a File in Java](https://www.baeldung.com/java-write-byte-array-file) - [[<-- Prev]](/core-java-modules/core-java-io-2) From 8a9c1a1911594488d7e0e8f8a6384f260a1e036b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 16 Dec 2020 16:38:31 -0300 Subject: [PATCH 316/590] migrated spring.profiles properties to spring.config.activate.on-profile --- .../src/main/resources/application.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml index fc9bb42a95..61d462bb5a 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml @@ -6,7 +6,9 @@ spring: --- spring: - profiles: test + config: + activate: + on-profile: test name: test-YAML environment: testing enabled: false @@ -37,7 +39,9 @@ component: --- spring: - profiles: prod + config: + activate: + on-profile: prod name: prod-YAML environment: production enabled: true @@ -48,7 +52,9 @@ servers: --- spring: - profiles: dev + config: + activate: + on-profile: dev name: ${DEV_NAME:dev-YAML} environment: development enabled: true From 7b17a09eb74b9401b7d28a85d0ea2bfd660ccdfe Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 16 Dec 2020 16:53:33 -0300 Subject: [PATCH 317/590] avoid using deprecated StringUtils#isEmpty method --- .../properties/reloading/configs/ReloadablePropertySource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java index 6d76a2e1e2..5d4e170226 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java @@ -15,7 +15,7 @@ public class ReloadablePropertySource extends PropertySource { } public ReloadablePropertySource(String name, String path) { - super(StringUtils.isEmpty(name) ? path : name); + super(StringUtils.hasText(name) ? path : name); try { this.propertiesConfiguration = new PropertiesConfiguration(path); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); From fbf57804b87ab53a5096c3f54f2498189e100b2e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 20:54:29 +0100 Subject: [PATCH 318/590] JAVA-3570: Keep spring-cloud-bus on Spring Boot 2.3.3 [cloud] --- spring-cloud-bus/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-bus/pom.xml b/spring-cloud-bus/pom.xml index ec56e23ac7..15eed8dcf0 100644 --- a/spring-cloud-bus/pom.xml +++ b/spring-cloud-bus/pom.xml @@ -35,6 +35,7 @@ Hoxton.SR4 + 2.3.3.RELEASE From 7b0de8a7031b00df90c47983ac34abae2b04cf9a Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 21:00:33 +0100 Subject: [PATCH 319/590] JAVA-3570: Keep spring-cloud-ribbon-client on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-ribbon-client/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-ribbon-client/pom.xml b/spring-cloud/spring-cloud-ribbon-client/pom.xml index fa9cee29a2..7bc7b51d51 100644 --- a/spring-cloud/spring-cloud-ribbon-client/pom.xml +++ b/spring-cloud/spring-cloud-ribbon-client/pom.xml @@ -46,6 +46,7 @@ Hoxton.SR4 + 2.3.3.RELEASE \ No newline at end of file From 080dd971f8c0c878620bd68304005e7582c890db Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 21:03:50 +0100 Subject: [PATCH 320/590] JAVA-3570: Keep spring-cloud-security on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-security/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-security/pom.xml b/spring-cloud/spring-cloud-security/pom.xml index 3a007c8df1..f861b892c0 100644 --- a/spring-cloud/spring-cloud-security/pom.xml +++ b/spring-cloud/spring-cloud-security/pom.xml @@ -21,5 +21,6 @@ + 2.3.3.RELEASE From 26eff5ca447a8f9e3c4f4005b0d8bd1b8d16778c Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 21:14:09 +0100 Subject: [PATCH 321/590] JAVA-3570: Upgrade Spring framework to version compatible with Spring Boot 2.4 in spring-core-2 --- spring-core-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-core-2/pom.xml b/spring-core-2/pom.xml index edbb351bd0..3f8e84e13d 100644 --- a/spring-core-2/pom.xml +++ b/spring-core-2/pom.xml @@ -198,7 +198,7 @@ com.baeldung.sample.App - 5.2.2.RELEASE + 5.3.0 1.3.2 5.2.5.Final From 3d17425795b3c5f0c3ee4dd2a3459aa16c75bb53 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 21:22:30 +0100 Subject: [PATCH 322/590] JAVA-3570: Register DefaultServlet in spring-social-login --- spring-social-login/src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-social-login/src/main/resources/application.properties b/spring-social-login/src/main/resources/application.properties index 2bd99d8239..22e6acf9e2 100644 --- a/spring-social-login/src/main/resources/application.properties +++ b/spring-social-login/src/main/resources/application.properties @@ -1,3 +1,4 @@ spring.social.facebook.appId=1715784745414888 spring.social.facebook.appSecret=abefd6497e9cc01ad03be28509617bf0 -spring.thymeleaf.cache=false \ No newline at end of file +spring.thymeleaf.cache=false +server.servlet.register-default-servlet=true \ No newline at end of file From d7cb1a586fe508b44ff021ecf1da04d71de17de2 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 16 Dec 2020 21:28:39 +0100 Subject: [PATCH 323/590] JAVA-3570: Keep spring-cloud-kubernetes on Spring Boot 2.3.3 [cloud] --- spring-cloud/spring-cloud-kubernetes/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml index a3669d2d55..44c429d8f5 100644 --- a/spring-cloud/spring-cloud-kubernetes/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/pom.xml @@ -25,5 +25,6 @@ + 2.3.3.RELEASE \ No newline at end of file From d4b22c74e3ab06291ba92585f136342c347b83e2 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Thu, 17 Dec 2020 14:02:59 +0200 Subject: [PATCH 324/590] BAEL-4687: updated formatting --- .../boot/jackson/controller/CoffeeController.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java index a960dafd89..ad2f6ab942 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java @@ -1,20 +1,21 @@ package com.baeldung.boot.jackson.controller; -import java.time.LocalDateTime; - +import com.baeldung.boot.jackson.model.Coffee; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.boot.jackson.model.Coffee; +import java.time.LocalDateTime; @RestController public class CoffeeController { @GetMapping("/coffee") - public Coffee getCoffee(@RequestParam(required = false) String brand, @RequestParam(required = false) String name) { + public Coffee getCoffee( + @RequestParam(required = false) String brand, + @RequestParam(required = false) String name) { return new Coffee().setBrand(brand) - .setDate(LocalDateTime.now()) - .setName(name); + .setDate(LocalDateTime.now()) + .setName(name); } } From d8f681c38e2d3dd8981a942e90e69778a3485840 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Thu, 17 Dec 2020 14:23:06 +0200 Subject: [PATCH 325/590] BAEL-4687: returned fixed date instead of dynamic --- .../boot/jackson/config/CoffeeConstants.java | 10 ++++++---- .../boot/jackson/config/CoffeeCustomizerConfig.java | 7 +++---- .../config/CoffeeHttpConverterConfiguration.java | 7 +++---- .../jackson/config/CoffeeJacksonBuilderConfig.java | 7 +++---- .../jackson/config/CoffeeObjectMapperConfig.java | 13 ++++++------- .../jackson/config/CoffeeRegisterModuleConfig.java | 9 ++++----- .../boot/jackson/controller/CoffeeController.java | 4 ++-- .../jackson/app/AbstractCoffeeIntegrationTest.java | 9 +++++---- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java index 90cad011ae..d1875d03d9 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeConstants.java @@ -1,11 +1,13 @@ package com.baeldung.boot.jackson.config; -import java.time.format.DateTimeFormatter; - import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + public class CoffeeConstants { - public static final String dateTimeFormat = "dd-MM-yyyy HH:mm"; - public static LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)); + public static final String DATETIME_FORMAT = "dd-MM-yyyy HH:mm"; + public static final LocalDateTime FIXED_DATE = LocalDateTime.now(); + public static LocalDateTimeSerializer LOCAL_DATETIME_SERIALIZER = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATETIME_FORMAT)); } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java index 363c67fd9a..edb2b478fc 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeCustomizerConfig.java @@ -1,12 +1,11 @@ package com.baeldung.boot.jackson.config; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; - +import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER; @Configuration public class CoffeeCustomizerConfig { @@ -14,6 +13,6 @@ public class CoffeeCustomizerConfig { @Bean public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL) - .serializers(localDateTimeSerializer); + .serializers(LOCAL_DATETIME_SERIALIZER); } } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java index b67f215816..eff2b5c252 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeHttpConverterConfiguration.java @@ -1,13 +1,12 @@ package com.baeldung.boot.jackson.config; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; - +import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER; @Configuration public class CoffeeHttpConverterConfiguration { @@ -15,7 +14,7 @@ public class CoffeeHttpConverterConfiguration { @Bean public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) + .serializers(LOCAL_DATETIME_SERIALIZER) .serializationInclusion(JsonInclude.Include.NON_NULL); return new MappingJackson2HttpMessageConverter(builder.build()); } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java index ec4de1d353..8057fff3db 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeJacksonBuilderConfig.java @@ -1,13 +1,12 @@ package com.baeldung.boot.jackson.config; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; - +import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import com.fasterxml.jackson.annotation.JsonInclude; +import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER; @Configuration public class CoffeeJacksonBuilderConfig { @@ -16,7 +15,7 @@ public class CoffeeJacksonBuilderConfig { @Primary public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { return new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) + .serializers(LOCAL_DATETIME_SERIALIZER) .serializationInclusion(JsonInclude.Include.NON_NULL); } } \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java index 3754de018a..f1ce6458ae 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeObjectMapperConfig.java @@ -1,14 +1,13 @@ package com.baeldung.boot.jackson.config; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER; @Configuration public class CoffeeObjectMapperConfig { @@ -17,7 +16,7 @@ public class CoffeeObjectMapperConfig { @Primary public ObjectMapper objectMapper() { JavaTimeModule module = new JavaTimeModule(); - module.addSerializer(localDateTimeSerializer); + module.addSerializer(LOCAL_DATETIME_SERIALIZER); return new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL) .registerModule(module); } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java index ea00e5a58e..fc157f8156 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/config/CoffeeRegisterModuleConfig.java @@ -1,13 +1,12 @@ package com.baeldung.boot.jackson.config; -import static com.baeldung.boot.jackson.config.CoffeeConstants.localDateTimeSerializer; - +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER; @Configuration @PropertySource("classpath:coffee.properties") @@ -16,7 +15,7 @@ public class CoffeeRegisterModuleConfig { @Bean public Module javaTimeModule() { JavaTimeModule module = new JavaTimeModule(); - module.addSerializer(localDateTimeSerializer); + module.addSerializer(LOCAL_DATETIME_SERIALIZER); return module; } } diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java index ad2f6ab942..23749b18a2 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/jackson/controller/CoffeeController.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; +import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE; @RestController public class CoffeeController { @@ -15,7 +15,7 @@ public class CoffeeController { @RequestParam(required = false) String brand, @RequestParam(required = false) String name) { return new Coffee().setBrand(brand) - .setDate(LocalDateTime.now()) + .setDate(FIXED_DATE) .setName(name); } } diff --git a/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java index 13e1f05f97..f1bc35a8ce 100644 --- a/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java +++ b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/jackson/app/AbstractCoffeeIntegrationTest.java @@ -6,9 +6,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -19,13 +19,14 @@ public abstract class AbstractCoffeeIntegrationTest { @Test public void whenGetCoffee_thenSerializedWithDateAndNonNull() { - String formattedDate = DateTimeFormatter.ofPattern(CoffeeConstants.dateTimeFormat) - .format(LocalDateTime.now()); + String formattedDate = DateTimeFormatter.ofPattern(CoffeeConstants.DATETIME_FORMAT) + .format(FIXED_DATE); String brand = "Lavazza"; - String url = "/coffee?brand=" + brand; + String response = restTemplate.getForObject(url, String.class); + assertThat(response).isEqualTo( "{\"brand\":\"" + brand + "\",\"date\":\"" + formattedDate + "\"}"); } From 450c0fe6dbc87f7955b87c5a7666d990cb88e34b Mon Sep 17 00:00:00 2001 From: bnasslah Date: Thu, 17 Dec 2020 13:49:42 +0100 Subject: [PATCH 326/590] upgrade to springdoc-openapi v1.5.2 --- .../spring-boot-springdoc/pom.xml | 2 +- .../springdoc/controller/BookController.java | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml index ed272200da..46c9a6a1b4 100644 --- a/spring-boot-modules/spring-boot-springdoc/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/pom.xml @@ -171,7 +171,7 @@ 1.8 5.2.10.Final - 1.2.32 + 1.5.2 1.5.6 1.2.71 ${project.build.directory}/generated-snippets diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/BookController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/BookController.java index 326a97149b..f2355a2ec3 100644 --- a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/BookController.java +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/BookController.java @@ -5,6 +5,17 @@ import java.util.Collection; import javax.validation.Valid; import javax.validation.constraints.NotNull; +import com.baeldung.springdoc.exception.BookNotFoundException; +import com.baeldung.springdoc.model.Book; +import com.baeldung.springdoc.repository.BookRepository; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springdoc.api.annotations.ParameterObject; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -21,17 +32,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.springdoc.exception.BookNotFoundException; -import com.baeldung.springdoc.model.Book; -import com.baeldung.springdoc.repository.BookRepository; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; - @RestController @RequestMapping("/api/book") public class BookController { @@ -58,7 +58,7 @@ public class BookController { } @GetMapping("/filter") - public Page filterBooks(Pageable pageable) { + public Page filterBooks(@ParameterObject Pageable pageable) { return repository.getBooks(pageable); } From 83e87aebc081a13f061ed251ce73e4d9c05943ec Mon Sep 17 00:00:00 2001 From: mdabrowski-eu <57441874+mdabrowski-eu@users.noreply.github.com> Date: Fri, 18 Dec 2020 06:13:31 +0100 Subject: [PATCH 327/590] BAEL-4718 using bytes array as key in HashMap (#10315) --- .../com/baeldung/map/bytearrays/BytesKey.java | 28 +++++ .../map/bytearrays/ByteArrayKeyUnitTest.java | 104 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/bytearrays/BytesKey.java create mode 100644 java-collections-maps-3/src/test/java/com/baeldung/map/bytearrays/ByteArrayKeyUnitTest.java diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/bytearrays/BytesKey.java b/java-collections-maps-3/src/main/java/com/baeldung/map/bytearrays/BytesKey.java new file mode 100644 index 0000000000..4bdcfe4b06 --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/bytearrays/BytesKey.java @@ -0,0 +1,28 @@ +package com.baeldung.map.bytearrays; + +import java.util.Arrays; + +public final class BytesKey { + private final byte[] array; + + public BytesKey(byte[] array) { + this.array = array; + } + + public byte[] getArray() { + return array.clone(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BytesKey bytesKey = (BytesKey) o; + return Arrays.equals(array, bytesKey.array); + } + + @Override + public int hashCode() { + return Arrays.hashCode(array); + } +} diff --git a/java-collections-maps-3/src/test/java/com/baeldung/map/bytearrays/ByteArrayKeyUnitTest.java b/java-collections-maps-3/src/test/java/com/baeldung/map/bytearrays/ByteArrayKeyUnitTest.java new file mode 100644 index 0000000000..8f5b89e11e --- /dev/null +++ b/java-collections-maps-3/src/test/java/com/baeldung/map/bytearrays/ByteArrayKeyUnitTest.java @@ -0,0 +1,104 @@ +package com.baeldung.map.bytearrays; + +import com.google.common.collect.ImmutableList; +import org.junit.jupiter.api.Test; + +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class ByteArrayKeyUnitTest { + @Test + void givenPrimitiveByteArrayKey_whenRetrievingFromMap_shouldRetrieveDifferentObjects() { + // given + byte[] key1 = {1, 2, 3}; + byte[] key2 = {1, 2, 3}; + String value1 = "value1"; + String value2 = "value2"; + Map map = new HashMap<>(); + map.put(key1, value1); + map.put(key2, value2); + + // when + String retrievedValue1 = map.get(key1); + String retrievedValue2 = map.get(key2); + String retrievedValue3 = map.get(new byte[]{1, 2, 3}); + + // then + assertThat(retrievedValue1).isEqualTo(value1); + assertThat(retrievedValue2).isEqualTo(value2); + assertThat(retrievedValue3).isNull(); + } + + @Test + void givenEncodedStringKey_whenRetrievingFromMap_shouldRetrieveLastPutObject() { + // given + String key1 = Base64.getEncoder().encodeToString(new byte[]{1, 2, 3}); + String key2 = Base64.getEncoder().encodeToString(new byte[]{1, 2, 3}); + String value1 = "value1"; + String value2 = "value2"; + Map map = new HashMap<>(); + map.put(key1, value1); + map.put(key2, value2); + + // when + String retrievedValue1 = map.get(key1); + String retrievedValue2 = map.get(key2); + + // then + assertThat(key1).isEqualTo(key2); + assertThat(retrievedValue1).isEqualTo(value2); + assertThat(retrievedValue2).isEqualTo(value2); + assertThat(retrievedValue1).isEqualTo(retrievedValue2); + } + + @Test + void givenByteListKey_whenRetrievingFromMap_shouldRetrieveLastPutObject() { + // given + List key1 = ImmutableList.of((byte)1, (byte)2, (byte)3); + List key2 = ImmutableList.of((byte)1, (byte)2, (byte)3); + String value1 = "value1"; + String value2 = "value2"; + Map, String> map = new HashMap<>(); + map.put(key1, value1); + map.put(key2, value2); + + // when + String retrievedValue1 = map.get(key1); + String retrievedValue2 = map.get(key2); + + // then + assertThat(key1).isEqualTo(key2); + assertThat(retrievedValue1).isEqualTo(value2); + assertThat(retrievedValue2).isEqualTo(value2); + assertThat(retrievedValue1).isEqualTo(retrievedValue2); + } + + @Test + void givenCustomWrapperKey_whenRetrievingFromMap_shouldRetrieveLastPutObject() { + // given + BytesKey key1 = new BytesKey(new byte[]{1, 2, 3}); + BytesKey key2 = new BytesKey(new byte[]{1, 2, 3}); + String value1 = "value1"; + String value2 = "value2"; + Map map = new HashMap<>(); + map.put(key1, value1); + map.put(key2, value2); + + // when + String retrievedValue1 = map.get(key1); + String retrievedValue2 = map.get(key2); + String retrievedValue3 = map.get(new BytesKey(new byte[]{1, 2, 3})); + + // then + assertThat(key1).isEqualTo(key2); + assertThat(retrievedValue1).isEqualTo(value2); + assertThat(retrievedValue2).isEqualTo(value2); + assertThat(retrievedValue1).isEqualTo(retrievedValue2); + assertThat(retrievedValue3).isEqualTo(value2); + + } +} From f542a4afabed15cd2617cae535ca2cfc2a294f81 Mon Sep 17 00:00:00 2001 From: Trixi-Turny Date: Fri, 18 Dec 2020 09:11:27 +0000 Subject: [PATCH 328/590] Bael 4457 list of json objects with rest template (#10058) * Add users.json * BAEL-4457 demo app with Object array and ParameterizedTypeReference example * BAEL-4457 write unit tests * BAEL-4456 remove new directory * BAEL-4457 fix pom and testname * BAEL-4457 use default target release * BAEL-4457 add more examples of processing the objects and address comments * BAEL-4457 remove new ArrayList and put @ResponseBody before public * BAEL-4457 use static userJson object * BAEL-4456 tidy up extra spaces * BAEL-4457 removed too many brackets * BAEL-4457 remove incorrect assertion * BAEL-4457 use a service instead of another controller * BAEL-4457 use ObjectMapper to extract usernames from objects * BAEL-4457 fix UserController * BAEL-4457 delete provider service and controller * BAEL-4457 use functional interface where possible * BAEL-4457 remove unnecessary annotations and tidy indents for exchange() * BAEL-4457 use @JsonCreator and @JsonProperty and resolve comments * BAEL-4457 improve comment * BAEL-4457 remove comments and use assertj core lib for assertions * BAEL-4457 fix indents Co-authored-by: Trixi Turny --- spring-resttemplate-2/pom.xml | 14 +- .../consumer/service/UserConsumerService.java | 16 +++ .../service/UserConsumerServiceImpl.java | 90 +++++++++++++ .../resttemplate/json/model/Address.java | 29 ++++ .../resttemplate/json/model/User.java | 30 +++++ .../UserConsumerServiceImplUnitTest.java | 127 ++++++++++++++++++ 6 files changed, 299 insertions(+), 7 deletions(-) create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java create mode 100644 spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java diff --git a/spring-resttemplate-2/pom.xml b/spring-resttemplate-2/pom.xml index 2aed154be6..1404a35f33 100644 --- a/spring-resttemplate-2/pom.xml +++ b/spring-resttemplate-2/pom.xml @@ -71,16 +71,16 @@ ch.qos.logback logback-classic - + - + - - org.springframework.boot - spring-boot-maven-plugin - + + org.springframework.boot + spring-boot-maven-plugin + - + \ No newline at end of file diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java new file mode 100644 index 0000000000..751e234e8b --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java @@ -0,0 +1,16 @@ +package com.baeldung.resttemplate.json.consumer.service; + +import java.util.List; + +public interface UserConsumerService { + + List processUserDataFromObjectArray(); + + List processUserDataFromUserArray(); + + List processUserDataFromUserList(); + + List processNestedUserDataFromUserArray(); + + List processNestedUserDataFromUserList(); +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java new file mode 100644 index 0000000000..dc1566d971 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java @@ -0,0 +1,90 @@ +package com.baeldung.resttemplate.json.consumer.service; + +import com.baeldung.resttemplate.json.model.Address; +import com.baeldung.resttemplate.json.model.User; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class UserConsumerServiceImpl implements UserConsumerService { + + private static final String BASE_URL = "http://localhost:8080/users"; + private final RestTemplate restTemplate; + private static final ObjectMapper mapper = new ObjectMapper(); + + public UserConsumerServiceImpl(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + @Override + public List processUserDataFromObjectArray() { + ResponseEntity responseEntity = restTemplate.getForEntity(BASE_URL, Object[].class); + Object[] objects = responseEntity.getBody(); + return Arrays.stream(objects) + .map(object -> mapper.convertValue(object, User.class)) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserArray() { + ResponseEntity responseEntity = restTemplate.getForEntity(BASE_URL, User[].class); + User[] userArray = responseEntity.getBody(); + return Arrays.stream(userArray) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserList() { + ResponseEntity> responseEntity = + restTemplate.exchange( + BASE_URL, + HttpMethod.GET, + null, + new ParameterizedTypeReference>() {} + ); + List users = responseEntity.getBody(); + return users.stream() + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserArray() { + ResponseEntity responseEntity = restTemplate.getForEntity(BASE_URL, User[].class); + User[] userArray = responseEntity.getBody(); + //we can get more info if we need : + MediaType contentType = responseEntity.getHeaders().getContentType(); + HttpStatus statusCode = responseEntity.getStatusCode(); + + return Arrays.stream(userArray) + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserList() { + ResponseEntity> responseEntity = + restTemplate.exchange( + BASE_URL, + HttpMethod.GET, + null, + new ParameterizedTypeReference>() {} + ); + List userList = responseEntity.getBody(); + return userList.stream() + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java new file mode 100644 index 0000000000..f41ff4d8ea --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java @@ -0,0 +1,29 @@ +package com.baeldung.resttemplate.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Address { + private final String addressLine1; + private final String addressLine2; + private final String town; + private final String postCode; + + @JsonCreator + public Address( + @JsonProperty("addressLine1") String addressLine1, + @JsonProperty("addressLine2") String addressLine2, + @JsonProperty("town") String town, + @JsonProperty("postCode") String postCode) { + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.town = town; + this.postCode = postCode; + } + public String getPostCode() { + return postCode; + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java new file mode 100644 index 0000000000..8e02ef7787 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java @@ -0,0 +1,30 @@ +package com.baeldung.resttemplate.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User { + private final int id; + private final String name; + private final List

    addressList; + + @JsonCreator + public User( + @JsonProperty("id") int id, + @JsonProperty("name") String name, + @JsonProperty("addressList") List
    addressList) { + this.id = id; + this.name = name; + this.addressList = addressList; + } + + public String getName() { + return name; + } + + public List
    getAddressList() { return addressList; } +} diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java new file mode 100644 index 0000000000..4cc58e30f5 --- /dev/null +++ b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java @@ -0,0 +1,127 @@ +package com.baeldung.resttemplate.json.consumer.service; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.web.client.ExpectedCount; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; + +@SpringBootTest +public class UserConsumerServiceImplUnitTest { + + private static String USER_JSON = "[{\"id\":1,\"name\":\"user1\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user1_address1_postCode\"}," + + "{\"addressLine1\":\"address2_addressLine1\",\"addressLine2\":\"address2_addressLine2\",\"town\":\"address2_town\",\"postCode\":\"user1_address2_postCode\"}]}," + + "{\"id\":2,\"name\":\"user2\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user2_address1_postCode\"}]}]"; + + private MockRestServiceServer mockServer; + private final RestTemplate restTemplate = new RestTemplate(); + private final UserConsumerService tested = new UserConsumerServiceImpl(restTemplate); + + @Before + public void init() { + mockServer = MockRestServiceServer.createServer(restTemplate); + } + + @Test + public void whenProcessUserDataAsObjects_thenOK() { + String url = "http://localhost:8080/users"; + List expected = Arrays.asList("user1", "user2"); + + mockServer.expect(ExpectedCount.once(), + requestTo(url)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withStatus(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(USER_JSON)); + + List actual = tested.processUserDataFromObjectArray(); + + mockServer.verify(); + assertThat(actual).containsExactly(expected.get(0), expected.get(1)); + } + + @Test + public void whenProcessUserDataAsArray_thenOK() { + String url = "http://localhost:8080/users"; + List expected = Arrays.asList("user1", "user2"); + + mockServer.expect(ExpectedCount.once(), + requestTo(url)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withStatus(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(USER_JSON)); + + List actual = tested.processUserDataFromUserArray(); + + mockServer.verify(); + assertThat(actual).containsExactly(expected.get(0), expected.get(1)); + } + + @Test + public void whenProcessUserDataAsList_thenOK() { + String url = "http://localhost:8080/users"; + List expected = Arrays.asList("user1", "user2"); + + mockServer.expect(ExpectedCount.once(), + requestTo(url)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withStatus(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(USER_JSON)); + + List actual = tested.processUserDataFromUserList(); + + mockServer.verify(); + assertThat(actual).containsExactly(expected.get(0), expected.get(1)); + } + + + @Test + public void whenProcessNestedUserDataFromArray_thenOK() { + String url = "http://localhost:8080/users"; + List expected = Arrays.asList("user1_address1_postCode", "user1_address2_postCode", "user2_address1_postCode"); + + mockServer.expect(ExpectedCount.once(), + requestTo(url)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withStatus(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(USER_JSON)); + + List actual = tested.processNestedUserDataFromUserArray(); + + mockServer.verify(); + assertThat(actual).containsExactly(expected.get(0), expected.get(1), expected.get(2)); + } + + @Test + public void whenProcessNestedUserDataFromList_thenOK() { + String url = "http://localhost:8080/users"; + List expected = Arrays.asList("user1_address1_postCode", "user1_address2_postCode", "user2_address1_postCode"); + + mockServer.expect(ExpectedCount.once(), + requestTo(url)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withStatus(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(USER_JSON)); + + List actual = tested.processNestedUserDataFromUserList(); + + mockServer.verify(); + assertThat(actual).containsExactly(expected.get(0), expected.get(1), expected.get(2)); + } +} \ No newline at end of file From 9a7a3fdac34d633480a40eb84f7cf7511dfbf24c Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 18 Dec 2020 10:14:23 +0100 Subject: [PATCH 329/590] JAVA-3570: Fix spring-security-oauth2 version in spring-security-oauth2-sso --- spring-security-modules/spring-security-oauth2-sso/pom.xml | 4 ++-- .../src/main/resources/application.yml | 1 + .../spring-security-sso-ui/src/main/resources/application.yml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-security-modules/spring-security-oauth2-sso/pom.xml b/spring-security-modules/spring-security-oauth2-sso/pom.xml index ed4b1d64ba..a272ba5b50 100644 --- a/spring-security-modules/spring-security-oauth2-sso/pom.xml +++ b/spring-security-modules/spring-security-oauth2-sso/pom.xml @@ -24,8 +24,8 @@ 3.1.0 - 2.3.3.RELEASE - 2.1.1.RELEASE + 2.4.0.RELEASE + 2.4.0 1.0.1.RELEASE 2.0.0-M2 diff --git a/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml index 97c8de7839..8cee9f24d5 100644 --- a/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml +++ b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml @@ -2,6 +2,7 @@ server: port: 8083 servlet: context-path: /ui2 + register-default-servlet: true session: cookie: name: UI2SESSION diff --git a/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml index d1d9ea6ebc..f98dee9429 100644 --- a/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml +++ b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml @@ -2,6 +2,7 @@ server: port: 8082 servlet: context-path: /ui + register-default-servlet: true session: cookie: name: UISESSION From 0c926e74413c8e2b011358b4db1e32deb1730717 Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Sat, 19 Dec 2020 12:58:00 +0000 Subject: [PATCH 330/590] BAEL-4071 - Get advised method info in Spring AOP Fixing identation --- .../com/baeldung/method/info/Account.java | 39 ++++++------- .../method/info/AccountOperation.java | 2 +- .../method/info/BankAccountAspect.java | 54 +++++++++--------- .../method/info/BankAccountService.java | 29 +++++----- .../method/info/WithdrawLimitException.java | 8 +-- .../BankAccountServiceIntegrationTest.java | 57 ++++++++++--------- 6 files changed, 94 insertions(+), 95 deletions(-) diff --git a/spring-aop/src/main/java/com/baeldung/method/info/Account.java b/spring-aop/src/main/java/com/baeldung/method/info/Account.java index 1c946501fd..646e403f1e 100644 --- a/spring-aop/src/main/java/com/baeldung/method/info/Account.java +++ b/spring-aop/src/main/java/com/baeldung/method/info/Account.java @@ -2,30 +2,27 @@ package com.baeldung.method.info; public class Account { - private String accountNumber; - private double balance; + private String accountNumber; + private double balance; - public String getAccountNumber() { - return accountNumber; - } + public String getAccountNumber() { + return accountNumber; + } - public void setAccountNumber(String accountNumber) { - this.accountNumber = accountNumber; - } + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } - public double getBalance() { - return balance; - } + public double getBalance() { + return balance; + } - public void setBalance(double balance) { - this.balance = balance; - } + public void setBalance(double balance) { + this.balance = balance; + } - @Override - public String toString() { - return "Account{" + - "accountNumber='" + accountNumber + '\'' + - ", balance=" + balance + - '}'; - } + @Override + public String toString() { + return "Account{" + "accountNumber='" + accountNumber + '\'' + ", balance=" + balance + '}'; + } } diff --git a/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java b/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java index db725a724f..74bc60a6db 100644 --- a/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java +++ b/spring-aop/src/main/java/com/baeldung/method/info/AccountOperation.java @@ -8,5 +8,5 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface AccountOperation { - String operation(); + String operation(); } diff --git a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java index 6c8ef9d8d6..f743758cd7 100644 --- a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java +++ b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountAspect.java @@ -14,40 +14,42 @@ import java.util.Arrays; @Component public class BankAccountAspect { - @Before(value="@annotation(com.baeldung.method.info.AccountOperation)") - public void getAccountOperationInfo(JoinPoint joinPoint) { + @Before(value = "@annotation(com.baeldung.method.info.AccountOperation)") + public void getAccountOperationInfo(JoinPoint joinPoint) { - //Method Information - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + // Method Information + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - System.out.println("full method description: " + signature.getMethod()); + System.out.println("full method description: " + signature.getMethod()); - System.out.println("method name: " + signature.getMethod().getName()); + System.out.println("method name: " + signature.getMethod().getName()); - System.out.println("declaring type: " + signature.getDeclaringType()); + System.out.println("declaring type: " + signature.getDeclaringType()); - //Method args - System.out.println("Method args names:"); - Arrays.stream(signature.getParameterNames()).forEach(s -> System.out.println("arg name: " + s)); + // Method args + System.out.println("Method args names:"); + Arrays.stream(signature.getParameterNames()) + .forEach(s -> System.out.println("arg name: " + s)); - System.out.println("Method args types:"); - Arrays.stream(signature.getParameterTypes()).forEach(s -> System.out.println("arg type: " + s)); + System.out.println("Method args types:"); + Arrays.stream(signature.getParameterTypes()) + .forEach(s -> System.out.println("arg type: " + s)); - System.out.println("Method args values:"); - Arrays.stream(joinPoint.getArgs()).forEach(o -> System.out.println("arg value: " + o.toString())); + System.out.println("Method args values:"); + Arrays.stream(joinPoint.getArgs()) + .forEach(o -> System.out.println("arg value: " + o.toString())); - //Additional Information - System.out.println("returning type: " + signature.getReturnType()); - System.out.println("method modifier: " + Modifier.toString(signature.getModifiers())); - Arrays.stream(signature.getExceptionTypes()) - .forEach(aClass -> System.out.println("exception type: " + aClass)); + // Additional Information + System.out.println("returning type: " + signature.getReturnType()); + System.out.println("method modifier: " + Modifier.toString(signature.getModifiers())); + Arrays.stream(signature.getExceptionTypes()) + .forEach(aClass -> System.out.println("exception type: " + aClass)); - //Method annotation - Method method = signature.getMethod(); - AccountOperation accountOperation = method.getAnnotation(AccountOperation.class); - System.out.println("Account operation annotation: " + accountOperation); - System.out.println("Account operation value: " + accountOperation.operation()); + // Method annotation + Method method = signature.getMethod(); + AccountOperation accountOperation = method.getAnnotation(AccountOperation.class); + System.out.println("Account operation annotation: " + accountOperation); + System.out.println("Account operation value: " + accountOperation.operation()); - } + } } - diff --git a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java index 4c7d0e3cac..6ebab37d9e 100644 --- a/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java +++ b/spring-aop/src/main/java/com/baeldung/method/info/BankAccountService.java @@ -6,25 +6,24 @@ import org.springframework.stereotype.Component; @Component public class BankAccountService { - @AccountOperation(operation = "deposit") - public void deposit(Account account, Double amount) { - account.setBalance(account.getBalance() + amount); - } - - @AccountOperation(operation = "withdraw") - public void withdraw(Account account, Double amount) throws WithdrawLimitException { - - if(amount > 500.0) { - throw new WithdrawLimitException("Withdraw limit exceeded."); + @AccountOperation(operation = "deposit") + public void deposit(Account account, Double amount) { + account.setBalance(account.getBalance() + amount); } - account.setBalance(account.getBalance() - amount); + @AccountOperation(operation = "withdraw") + public void withdraw(Account account, Double amount) throws WithdrawLimitException { - } + if (amount > 500.0) { + throw new WithdrawLimitException("Withdraw limit exceeded."); + } - public double getBalance() { - return RandomUtils.nextDouble(); - } + account.setBalance(account.getBalance() - amount); + } + + public double getBalance() { + return RandomUtils.nextDouble(); + } } diff --git a/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java b/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java index 85b0b4acfb..b29a27c94f 100644 --- a/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java +++ b/spring-aop/src/main/java/com/baeldung/method/info/WithdrawLimitException.java @@ -1,7 +1,7 @@ package com.baeldung.method.info; -public class WithdrawLimitException extends RuntimeException { - public WithdrawLimitException(String message) { - super(message); - } +public class WithdrawLimitException extends RuntimeException { + public WithdrawLimitException(String message) { + super(message); + } } diff --git a/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java b/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java index 9e0ebfa903..b1ba97654e 100644 --- a/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java +++ b/spring-aop/src/test/java/com/baeldung/method/info/BankAccountServiceIntegrationTest.java @@ -11,38 +11,39 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest class BankAccountServiceIntegrationTest { - private Account account; + private Account account; - @BeforeEach - public void setup() { - account = new Account(); - account.setAccountNumber("12345"); - account.setBalance(2000.0); - } + @BeforeEach + public void setup() { + account = new Account(); + account.setAccountNumber("12345"); + account.setBalance(2000.0); + } - @Autowired - BankAccountService bankAccountService; + @Autowired + BankAccountService bankAccountService; - @Test - void withdraw() { - bankAccountService.withdraw(account, 500.0); - assertTrue(account.getBalance() == 1500.0); - } + @Test + void withdraw() { + bankAccountService.withdraw(account, 500.0); + assertTrue(account.getBalance() == 1500.0); + } - @Test - void withdrawWhenLimitReached() { - Assertions.assertThatExceptionOfType(WithdrawLimitException.class).isThrownBy(() -> bankAccountService.withdraw(account, 600.0)); - assertTrue(account.getBalance() == 2000.0); - } + @Test + void withdrawWhenLimitReached() { + Assertions.assertThatExceptionOfType(WithdrawLimitException.class) + .isThrownBy(() -> bankAccountService.withdraw(account, 600.0)); + assertTrue(account.getBalance() == 2000.0); + } - @Test - void deposit() { - bankAccountService.deposit(account, 500.0); - assertTrue(account.getBalance() == 2500.0); - } + @Test + void deposit() { + bankAccountService.deposit(account, 500.0); + assertTrue(account.getBalance() == 2500.0); + } - @Test - void getBalance() { - bankAccountService.getBalance(); - } + @Test + void getBalance() { + bankAccountService.getBalance(); + } } From 35b8de3a5fef91ca64758b3dcb23d0e3ef836e83 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Sat, 19 Dec 2020 23:07:14 +0100 Subject: [PATCH 331/590] JAVA-3570: Update Mockito version in the parent-boot-2 to match Spring Boot 2.4 --- parent-boot-2/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 2ee4f1483b..ace3e538c9 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -84,6 +84,8 @@ 1.0.22.RELEASE 2.4.0 1.9.1 + + 3.4.0 From 0ee156ff9235d2f696b1ba3dd50e505c2bb1ddc3 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Sat, 19 Dec 2020 23:15:22 +0100 Subject: [PATCH 332/590] JAVA-3570: Remove unused spring-cloud-context dependency from spring-mvc-basics-3 --- spring-mvc-basics-3/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spring-mvc-basics-3/pom.xml b/spring-mvc-basics-3/pom.xml index a929337b25..fac6f54a16 100644 --- a/spring-mvc-basics-3/pom.xml +++ b/spring-mvc-basics-3/pom.xml @@ -78,12 +78,6 @@ test - - org.springframework.cloud - spring-cloud-context - ${springcloud.version} - - org.apache.httpcomponents httpclient @@ -149,7 +143,6 @@ 2.2 18.0 3.1.7 - 2.0.2.RELEASE 4.5.8 From 00e15a4911ae4b34efcb0c15def916352228ea91 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Sat, 19 Dec 2020 23:21:02 +0100 Subject: [PATCH 333/590] JAVA-3570: Remove unused spring-cloud-context dependency from spring-boot-artifacts --- spring-boot-modules/spring-boot-artifacts/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spring-boot-modules/spring-boot-artifacts/pom.xml b/spring-boot-modules/spring-boot-artifacts/pom.xml index 2704b71bd6..467f931559 100644 --- a/spring-boot-modules/spring-boot-artifacts/pom.xml +++ b/spring-boot-modules/spring-boot-artifacts/pom.xml @@ -86,12 +86,6 @@ ${jquery.version} - - org.springframework.cloud - spring-cloud-context - ${springcloud.version} - - org.apache.httpcomponents httpclient @@ -216,7 +210,6 @@ 2.2.4 18.0 3.1.7 - 2.0.2.RELEASE 4.5.8 From e2026cf43e7c537d5c5be35a7d051e50200b98d5 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Sat, 19 Dec 2020 23:27:59 +0100 Subject: [PATCH 334/590] JAVA-3570: Update JaVers version in spring-boot-data --- spring-boot-modules/spring-boot-data/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-data/pom.xml b/spring-boot-modules/spring-boot-data/pom.xml index fe64b07379..06f09c70fe 100644 --- a/spring-boot-modules/spring-boot-data/pom.xml +++ b/spring-boot-modules/spring-boot-data/pom.xml @@ -168,7 +168,7 @@ - 5.6.3 + 5.14.0 2.2.4 1.8 1.8 From 84a14bcaeb9a2dad95794b418a80c91375d7399d Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Sun, 20 Dec 2020 18:25:50 +0100 Subject: [PATCH 335/590] JAVA-3570: Update to Spring Batch 4.3 and update config accordingly in spring-batch --- spring-batch/pom.xml | 4 +-- spring-batch/repository.sqlite | Bin 73728 -> 73728 bytes .../batchscheduler/SpringBatchScheduler.java | 32 ++++++++++++------ .../taskletsvschunks/config/ChunksConfig.java | 18 ++++++++-- .../config/TaskletsConfig.java | 18 ++++++++-- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/spring-batch/pom.xml b/spring-batch/pom.xml index 9edf8ad3be..75ec0d4877 100644 --- a/spring-batch/pom.xml +++ b/spring-batch/pom.xml @@ -95,8 +95,8 @@ - 5.2.0.RELEASE - 4.2.0.RELEASE + 5.3.0 + 4.3.0 3.15.1 4.1 2.3.1 diff --git a/spring-batch/repository.sqlite b/spring-batch/repository.sqlite index 2b549352ec8073708bd085fd414ed93d189c7511..a2b87ffa00f315b4084437ce2f5f639d47469027 100644 GIT binary patch delta 4429 zcmb`JO>7&-6~}kQ-Q}(*ab;Ms<0dMpb?eG7&2UNX2h}f;6cb4yB|)Mhsj(^zxl57K zlB<%G4Z>#Es&nYcsKXTXB}ft2$e}KfL0{H$VO7@m;)0T)avA;tBlrl_#V4?Kjr0u}2tZ1Y_T4f61O< zN1UHIZ#l0y%g)H|p@9*n;bTaQKAtFp(x#@COH+EvCn=(j&xF)eS{6k`$fN|HmJ1PKoWxiNdT&3WOy;9!euoe@nD2%no0pl6a+CS2Gx+H_=6cKm67imMe<@}5D278)aW3M{nkdGhoA&w{T1JGf-ge!sX8xB1}98Tc(XM@nR*w~wv z-Ox~bGw4Q!+&%qNe1Kver)&aV`@lX(Ii4hK-#4eViv&SAjuN&2Ui+8rFvUD!vwas$ zj~-)=^w@Yj5>7@ZR;OkntCQ37$?$YE#=JR33_zl{F!t~4TkMN$o}Gq7`n7)aq-?F3K{X?loBat9yBfv`!#fC%io6_~HMrk&iF$ z=2w3;@C^s~D(3uC|CPQUIga=Km^n{hwcoZMqt1}8!dtvRp4gEbB=)nPVCT89v<6Bg zZj{>qXMuOSoYTA$pp;F3EzVQ>^G_cOr1iWv1yoJhF06Z-QaW3zYs6ac#&ZR=v{=lQ z)go7OUWlLA8SRBfoZH6{;z5p>E$V5tRMMNLNU#EY{TG>2fnr@G0!zjvd-sbh)CMk0 zo!VK072{I0i#eCl_08Jp>d_tnVQ#v@3i42{Cw3yRr0h4zI8N-YToCcyGZ(Jg92kb- z>|Kn#%ii7XyZA9XO!r_tOb^x%HyFAPV?Sf>u>WQM$^L=8%9hz#x({mT-*)420-}F; z$h_#~Fq)IyF0CPvaHG$+i7i|#f=WDBDs!Ia+tm1AN#u1!H8fLmoQErbyb1-J0IGXJ zSJvSP9!}9y+~|3(qJknf%7-Mshs*1Qau(XnM3Xa-*c>tfm6=SUzU*&WJO{LG7>@UO zIJF3@WXrj{>P=^hdO`P2mh@QB05C!{#;r8sEUM}zj6T0GJsw_e246PM_lHCer>S78 z{Vc$; z=ELods*}_+pjdIw>Sgp+??EL5TBx3mMdlX5bJlg*Ss9310~TcWKvw%lg-&mg$^fnO zRj7>puo5Mc)x)ETsO56Sy_hShoumvtB+6Y;@lwO&(MW}p3v(T^GLRD5VLhU(1pmQM z8EU7j7D1(;y65zJS-}U`&+a!%E>PF?Y#kkFFVd~7xuOWdbiNyc7cq3*=?56myY z>euBN8V4v@e&Jx+x<^{^?Q~AlRQGHae&n`Lg*Q4%e5hH#p~4ca3f#~a4;9reFo^ge zDpqo0VXi4J1O0f^3pyWw;aa#J@ge%<>dH!$qX}&CLBFTQ7FXr$U5t7GV&@#alpY>*~sjQpH@ zoy?IO@i*cnB0K(=Cz#vLmTK~dJ+-1{VEZ>G~0ibUx|U{6`HBdayi z9H%T-8$noebL-g{_0?ev7>7b;OVj4qx>jeLrQc4F-EM|*Iq4?QIDEv)qT^yGhmXEw zBL?fBUn3~IcYq>3!YGP-pL~&ABELy|1f}r-VaQA$hQogb>4F4dqlyyTu$f~NjhmlX zM_3bc{Zkn>vu⪻Dcx{`y3i`q~%~u%yqkLw>%AWsL6QsU9`FSKQykLu{^AaxxOM( zmMikCQ#F%bdJ0)Ay=^&I6Lb9?ncU-PQglh*f}1B@H_$lzJkKxzYtY{#?KUqWm4p3B=f&U!8 zE`I|544|ki|7Kl%9|1NN2{vX^#>p4hMc7zmSeb3X%*hQbENm>|EX>A?lOHk*v$04s zGh2h0;*u<4Ow5LiPL3hY9`RoOPVt_8!6A-*&aNz*99RT^mgF+<-{IfRKZ!qgv*3bQ z{>{1Z(}BX=$_#ubcqj5iaVu|D6cFZSZZcun99v_?xH+a~DKj_!9|lJL9}N6I_%a=;`v r9bj=_V`Tls!1@d5k`Jugf3Y%haj`M7u`#f*0Y(0>Zf6r?{KW|X$tzkF diff --git a/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java b/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java index 4de3e0a4b6..cff4e96c89 100644 --- a/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java +++ b/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java @@ -1,12 +1,5 @@ package com.baeldung.batchscheduler; -import java.util.Date; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import com.baeldung.batchscheduler.model.Book; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +13,7 @@ import org.springframework.batch.core.configuration.annotation.StepBuilderFactor import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.file.FlatFileItemReader; import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder; @@ -30,12 +23,22 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.support.ScheduledMethodRunnable; +import javax.sql.DataSource; +import java.util.Date; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + @Configuration @EnableBatchProcessing @EnableScheduling @@ -122,9 +125,18 @@ public class SpringBatchScheduler { @Bean public JobRepository jobRepository() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(dataSource()); factory.setTransactionManager(new ResourcelessTransactionManager()); - return (JobRepository) factory.getObject(); + return factory.getObject(); + } + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.sqlite.JDBC"); + dataSource.setUrl("jdbc:sqlite:repository.sqlite"); + return dataSource; } @Bean diff --git a/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java index 57288fb312..c8b05848f9 100644 --- a/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java @@ -12,7 +12,7 @@ import org.springframework.batch.core.configuration.annotation.StepBuilderFactor import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -21,8 +21,11 @@ import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.transaction.PlatformTransactionManager; +import javax.sql.DataSource; + @Configuration @EnableBatchProcessing public class ChunksConfig { @@ -38,9 +41,18 @@ public class ChunksConfig { @Bean public JobRepository jobRepository() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(dataSource()); factory.setTransactionManager(transactionManager()); - return (JobRepository) factory.getObject(); + return factory.getObject(); + } + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.sqlite.JDBC"); + dataSource.setUrl("jdbc:sqlite:repository.sqlite"); + return dataSource; } @Bean diff --git a/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java index e7157ac520..5f2f49928c 100644 --- a/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java @@ -11,14 +11,17 @@ import org.springframework.batch.core.configuration.annotation.StepBuilderFactor import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.transaction.PlatformTransactionManager; +import javax.sql.DataSource; + @Configuration @EnableBatchProcessing public class TaskletsConfig { @@ -34,9 +37,18 @@ public class TaskletsConfig { @Bean public JobRepository jobRepository() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(dataSource()); factory.setTransactionManager(transactionManager()); - return (JobRepository) factory.getObject(); + return factory.getObject(); + } + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.sqlite.JDBC"); + dataSource.setUrl("jdbc:sqlite:repository.sqlite"); + return dataSource; } @Bean From df7af0d0ecde427e161d72aa4b089ea4298b83d2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 20 Dec 2020 23:02:10 +0530 Subject: [PATCH 336/590] JAVA-3508: Create spring-web-modules parent --- pom.xml | 2 ++ spring-web-modules/pom.xml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spring-web-modules/pom.xml diff --git a/pom.xml b/pom.xml index 17e4fe1584..b309d027fb 100644 --- a/pom.xml +++ b/pom.xml @@ -714,6 +714,7 @@ spring-vault spring-vertx + spring-web-modules spring-webflux-amqp spring-websockets @@ -1199,6 +1200,7 @@ spring-vault spring-vertx + spring-web-modules spring-webflux-amqp spring-websockets diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml new file mode 100644 index 0000000000..df8b0d6562 --- /dev/null +++ b/spring-web-modules/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + spring-web-modules + 0.0.1-SNAPSHOT + spring-web-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + From 17d2870daa871ff283ee9b50384bdad32e6b0e8a Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Mon, 21 Dec 2020 01:19:26 +0530 Subject: [PATCH 337/590] BAEL-4751: Java 14 New Features (#10319) * BAEL-4751: Java 14 New Features * BAEL-4751: Code formatting * BAEL-4751: Consistent excpetion message * BAEL-4751: Changed assert --- .../java14/newfeatues/MultilineUnitTest.java | 26 ++++++++++ .../java14/newfeatues/RecordUnitTest.java | 38 ++++++++++++++ .../java14/newfeatues/SwitchExprUnitTest.java | 50 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java new file mode 100644 index 0000000000..4efd1ff362 --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.java14.newfeatues; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class MultilineUnitTest { + + @SuppressWarnings("preview") + String multiline = """ + A quick brown fox jumps over a lazy dog; \ + the lazy dog howls loudly."""; + + @SuppressWarnings("preview") + String anotherMultiline = """ + A quick brown fox jumps over a lazy dog; + the lazy dog howls loudly."""; + + @Test + public void givenMultilineString_whenSlashUsed_thenNoNewLine() { + assertFalse(multiline.contains("\n")); + assertTrue(anotherMultiline.contains("\n")); + } + +} diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java new file mode 100644 index 0000000000..3d7a55d3e6 --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.java14.newfeatues; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class RecordUnitTest { + + @SuppressWarnings("preview") + public record User(int id, String password) { + }; + + private User user1 = new User(0, "UserOne"); + + @Test + public void givenRecord_whenObjInitialized_thenValuesCanBeFetchedWithGetters() { + + assertEquals(0, user1.id()); + assertEquals("UserOne", user1.password()); + } + + @Test + public void whenRecord_thenEqualsImplemented() { + + User user2 = user1; + + assertEquals(user1, user2); + } + + @Test + public void whenRecord_thenToStringImplemented() { + + assertTrue(user1.toString() + .contains("UserOne")); + } + +} diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java new file mode 100644 index 0000000000..896b3ec7de --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.java14.newfeatues; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SwitchExprUnitTest { + + @Test + public void givenDay_whenSunday_thenWeekend() { + assertTrue(isTodayHolidayInJava8("SUNDAY")); + + assertTrue(isTodayHolidayInJava14("SUNDAY")); + + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> isTodayHolidayInJava8("SOMEDAY")); + + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> isTodayHolidayInJava14("SOMEDAY")); + } + + private boolean isTodayHolidayInJava8(String day) { + + boolean isTodayHoliday; + switch (day) { + case "MONDAY": + case "TUESDAY": + case "WEDNESDAY": + case "THURSDAY": + case "FRIDAY": + isTodayHoliday = false; + break; + case "SATURDAY": + case "SUNDAY": + isTodayHoliday = true; + break; + default: + throw new IllegalArgumentException("What's a " + day); + } + return isTodayHoliday; + } + + private boolean isTodayHolidayInJava14(String day) { + return switch (day) { + case "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" -> false; + case "SATURDAY", "SUNDAY" -> true; + default -> throw new IllegalArgumentException("What's a " + day); + }; + } + +} From a07e23dddd90d529a0719f24c6f6217694834c15 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 21 Dec 2020 02:06:26 +0530 Subject: [PATCH 338/590] BAEL-4686: fixed review comments --- .../NullAllowInMapUnitTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java index c5fc57d8ce..594e8ec3b4 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/concurrenthashmap/NullAllowInMapUnitTest.java @@ -13,7 +13,7 @@ import org.junit.Test; public class NullAllowInMapUnitTest { @Test - public void allowNullKey_In_HashMapBackedSynchronizedMap() { + public void givenHashMapBackedSynchronizedMap_whenNullAsKey_thenNoError() { Map map = Collections .synchronizedMap(new HashMap()); map.put(null, 1); @@ -22,14 +22,14 @@ public class NullAllowInMapUnitTest { @Test(expected = NullPointerException.class) - public void allowNullKey_In_TreeMapBackedSynchronizedMap() { + public void givenTreeMapBackedSynchronizedMap_whenNullAsKey_thenException() { Map map = Collections.synchronizedMap(new TreeMap()); map.put(null, 1); Assert.assertTrue(map.get(null).equals(1)); } @Test - public void allowNullKey_In_LinkedHashMapBackedSynchronizedMap() { + public void givenLinkedHashMapBackedSynchronizedMap_whenNullAsKey_thenNoError() { Map map = Collections .synchronizedMap(new LinkedHashMap()); map.put(null, 1); @@ -37,27 +37,27 @@ public class NullAllowInMapUnitTest { } @Test(expected = NullPointerException.class) - public void allowNullKey_In_ConcurrentHasMap() { + public void givenConcurrentHasMap_whenNullAsKey_thenException() { Map map = new ConcurrentHashMap<>(); map.put(null, 1); } @Test - public void allowNullValue_In_HashMapBackedSynchronizedMap() { + public void givenHashMapBackedSynchronizedMap_whenNullAsValue_thenNoError() { Map map = Collections.synchronizedMap(new HashMap()); map.put("1", null); Assert.assertNull(map.get("1")); } @Test - public void allowNullValue_In_TreeMapBackedSynchronizedMap() { + public void givenTreeMapBackedSynchronizedMap_whenNullAsValue_thenNoError() { Map map = Collections.synchronizedMap(new TreeMap()); map.put("1", null); Assert.assertNull(map.get("1")); } @Test - public void allowNullValue_In_LinkedHashSynchronizedMap() { + public void givenLinkedHashMapBackedSynchronizedMap_whenNullAsValue_thenNoError() { Map map = Collections .synchronizedMap(new LinkedHashMap()); map.put("1", null); @@ -65,7 +65,7 @@ public class NullAllowInMapUnitTest { } @Test(expected = NullPointerException.class) - public void allowNullValue_In_ConcurrentHasMap() { + public void givenConcurrentHasMap_whenNullAsValue_thenException() { Map map = new ConcurrentHashMap<>(); map.put("1", null); } From 3ef0ac42572f64ce9f99c112a43bcc350803ab97 Mon Sep 17 00:00:00 2001 From: Gilvan Ornelas Fernandes Filho Date: Sun, 20 Dec 2020 21:29:30 -0300 Subject: [PATCH 339/590] Clean architecture initial commit --- patterns/clean-architecture/pom.xml | 87 +++++++++++++++++++ .../CleanArchitectureApplication.java | 40 +++++++++ .../usercreation/CommonUser.java | 30 +++++++ .../usercreation/CommonUserFactory.java | 8 ++ .../usercreation/JpaUser.java | 21 +++++ .../usercreation/JpaUserRepository.java | 8 ++ .../cleanarchitecture/usercreation/User.java | 9 ++ .../usercreation/UserDataMapper.java | 53 +++++++++++ .../usercreation/UserDsRequestModel.java | 41 +++++++++ .../usercreation/UserFactory.java | 5 ++ .../usercreation/UserInputBoundary.java | 5 ++ .../usercreation/UserPresenter.java | 7 ++ .../usercreation/UserRegisterController.java | 20 +++++ .../usercreation/UserRegisterDsGateway.java | 7 ++ .../usercreation/UserRegisterInteractor.java | 35 ++++++++ .../usercreation/UserRequestModel.java | 33 +++++++ .../usercreation/UserResponseFormatter.java | 22 +++++ .../usercreation/UserResponseModel.java | 29 +++++++ .../src/main/resources/application.properties | 2 + .../UserResponseFormatterTests.java | 29 +++++++ .../usercreation/UserUnitTest.java | 15 ++++ 21 files changed, 506 insertions(+) create mode 100644 patterns/clean-architecture/pom.xml create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java create mode 100644 patterns/clean-architecture/src/main/resources/application.properties create mode 100644 patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java create mode 100644 patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java diff --git a/patterns/clean-architecture/pom.xml b/patterns/clean-architecture/pom.xml new file mode 100644 index 0000000000..6e7de78751 --- /dev/null +++ b/patterns/clean-architecture/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + clean-architecture + 1.0 + clean-architecture + Project for clean architecture in java + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + 1.8 + + + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.mockito + mockito-core + test + + + org.junit.platform + junit-platform-engine + + + org.junit.jupiter + junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.platform + junit-platform-runner + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java new file mode 100644 index 0000000000..ebac2bacf3 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java @@ -0,0 +1,40 @@ +package com.baeldung.pattern.cleanarchitecture; + +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.core.type.filter.TypeFilter; + +@SpringBootApplication +public class CleanArchitectureApplication { + + public static void main(String[] args) { + SpringApplication.run(CleanArchitectureApplication.class); + } + + @Bean + BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext beanRegistry) { + return beanFactory -> { + genericApplicationContext((BeanDefinitionRegistry) ((AnnotationConfigServletWebServerApplicationContext) beanRegistry).getBeanFactory()); + }; + } + + void genericApplicationContext(BeanDefinitionRegistry beanRegistry) { + ClassPathBeanDefinitionScanner beanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanRegistry); + beanDefinitionScanner.addIncludeFilter(removeModelAndEntitiesFilter()); + beanDefinitionScanner.scan("com.baeldung.pattern.cleanarchitecture"); + } + + static TypeFilter removeModelAndEntitiesFilter() { + return (MetadataReader mr, MetadataReaderFactory mrf) -> !mr.getClassMetadata() + .getClassName() + .endsWith("Model"); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java new file mode 100644 index 0000000000..f7ba9dacc0 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java @@ -0,0 +1,30 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class CommonUser implements User { + + String name; + String password; + + CommonUser(String name, String password) { + this.name = name; + this.password = password; + } + + CommonUser() { + } + + @Override + public boolean passwordIsValid() { + return password == null || password.length() > 5; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getPassword() { + return password; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java new file mode 100644 index 0000000000..a2b851da94 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java @@ -0,0 +1,8 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class CommonUserFactory implements UserFactory { + @Override + public User create(String name, String password) { + return new CommonUser(name, password); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java new file mode 100644 index 0000000000..20751f282a --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java @@ -0,0 +1,21 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class JpaUser implements UserRegisterDsGateway { + + final JpaUserRepository repository; + + JpaUser(JpaUserRepository repository) { + this.repository = repository; + } + + @Override + public boolean existsByName(String name) { + return repository.existsById(name); + } + + @Override + public void save(UserDsRequestModel requestModel) { + UserDataMapper accountDataMapper = new UserDataMapper(requestModel.getName(), requestModel.getPassword(), requestModel.getCreationTime()); + repository.save(accountDataMapper); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java new file mode 100644 index 0000000000..8565ed7965 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +interface JpaUserRepository extends JpaRepository { +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java new file mode 100644 index 0000000000..aab652f2a1 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java @@ -0,0 +1,9 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface User { + boolean passwordIsValid(); + + String getName(); + + String getPassword(); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java new file mode 100644 index 0000000000..44112de8a9 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java @@ -0,0 +1,53 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "user") +class UserDataMapper { + + @Id + String name; + + String password; + + LocalDateTime creationTime; + + public UserDataMapper() { + } + + public UserDataMapper(String name, String password, LocalDateTime creationTime) { + super(); + this.name = name; + this.password = password; + this.creationTime = creationTime; + } + + 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 LocalDateTime getCreationTime() { + return creationTime; + } + + public void setCreationTime(LocalDateTime creationTime) { + this.creationTime = creationTime; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java new file mode 100644 index 0000000000..aa0f0b56d1 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java @@ -0,0 +1,41 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +class UserDsRequestModel { + + String name; + String password; + LocalDateTime creationTime; + + public UserDsRequestModel(String name, String password, LocalDateTime creationTime) { + this.name = name; + this.password = password; + this.creationTime = creationTime; + } + + 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 LocalDateTime getCreationTime() { + return creationTime; + } + + public void setCreationTime(LocalDateTime creationTime) { + this.creationTime = creationTime; + } + +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java new file mode 100644 index 0000000000..1ff29709be --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java @@ -0,0 +1,5 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserFactory { + User create(String name, String password); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java new file mode 100644 index 0000000000..e72c30f13c --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java @@ -0,0 +1,5 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +public interface UserInputBoundary { + UserResponseModel create(UserRequestModel requestModel); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java new file mode 100644 index 0000000000..45d202643e --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java @@ -0,0 +1,7 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserPresenter { + UserResponseModel prepareSuccessView(UserResponseModel user); + + UserResponseModel prepareFailView(String error); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java new file mode 100644 index 0000000000..039dc12910 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java @@ -0,0 +1,20 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +class UserRegisterController { + + final UserInputBoundary userInput; + + UserRegisterController(UserInputBoundary accountGateway) { + this.userInput = accountGateway; + } + + @PostMapping("/user") + UserResponseModel create(@RequestBody UserRequestModel requestModel) { + return userInput.create(requestModel); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java new file mode 100644 index 0000000000..89c1b7e774 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java @@ -0,0 +1,7 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserRegisterDsGateway { + boolean existsByName(String identifier); + + void save(UserDsRequestModel requestModel); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java new file mode 100644 index 0000000000..5137593dc3 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java @@ -0,0 +1,35 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +class UserRegisterInteractor implements UserInputBoundary { + + final UserRegisterDsGateway userDsGateway; + final UserPresenter userPresenter; + final UserFactory userFactory; + + UserRegisterInteractor(UserRegisterDsGateway userRegisterDfGateway, UserPresenter userPresenter, + UserFactory userFactory) { + this.userDsGateway = userRegisterDfGateway; + this.userPresenter = userPresenter; + this.userFactory = userFactory; + } + + @Override + public UserResponseModel create(UserRequestModel requestModel) { + if (userDsGateway.existsByName(requestModel.getName())) { + return userPresenter.prepareFailView("User already exists."); + } + User user = userFactory.create(requestModel.getName(), requestModel.getPassword()); + if (!user.passwordIsValid()) { + return userPresenter.prepareFailView("User password must have more than 5 characters."); + } + LocalDateTime now = LocalDateTime.now(); + UserDsRequestModel userDsModel = new UserDsRequestModel(user.getName(), user.getPassword(), now); + + userDsGateway.save(userDsModel); + + UserResponseModel accountResponseModel = new UserResponseModel(user.getName(), now.toString()); + return userPresenter.prepareSuccessView(accountResponseModel); + } +} \ No newline at end of file diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java new file mode 100644 index 0000000000..8317665c31 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java @@ -0,0 +1,33 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class UserRequestModel { + + String name; + String password; + + public UserRequestModel() { + super(); + } + + UserRequestModel(String name, String password) { + super(); + this.name = name; + this.password = password; + } + + String getName() { + return name; + } + + void setName(String name) { + this.name = name; + } + + String getPassword() { + return password; + } + + void setPassword(String password) { + this.password = password; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java new file mode 100644 index 0000000000..4842d44e22 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java @@ -0,0 +1,22 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +class UserResponseFormatter implements UserPresenter { + + @Override + public UserResponseModel prepareSuccessView(UserResponseModel response) { + LocalDateTime responseTime = LocalDateTime.parse(response.getCreationTime()); + response.setCreationTime(responseTime.format(DateTimeFormatter.ofPattern("hh:mm:ss"))); + return response; + } + + @Override + public UserResponseModel prepareFailView(String error) { + throw new ResponseStatusException(HttpStatus.CONFLICT, error); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java new file mode 100644 index 0000000000..73a3d8fb10 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java @@ -0,0 +1,29 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +public class UserResponseModel { + + String login; + String creationTime; + + public UserResponseModel(String login, String creationTime) { + this.login = login; + this.creationTime = creationTime; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getCreationTime() { + return creationTime; + } + + public void setCreationTime(String creationTime) { + this.creationTime = creationTime; + } + +} diff --git a/patterns/clean-architecture/src/main/resources/application.properties b/patterns/clean-architecture/src/main/resources/application.properties new file mode 100644 index 0000000000..a5a02bb49d --- /dev/null +++ b/patterns/clean-architecture/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.error.include-message=always \ No newline at end of file diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java new file mode 100644 index 0000000000..f8ebde5f10 --- /dev/null +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java @@ -0,0 +1,29 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; +import org.springframework.web.server.ResponseStatusException; + +import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseFormatter; +import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseModel; + +class UserResponseFormatterTests { + + UserResponseFormatter userResponseFormatter = new UserResponseFormatter(); + + @Test + void givenDateAnd3HourTime_whenPrepareSuccessView_thenReturnOnly3HourTime() { + UserResponseModel modelResponse = new UserResponseModel("baeldung", "2020-12-20T03:00:00.000"); + UserResponseModel formattedResponse = userResponseFormatter.prepareSuccessView(modelResponse); + + assertThat(formattedResponse.getCreationTime()).isEqualTo("03:00:00"); + } + + @Test + void whenPrepareFailView_thenThrowHttpConflictException() { + assertThatThrownBy(() -> userResponseFormatter.prepareFailView("Invalid password")) + .isInstanceOf(ResponseStatusException.class); + } +} diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java new file mode 100644 index 0000000000..505ea47e3f --- /dev/null +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class UserUnitTest { + + @Test + void given123Password_whenPasswordIsNotValid_thenIsFalse() { + User user = new CommonUser("Baeldung", "123"); + + assertThat(user.passwordIsValid()).isFalse(); + } +} From b18f0e7980d02fdfea4af9be2f5f36221ce38917 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 21 Dec 2020 10:49:28 +0200 Subject: [PATCH 340/590] Update README.md --- spring-5/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/spring-5/README.md b/spring-5/README.md index d50f9c7544..cef0fedb4f 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -2,9 +2,6 @@ This module contains articles about Spring 5 -### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring - ### Relevant Articles - [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) From 9264d091b09eda29f77825ea34aa62ddbf7f78c8 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 21 Dec 2020 13:41:50 +0100 Subject: [PATCH 341/590] JAVA-3570: Ignore one of the FunctionalWebApplicationIntegrationTest --- .../functional/FunctionalWebApplicationIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java index 1256d5f129..38496d3500 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java @@ -5,6 +5,7 @@ import static org.springframework.web.reactive.function.BodyInserters.fromResour import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.springframework.boot.web.server.WebServer; import org.springframework.core.io.ClassPathResource; @@ -102,6 +103,7 @@ public class FunctionalWebApplicationIntegrationTest { .isEqualTo(String.valueOf(resource.contentLength())); } + @Ignore("We get 404 after Spring Boot 2.4 upgrade. We need to solve it in a new task.") @Test public void givenActors_whenAddActor_thenAdded() throws Exception { client.get() From dcd9eaf33a47d8e73d294aa7befcb6c455200db4 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 21 Dec 2020 19:52:50 +0530 Subject: [PATCH 342/590] JAVA-3509: Moved spring-mvc-basics inside spring-web-modules --- .../spring-mvc-basics}/.gitignore | 0 .../spring-mvc-basics}/README.md | 0 .../spring-mvc-basics}/pom.xml | 2 +- .../src/main/java/com/baeldung/Application.java | 0 .../main/java/com/baeldung/config/MainWebAppInitializer.java | 0 .../com/baeldung/customvalidator/ContactNumberConstraint.java | 0 .../com/baeldung/customvalidator/ContactNumberValidator.java | 0 .../java/com/baeldung/customvalidator/FieldsValueMatch.java | 0 .../com/baeldung/customvalidator/FieldsValueMatchValidator.java | 0 .../HttpMediaTypeNotAcceptableExceptionExampleController.java | 0 .../src/main/java/com/baeldung/model/Book.java | 0 .../src/main/java/com/baeldung/model/Employee.java | 0 .../src/main/java/com/baeldung/model/NewUserForm.java | 0 .../src/main/java/com/baeldung/model/User.java | 0 .../src/main/java/com/baeldung/model/ValidatedPhone.java | 0 .../src/main/java/com/baeldung/services/UserService.java | 0 .../src/main/java/com/baeldung/spring/web/config/WebConfig.java | 0 .../java/com/baeldung/web/controller/EmployeeController.java | 0 .../java/com/baeldung/web/controller/MultipartController.java | 0 .../java/com/baeldung/web/controller/NewUserController.java | 0 .../web/controller/RequestMappingShortcutsController.java | 0 .../baeldung/web/controller/ResponseStatusRestController.java | 0 .../main/java/com/baeldung/web/controller/SampleController.java | 0 .../java/com/baeldung/web/controller/SimpleBookController.java | 0 .../com/baeldung/web/controller/SimpleBookRestController.java | 0 .../main/java/com/baeldung/web/controller/UserController.java | 0 .../java/com/baeldung/web/controller/UserRestController.java | 0 .../com/baeldung/web/controller/ValidatedPhoneController.java | 0 .../handlermapping/BeanNameHandlerMappingController.java | 0 .../controller/handlermapping/SimpleUrlMappingController.java | 0 .../web/controller/handlermapping/WelcomeController.java | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-basics}/src/main/resources/mvc-configuration.xml | 0 .../src/main/resources/themes/default.properties | 0 .../src/main/resources/themes/example.properties | 0 .../spring-mvc-basics}/src/main/resources/views.properties | 0 .../spring-mvc-basics}/src/main/resources/views.xml | 0 .../src/main/webapp/WEB-INF/view/employeeHome.jsp | 0 .../src/main/webapp/WEB-INF/view/employeeView.jsp | 0 .../spring-mvc-basics}/src/main/webapp/WEB-INF/view/index.jsp | 0 .../src/main/webapp/WEB-INF/view/phoneHome.jsp | 0 .../spring-mvc-basics}/src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/view/userHome.jsp | 0 .../src/main/webapp/WEB-INF/view2/sample2.jsp | 0 .../src/main/webapp/WEB-INF/view3/sample3.jsp | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../com/baeldung/config/BeanNameUrlHandlerMappingConfig.java | 0 .../java/com/baeldung/config/HandlerMappingDefaultConfig.java | 0 .../com/baeldung/config/HandlerMappingPrioritiesConfig.java | 0 .../java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java | 0 ...ediaTypeNotAcceptableExceptionControllerIntegrationTest.java | 0 .../handlermappings/BeanNameMappingConfigIntegrationTest.java | 0 .../HandlerMappingDefaultConfigIntegrationTest.java | 0 .../HandlerMappingPriorityConfigIntegrationTest.java | 0 .../handlermappings/SimpleUrlMappingConfigIntegrationTest.java | 0 .../web/controller/ClassValidationMvcIntegrationTest.java | 0 .../web/controller/CustomMVCValidatorIntegrationTest.java | 0 .../EmployeeControllerContentNegotiationIntegrationTest.java | 0 .../EmployeeControllerModelAttributeIntegrationTest.java | 0 .../web/controller/RequestMapingShortcutsIntegrationTest.java | 0 .../controller/ResponseStatusRestControllerIntegrationTest.java | 0 .../com/baeldung/web/controller/SampleControllerLiveTest.java | 0 .../web/controller/SimpleBookControllerIntegrationTest.java | 0 .../web/controller/SimpleBookRestControllerIntegrationTest.java | 0 .../src/test/resources/BeanNameUrlHandlerMappingConfig.xml | 0 .../test/resources/ControllerClassNameHandlerMappingConfig.xml | 0 .../src/test/resources/HandlerMappingConfiguringPriorities.xml | 0 .../src/test/resources/SimpleUrlHandlerMappingConfig.xml | 0 68 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/.gitignore (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/README.md (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/pom.xml (97%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/Application.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/config/MainWebAppInitializer.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionExampleController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/model/Book.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/model/Employee.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/model/NewUserForm.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/model/User.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/model/ValidatedPhone.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/services/UserService.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/spring/web/config/WebConfig.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/EmployeeController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/MultipartController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/NewUserController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/RequestMappingShortcutsController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/ResponseStatusRestController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/SampleController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/SimpleBookController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/SimpleBookRestController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/UserController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/UserRestController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/ValidatedPhoneController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/handlermapping/BeanNameHandlerMappingController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/handlermapping/SimpleUrlMappingController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/application.properties (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/mvc-configuration.xml (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/themes/default.properties (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/themes/example.properties (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/views.properties (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/resources/views.xml (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/employeeHome.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/employeeView.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/index.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/phoneHome.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view/userHome.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view2/sample2.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/main/webapp/WEB-INF/view3/sample3.jsp (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/config/BeanNameUrlHandlerMappingConfig.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/config/HandlerMappingDefaultConfig.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/config/HandlerMappingPrioritiesConfig.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionControllerIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/handlermappings/BeanNameMappingConfigIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/handlermappings/HandlerMappingDefaultConfigIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/handlermappings/HandlerMappingPriorityConfigIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/handlermappings/SimpleUrlMappingConfigIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/ClassValidationMvcIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/CustomMVCValidatorIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/EmployeeControllerModelAttributeIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/RequestMapingShortcutsIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/ResponseStatusRestControllerIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/SampleControllerLiveTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/resources/BeanNameUrlHandlerMappingConfig.xml (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/resources/ControllerClassNameHandlerMappingConfig.xml (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/resources/HandlerMappingConfiguringPriorities.xml (100%) rename {spring-mvc-basics => spring-web-modules/spring-mvc-basics}/src/test/resources/SimpleUrlHandlerMappingConfig.xml (100%) diff --git a/spring-mvc-basics/.gitignore b/spring-web-modules/spring-mvc-basics/.gitignore similarity index 100% rename from spring-mvc-basics/.gitignore rename to spring-web-modules/spring-mvc-basics/.gitignore diff --git a/spring-mvc-basics/README.md b/spring-web-modules/spring-mvc-basics/README.md similarity index 100% rename from spring-mvc-basics/README.md rename to spring-web-modules/spring-mvc-basics/README.md diff --git a/spring-mvc-basics/pom.xml b/spring-web-modules/spring-mvc-basics/pom.xml similarity index 97% rename from spring-mvc-basics/pom.xml rename to spring-web-modules/spring-mvc-basics/pom.xml index cd486cb1d3..ac92c7bfe5 100644 --- a/spring-mvc-basics/pom.xml +++ b/spring-web-modules/spring-mvc-basics/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-basics/src/main/java/com/baeldung/Application.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/Application.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/Application.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/Application.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/config/MainWebAppInitializer.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/config/MainWebAppInitializer.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/config/MainWebAppInitializer.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/config/MainWebAppInitializer.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionExampleController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionExampleController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionExampleController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionExampleController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/model/Book.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/Book.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/model/Book.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/Book.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/model/Employee.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/Employee.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/model/Employee.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/Employee.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/model/NewUserForm.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/NewUserForm.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/model/NewUserForm.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/NewUserForm.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/model/User.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/User.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/model/User.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/User.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/model/ValidatedPhone.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/ValidatedPhone.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/model/ValidatedPhone.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/model/ValidatedPhone.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/services/UserService.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/EmployeeController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/EmployeeController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/EmployeeController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/EmployeeController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/MultipartController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/NewUserController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/NewUserController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/NewUserController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/NewUserController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/RequestMappingShortcutsController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/RequestMappingShortcutsController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/RequestMappingShortcutsController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/RequestMappingShortcutsController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ResponseStatusRestController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ResponseStatusRestController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/ResponseStatusRestController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ResponseStatusRestController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SampleController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SampleController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/SampleController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SampleController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookRestController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookRestController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookRestController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/SimpleBookRestController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/UserRestController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ValidatedPhoneController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ValidatedPhoneController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/ValidatedPhoneController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/ValidatedPhoneController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/BeanNameHandlerMappingController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/BeanNameHandlerMappingController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/BeanNameHandlerMappingController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/BeanNameHandlerMappingController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/SimpleUrlMappingController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/SimpleUrlMappingController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/SimpleUrlMappingController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/SimpleUrlMappingController.java diff --git a/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java similarity index 100% rename from spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java rename to spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/web/controller/handlermapping/WelcomeController.java diff --git a/spring-mvc-basics/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/application.properties similarity index 100% rename from spring-mvc-basics/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-basics/src/main/resources/application.properties diff --git a/spring-mvc-basics/src/main/resources/mvc-configuration.xml b/spring-web-modules/spring-mvc-basics/src/main/resources/mvc-configuration.xml similarity index 100% rename from spring-mvc-basics/src/main/resources/mvc-configuration.xml rename to spring-web-modules/spring-mvc-basics/src/main/resources/mvc-configuration.xml diff --git a/spring-mvc-basics/src/main/resources/themes/default.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/themes/default.properties similarity index 100% rename from spring-mvc-basics/src/main/resources/themes/default.properties rename to spring-web-modules/spring-mvc-basics/src/main/resources/themes/default.properties diff --git a/spring-mvc-basics/src/main/resources/themes/example.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/themes/example.properties similarity index 100% rename from spring-mvc-basics/src/main/resources/themes/example.properties rename to spring-web-modules/spring-mvc-basics/src/main/resources/themes/example.properties diff --git a/spring-mvc-basics/src/main/resources/views.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/views.properties similarity index 100% rename from spring-mvc-basics/src/main/resources/views.properties rename to spring-web-modules/spring-mvc-basics/src/main/resources/views.properties diff --git a/spring-mvc-basics/src/main/resources/views.xml b/spring-web-modules/spring-mvc-basics/src/main/resources/views.xml similarity index 100% rename from spring-mvc-basics/src/main/resources/views.xml rename to spring-web-modules/spring-mvc-basics/src/main/resources/views.xml diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeHome.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeHome.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeHome.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeHome.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeView.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeView.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeView.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/employeeView.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/index.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/index.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/index.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/index.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/phoneHome.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/phoneHome.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/phoneHome.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/phoneHome.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view/userHome.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/userHome.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view/userHome.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view/userHome.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view2/sample2.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view2/sample2.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view2/sample2.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view2/sample2.jsp diff --git a/spring-mvc-basics/src/main/webapp/WEB-INF/view3/sample3.jsp b/spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view3/sample3.jsp similarity index 100% rename from spring-mvc-basics/src/main/webapp/WEB-INF/view3/sample3.jsp rename to spring-web-modules/spring-mvc-basics/src/main/webapp/WEB-INF/view3/sample3.jsp diff --git a/spring-mvc-basics/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/config/BeanNameUrlHandlerMappingConfig.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/BeanNameUrlHandlerMappingConfig.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/config/BeanNameUrlHandlerMappingConfig.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/BeanNameUrlHandlerMappingConfig.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingDefaultConfig.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingDefaultConfig.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingDefaultConfig.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingDefaultConfig.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingPrioritiesConfig.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingPrioritiesConfig.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingPrioritiesConfig.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/HandlerMappingPrioritiesConfig.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/config/SimpleUrlHandlerMappingConfig.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/exception/HttpMediaTypeNotAcceptableExceptionControllerIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/BeanNameMappingConfigIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/BeanNameMappingConfigIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/handlermappings/BeanNameMappingConfigIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/BeanNameMappingConfigIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingDefaultConfigIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingDefaultConfigIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingDefaultConfigIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingDefaultConfigIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingPriorityConfigIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingPriorityConfigIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingPriorityConfigIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/HandlerMappingPriorityConfigIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/SimpleUrlMappingConfigIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/SimpleUrlMappingConfigIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/handlermappings/SimpleUrlMappingConfigIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/handlermappings/SimpleUrlMappingConfigIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ClassValidationMvcIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ClassValidationMvcIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/ClassValidationMvcIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ClassValidationMvcIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/CustomMVCValidatorIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/CustomMVCValidatorIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/CustomMVCValidatorIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/CustomMVCValidatorIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerModelAttributeIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerModelAttributeIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerModelAttributeIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerModelAttributeIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/RequestMapingShortcutsIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/RequestMapingShortcutsIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/RequestMapingShortcutsIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/RequestMapingShortcutsIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ResponseStatusRestControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ResponseStatusRestControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/ResponseStatusRestControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/ResponseStatusRestControllerIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SampleControllerLiveTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SampleControllerLiveTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/SampleControllerLiveTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SampleControllerLiveTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java diff --git a/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java diff --git a/spring-mvc-basics/src/test/resources/BeanNameUrlHandlerMappingConfig.xml b/spring-web-modules/spring-mvc-basics/src/test/resources/BeanNameUrlHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-basics/src/test/resources/BeanNameUrlHandlerMappingConfig.xml rename to spring-web-modules/spring-mvc-basics/src/test/resources/BeanNameUrlHandlerMappingConfig.xml diff --git a/spring-mvc-basics/src/test/resources/ControllerClassNameHandlerMappingConfig.xml b/spring-web-modules/spring-mvc-basics/src/test/resources/ControllerClassNameHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-basics/src/test/resources/ControllerClassNameHandlerMappingConfig.xml rename to spring-web-modules/spring-mvc-basics/src/test/resources/ControllerClassNameHandlerMappingConfig.xml diff --git a/spring-mvc-basics/src/test/resources/HandlerMappingConfiguringPriorities.xml b/spring-web-modules/spring-mvc-basics/src/test/resources/HandlerMappingConfiguringPriorities.xml similarity index 100% rename from spring-mvc-basics/src/test/resources/HandlerMappingConfiguringPriorities.xml rename to spring-web-modules/spring-mvc-basics/src/test/resources/HandlerMappingConfiguringPriorities.xml diff --git a/spring-mvc-basics/src/test/resources/SimpleUrlHandlerMappingConfig.xml b/spring-web-modules/spring-mvc-basics/src/test/resources/SimpleUrlHandlerMappingConfig.xml similarity index 100% rename from spring-mvc-basics/src/test/resources/SimpleUrlHandlerMappingConfig.xml rename to spring-web-modules/spring-mvc-basics/src/test/resources/SimpleUrlHandlerMappingConfig.xml From faa64a1f7591ff43e458d721d01a2f7861c944ed Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 21 Dec 2020 19:53:49 +0530 Subject: [PATCH 343/590] JAVA-3509: Added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index df8b0d6562..29a90b5bd2 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -14,6 +14,7 @@ + spring-mvc-basics From c531b9851d8168a86a184959a13a5482dbd62896 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 21 Dec 2020 19:56:23 +0530 Subject: [PATCH 344/590] JAVA-3509: Updated README to change link from http to https --- spring-web-modules/spring-mvc-basics/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-web-modules/spring-mvc-basics/README.md b/spring-web-modules/spring-mvc-basics/README.md index dea18a1619..49d23aef25 100644 --- a/spring-web-modules/spring-mvc-basics/README.md +++ b/spring-web-modules/spring-mvc-basics/README.md @@ -4,7 +4,7 @@ This module contains articles about the basics of Spring MVC. Articles about mor their own module. ### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring +The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Spring MVC Tutorial](https://www.baeldung.com/spring-mvc-tutorial) From b89b16b430e77e5b811a82e484ef5740d61e6936 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 21 Dec 2020 19:57:39 +0530 Subject: [PATCH 345/590] JAVA-3509: removed module spring-mvc-basics from main pom --- pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b309d027fb..f6e3ddad6c 100644 --- a/pom.xml +++ b/pom.xml @@ -662,8 +662,7 @@ spring-mobile spring-mockito - - spring-mvc-basics + spring-mvc-basics-2 spring-mvc-basics-3 spring-mvc-basics-4 @@ -1149,8 +1148,7 @@ spring-mobile spring-mockito - - spring-mvc-basics + spring-mvc-basics-2 spring-mvc-basics-3 spring-mvc-basics-4 From 8bf0f8a0a3fc37861914ce4f0a616b55b9b0045a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 22 Dec 2020 16:24:43 +0530 Subject: [PATCH 346/590] JAVA-3519: Moved spring-mvc-basics-2 inside spring-web-modules --- .../spring-mvc-basics-2}/README.md | 0 .../spring-mvc-basics-2}/pom.xml | 2 +- .../configuration/ApplicationConfiguration.java | 0 .../spring/configuration/EmailConfiguration.java | 0 .../configuration/FreemarkerConfiguration.java | 0 .../spring/configuration/GroovyConfiguration.java | 0 .../configuration/JadeTemplateConfiguration.java | 0 .../spring/configuration/PushConfiguration.java | 0 .../configuration/ThymeleafConfiguration.java | 0 .../spring/configuration/WebInitializer.java | 0 .../AnnotationMethodHandlerAdapterExample.java | 0 .../spring/controller/CustomerController.java | 0 .../spring/controller/EmployeeController.java | 0 .../spring/controller/FileUploadController.java | 0 .../baeldung/spring/controller/MailController.java | 0 .../RequestMappingHandlerAdapterExample.java | 0 .../spring/controller/RequestMethodController.java | 0 .../SimpleControllerHandlerAdapterExample.java | 0 .../baeldung/spring/controller/UserController.java | 0 .../com/baeldung/spring/controller/rss/Article.java | 0 .../spring/controller/rss/ArticleFeedView.java | 0 .../spring/controller/rss/ArticleRssController.java | 0 .../controller/rss/ArticleRssFeedViewResolver.java | 0 .../rss/JsonChannelHttpMessageConverter.java | 0 .../spring/controller/scribe/GithubController.java | 0 .../spring/controller/scribe/TwitterController.java | 0 .../java/com/baeldung/spring/domain/Customer.java | 0 .../java/com/baeldung/spring/domain/Employee.java | 0 .../java/com/baeldung/spring/domain/MailObject.java | 0 .../main/java/com/baeldung/spring/domain/User.java | 0 .../spring/exception/InvalidRequestException.java | 0 .../interceptor/FileUploadExceptionAdvice.java | 0 .../java/com/baeldung/spring/mail/EmailService.java | 0 .../com/baeldung/spring/mail/EmailServiceImpl.java | 0 .../spring/push/controller/PushController.java | 0 .../spring/requestparam/RequestParamController.java | 0 .../baeldung/spring/service/EmployeeService.java | 0 .../spring/service/EmployeeServiceImpl.java | 0 .../baeldung/spring/servlets/ForwardedServlet.java | 0 .../com/baeldung/spring/servlets/HelloServlet.java | 0 .../baeldung/spring/servlets/RedirectedServlet.java | 0 .../baeldung/spring/servlets/WelcomeServlet.java | 0 .../spring/validator/CustomerValidator.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/mail-logo.png | Bin .../mail-templates/template-freemarker.ftl | 0 .../mail-templates/template-thymeleaf.html | 0 .../src/main/resources/mailMessages.properties | 0 .../main/resources/mailMessages_fr_FR.properties | 0 .../src/main/webapp/WEB-INF/Greeting.jsp | 0 .../src/main/webapp/WEB-INF/views/Greeting.jsp | 0 .../src/main/webapp/WEB-INF/views/customerHome.jsp | 0 .../src/main/webapp/WEB-INF/views/customerView.jsp | 0 .../src/main/webapp/WEB-INF/views/demo.jsp | 0 .../src/main/webapp/WEB-INF/views/emails.jsp | 0 .../src/main/webapp/WEB-INF/views/employeeHome.jsp | 0 .../src/main/webapp/WEB-INF/views/employeeView.jsp | 0 .../src/main/webapp/WEB-INF/views/error.jsp | 0 .../src/main/webapp/WEB-INF/views/file.jsp | 0 .../src/main/webapp/WEB-INF/views/mail/send.jsp | 0 .../src/main/webapp/WEB-INF/views/mail/sendHtml.jsp | 0 .../src/main/webapp/WEB-INF/views/pages/home.jsp | 0 .../main/webapp/WEB-INF/views/pages/springmvc.jsp | 0 .../WEB-INF/views/registration-freemarker.ftl | 0 .../webapp/WEB-INF/views/registration-groovy.tpl | 0 .../webapp/WEB-INF/views/registration-jade.jade | 0 .../WEB-INF/views/registration-thymeleaf.html | 0 .../src/main/webapp/WEB-INF/views/registration.jsp | 0 .../src/main/webapp/resources/logo.png | Bin .../src/main/webapp/static/css/app.css | 0 .../test/java/com/baeldung/SpringContextTest.java | 0 .../push/PushControllerIntegrationTest.java | 0 .../controller/rss/ArticleRssIntegrationTest.java | 0 .../servlets/HelloServletIntegrationTest.java | 0 .../servlets/WelcomeServletIntegrationTest.java | 0 76 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/README.md (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/pom.xml (99%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/FreemarkerConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/GroovyConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/configuration/WebInitializer.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/CustomerController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/EmployeeController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/FileUploadController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/MailController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/RequestMethodController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/UserController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/rss/Article.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/rss/ArticleFeedView.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/rss/ArticleRssController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/rss/ArticleRssFeedViewResolver.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/rss/JsonChannelHttpMessageConverter.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/scribe/GithubController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/controller/scribe/TwitterController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/domain/Customer.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/domain/Employee.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/domain/MailObject.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/domain/User.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/exception/InvalidRequestException.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/interceptor/FileUploadExceptionAdvice.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/mail/EmailService.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/push/controller/PushController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/requestparam/RequestParamController.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/service/EmployeeService.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/service/EmployeeServiceImpl.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/servlets/HelloServlet.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/java/com/baeldung/spring/validator/CustomerValidator.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/application.properties (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/logback.xml (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/mail-logo.png (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/mail-templates/template-freemarker.ftl (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/mail-templates/template-thymeleaf.html (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/mailMessages.properties (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/resources/mailMessages_fr_FR.properties (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/Greeting.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/Greeting.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/customerHome.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/customerView.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/demo.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/emails.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/employeeHome.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/employeeView.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/error.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/file.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/mail/send.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/mail/sendHtml.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/pages/home.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/pages/springmvc.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/registration-freemarker.ftl (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/registration-groovy.tpl (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/registration-jade.jade (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/registration-thymeleaf.html (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/WEB-INF/views/registration.jsp (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/resources/logo.png (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/main/webapp/static/css/app.css (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/test/java/com/baeldung/controller/rss/ArticleRssIntegrationTest.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/test/java/com/baeldung/spring/servlets/HelloServletIntegrationTest.java (100%) rename {spring-mvc-basics-2 => spring-web-modules/spring-mvc-basics-2}/src/test/java/com/baeldung/spring/servlets/WelcomeServletIntegrationTest.java (100%) diff --git a/spring-mvc-basics-2/README.md b/spring-web-modules/spring-mvc-basics-2/README.md similarity index 100% rename from spring-mvc-basics-2/README.md rename to spring-web-modules/spring-mvc-basics-2/README.md diff --git a/spring-mvc-basics-2/pom.xml b/spring-web-modules/spring-mvc-basics-2/pom.xml similarity index 99% rename from spring-mvc-basics-2/pom.xml rename to spring-web-modules/spring-mvc-basics-2/pom.xml index c4688ffad6..e16b54b2c8 100644 --- a/spring-mvc-basics-2/pom.xml +++ b/spring-web-modules/spring-mvc-basics-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-5 0.0.1-SNAPSHOT - ../parent-spring-5 + ../../parent-spring-5 diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/FreemarkerConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/FreemarkerConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/FreemarkerConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/FreemarkerConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/GroovyConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/GroovyConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/GroovyConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/GroovyConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/FileUploadController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/FileUploadController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/FileUploadController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/FileUploadController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMethodController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMethodController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMethodController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/RequestMethodController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/UserController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/UserController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/UserController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/UserController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/Article.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/Article.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/Article.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/Article.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleFeedView.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleFeedView.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleFeedView.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleFeedView.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssFeedViewResolver.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssFeedViewResolver.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssFeedViewResolver.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/ArticleRssFeedViewResolver.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/JsonChannelHttpMessageConverter.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/JsonChannelHttpMessageConverter.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/JsonChannelHttpMessageConverter.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/rss/JsonChannelHttpMessageConverter.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/GithubController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/GithubController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/GithubController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/GithubController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/TwitterController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/TwitterController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/TwitterController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/scribe/TwitterController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Customer.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Customer.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Customer.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Customer.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/User.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/User.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/User.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/User.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/exception/InvalidRequestException.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/exception/InvalidRequestException.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/exception/InvalidRequestException.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/exception/InvalidRequestException.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/interceptor/FileUploadExceptionAdvice.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/interceptor/FileUploadExceptionAdvice.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/interceptor/FileUploadExceptionAdvice.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/interceptor/FileUploadExceptionAdvice.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailService.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailService.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailService.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailService.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/push/controller/PushController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/push/controller/PushController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/push/controller/PushController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/push/controller/PushController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/requestparam/RequestParamController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/requestparam/RequestParamController.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/requestparam/RequestParamController.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/requestparam/RequestParamController.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeService.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeService.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeService.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeService.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeServiceImpl.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeServiceImpl.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeServiceImpl.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/service/EmployeeServiceImpl.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/HelloServlet.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/HelloServlet.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/HelloServlet.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/HelloServlet.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/validator/CustomerValidator.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/validator/CustomerValidator.java similarity index 100% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/validator/CustomerValidator.java rename to spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/validator/CustomerValidator.java diff --git a/spring-mvc-basics-2/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics-2/src/main/resources/application.properties similarity index 100% rename from spring-mvc-basics-2/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/application.properties diff --git a/spring-mvc-basics-2/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-basics-2/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-basics-2/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/logback.xml diff --git a/spring-mvc-basics-2/src/main/resources/mail-logo.png b/spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-logo.png similarity index 100% rename from spring-mvc-basics-2/src/main/resources/mail-logo.png rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-logo.png diff --git a/spring-mvc-basics-2/src/main/resources/mail-templates/template-freemarker.ftl b/spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-templates/template-freemarker.ftl similarity index 100% rename from spring-mvc-basics-2/src/main/resources/mail-templates/template-freemarker.ftl rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-templates/template-freemarker.ftl diff --git a/spring-mvc-basics-2/src/main/resources/mail-templates/template-thymeleaf.html b/spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-templates/template-thymeleaf.html similarity index 100% rename from spring-mvc-basics-2/src/main/resources/mail-templates/template-thymeleaf.html rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/mail-templates/template-thymeleaf.html diff --git a/spring-mvc-basics-2/src/main/resources/mailMessages.properties b/spring-web-modules/spring-mvc-basics-2/src/main/resources/mailMessages.properties similarity index 100% rename from spring-mvc-basics-2/src/main/resources/mailMessages.properties rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/mailMessages.properties diff --git a/spring-mvc-basics-2/src/main/resources/mailMessages_fr_FR.properties b/spring-web-modules/spring-mvc-basics-2/src/main/resources/mailMessages_fr_FR.properties similarity index 100% rename from spring-mvc-basics-2/src/main/resources/mailMessages_fr_FR.properties rename to spring-web-modules/spring-mvc-basics-2/src/main/resources/mailMessages_fr_FR.properties diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/Greeting.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/Greeting.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/Greeting.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/Greeting.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/Greeting.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/Greeting.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/Greeting.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/Greeting.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerHome.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerHome.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerHome.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerHome.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerView.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerView.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerView.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/customerView.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/demo.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/demo.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/demo.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/demo.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/emails.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/emails.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/emails.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/emails.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeHome.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeHome.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeHome.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeHome.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeView.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeView.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeView.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/employeeView.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/error.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/error.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/error.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/error.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/file.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/file.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/file.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/file.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/send.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/send.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/send.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/send.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/sendHtml.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/sendHtml.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/sendHtml.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/mail/sendHtml.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/home.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/home.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/home.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/springmvc.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/springmvc.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/springmvc.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-freemarker.ftl b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-freemarker.ftl similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-freemarker.ftl rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-freemarker.ftl diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-groovy.tpl b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-groovy.tpl similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-groovy.tpl rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-groovy.tpl diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-jade.jade b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-jade.jade similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-jade.jade rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-jade.jade diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-thymeleaf.html b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-thymeleaf.html similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-thymeleaf.html rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration-thymeleaf.html diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration.jsp b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration.jsp rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/registration.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/resources/logo.png b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/resources/logo.png similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/resources/logo.png rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/resources/logo.png diff --git a/spring-mvc-basics-2/src/main/webapp/static/css/app.css b/spring-web-modules/spring-mvc-basics-2/src/main/webapp/static/css/app.css similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/static/css/app.css rename to spring-web-modules/spring-mvc-basics-2/src/main/webapp/static/css/app.css diff --git a/spring-mvc-basics-2/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-basics-2/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-mvc-basics-2/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-2/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java diff --git a/spring-mvc-basics-2/src/test/java/com/baeldung/controller/rss/ArticleRssIntegrationTest.java b/spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/controller/rss/ArticleRssIntegrationTest.java similarity index 100% rename from spring-mvc-basics-2/src/test/java/com/baeldung/controller/rss/ArticleRssIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/controller/rss/ArticleRssIntegrationTest.java diff --git a/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/HelloServletIntegrationTest.java b/spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/HelloServletIntegrationTest.java similarity index 100% rename from spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/HelloServletIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/HelloServletIntegrationTest.java diff --git a/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/WelcomeServletIntegrationTest.java b/spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/WelcomeServletIntegrationTest.java similarity index 100% rename from spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/WelcomeServletIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-2/src/test/java/com/baeldung/spring/servlets/WelcomeServletIntegrationTest.java From f54863d501f991f8f4fc7cb67cdb313652c3c147 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 22 Dec 2020 16:25:19 +0530 Subject: [PATCH 347/590] JAVA-3519: Added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 29a90b5bd2..9134906364 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -15,6 +15,7 @@ spring-mvc-basics + spring-mvc-basics-2 From 97a4f763daeea858652909ab178e654e8a693e47 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 22 Dec 2020 16:26:16 +0530 Subject: [PATCH 348/590] JAVA-3519: removed module spring-mvc-basics-2 from main pom --- pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f6e3ddad6c..00bc39d49f 100644 --- a/pom.xml +++ b/pom.xml @@ -662,8 +662,7 @@ spring-mobile spring-mockito - - spring-mvc-basics-2 + spring-mvc-basics-3 spring-mvc-basics-4 @@ -1148,8 +1147,7 @@ spring-mobile spring-mockito - - spring-mvc-basics-2 + spring-mvc-basics-3 spring-mvc-basics-4 From e5bb56740559f4a05c365145d36d8f658ee284cc Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 22 Dec 2020 21:27:18 +0100 Subject: [PATCH 349/590] Rename finalize methods --- .../migration/junit4/BeforeAndAfterAnnotationsUnitTest.java | 4 ++-- .../junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java index fac07a20ef..6022de123f 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java @@ -28,8 +28,8 @@ public class BeforeAndAfterAnnotationsUnitTest { } @After - public void finalize() { - LOG.info("finalize"); + public void teardown() { + LOG.info("teardown"); list.clear(); } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java index be916d66ea..f0093b3bf6 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java @@ -28,8 +28,8 @@ public class BeforeEachAndAfterEachAnnotationsUnitTest { } @AfterEach - public void finalize() { - LOG.info("finalize"); + public void teardown() { + LOG.info("teardown"); list.clear(); } From 76778779dd6eec6f66ac94520a808b977cfdedcc Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Wed, 23 Dec 2020 00:04:10 +0100 Subject: [PATCH 350/590] mvn package vs springboot:repackage --- spring-boot-modules/pom.xml | 1 + .../spring-boot-artifacts-2/README.md | 7 +++ .../spring-boot-artifacts-2/pom.xml | 48 +++++++++++++++++++ .../com/baeldung/demo/DemoApplication.java | 11 +++++ .../com/baeldung/demo/DemoRestController.java | 15 ++++++ .../src/main/resources/application.yml | 3 ++ 6 files changed, 85 insertions(+) create mode 100644 spring-boot-modules/spring-boot-artifacts-2/README.md create mode 100644 spring-boot-modules/spring-boot-artifacts-2/pom.xml create mode 100644 spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoApplication.java create mode 100644 spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoRestController.java create mode 100644 spring-boot-modules/spring-boot-artifacts-2/src/main/resources/application.yml diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 825af8fb9e..c562d522e2 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -24,6 +24,7 @@ spring-boot-angular spring-boot-annotations spring-boot-artifacts + spring-boot-artifacts-2 spring-boot-autoconfiguration spring-boot-basic-customization spring-boot-basic-customization-2 diff --git a/spring-boot-modules/spring-boot-artifacts-2/README.md b/spring-boot-modules/spring-boot-artifacts-2/README.md new file mode 100644 index 0000000000..80e3d95d14 --- /dev/null +++ b/spring-boot-modules/spring-boot-artifacts-2/README.md @@ -0,0 +1,7 @@ +## Spring Boot Artifacts 2 + +This module contains articles about configuring the Spring Boot build process 2. + +### Relevant Articles: + +TBD \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-artifacts-2/pom.xml b/spring-boot-modules/spring-boot-artifacts-2/pom.xml new file mode 100644 index 0000000000..abea13151e --- /dev/null +++ b/spring-boot-modules/spring-boot-artifacts-2/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ + + + spring-boot-artifacts-2 + jar + + spring-boot-artifacts-2 + Demo project for Spring Boot + + + + org.springframework.boot + spring-boot-starter-web + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + + + com.baeldung.demo.DemoApplication + + + diff --git a/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoApplication.java new file mode 100644 index 0000000000..177d3c834e --- /dev/null +++ b/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoRestController.java b/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoRestController.java new file mode 100644 index 0000000000..0869927926 --- /dev/null +++ b/spring-boot-modules/spring-boot-artifacts-2/src/main/java/com/baeldung/demo/DemoRestController.java @@ -0,0 +1,15 @@ +package com.baeldung.demo; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class DemoRestController { + + @GetMapping(value = "/welcome") + public ResponseEntity welcomeEndpoint() { + return ResponseEntity.ok("Welcome to Baeldung Spring Boot Demo!"); + } + +} diff --git a/spring-boot-modules/spring-boot-artifacts-2/src/main/resources/application.yml b/spring-boot-modules/spring-boot-artifacts-2/src/main/resources/application.yml new file mode 100644 index 0000000000..3cd1d2e797 --- /dev/null +++ b/spring-boot-modules/spring-boot-artifacts-2/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + application: + name: Baeldung_SpringBoot_Demo \ No newline at end of file From 981ca0b5068b3b4fdb73af3304fa7c792ad2990e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 23 Dec 2020 11:05:24 +0100 Subject: [PATCH 351/590] JAVA-3496: Add integration tests for UserRepository --- .../data/jpa/query/UserApplication.java | 13 ++ .../src/main/resources/insert_users.sql | 8 + .../query/UserRepositoryIntegrationTest.java | 162 ++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java create mode 100644 persistence-modules/spring-data-jpa-query-2/src/main/resources/insert_users.sql create mode 100644 persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/spring/data/jpa/query/UserRepositoryIntegrationTest.java diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java new file mode 100644 index 0000000000..0f7b19ec47 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.spring.data.jpa.query; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class UserApplication { + + public static void main(String[] args) { + SpringApplication.run(UserApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/resources/insert_users.sql b/persistence-modules/spring-data-jpa-query-2/src/main/resources/insert_users.sql new file mode 100644 index 0000000000..330b2e36b0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query-2/src/main/resources/insert_users.sql @@ -0,0 +1,8 @@ +insert into Users(id, name, creation_date, last_login_date, active, age, email, status) +values(1, 'John', TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('01/01/2020', 'DD/MM/YYYY'), 1, 23, 'john@email.com', 1); + +insert into Users(id, name, creation_date, last_login_date, active, age, email, status) +values(2, 'Bob', TO_DATE('02/02/2019', 'DD/MM/YYYY'), TO_DATE('02/02/2020', 'DD/MM/YYYY'), 1, 56, 'bob@email.com', 1); + +insert into Users(id, name, creation_date, last_login_date, active, age, email, status) +values(3, 'Cindy', TO_DATE('02/02/2019', 'DD/MM/YYYY'), TO_DATE('02/02/2020', 'DD/MM/YYYY'), 1, 18, 'cindy@email.com', 0); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/spring/data/jpa/query/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/spring/data/jpa/query/UserRepositoryIntegrationTest.java new file mode 100644 index 0000000000..0ede418acd --- /dev/null +++ b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/spring/data/jpa/query/UserRepositoryIntegrationTest.java @@ -0,0 +1,162 @@ +package com.baeldung.spring.data.jpa.query; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.JpaSort; +import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@RunWith(SpringRunner.class) +@DataJpaTest(properties = "spring.datasource.data=classpath:insert_users.sql") +public class UserRepositoryIntegrationTest { + + @Autowired + private UserRepository userRepository; + + @Test + public void whenFindAllActiveUsersThenAllActiveFound() { + Collection allActiveUsers = userRepository.findAllActiveUsers(); + assertThat(allActiveUsers).hasSize(2); + } + + @Test + public void whenFindAllActiveUsersNativeThenAllActiveFound() { + Collection allActiveUsers = userRepository.findAllActiveUsersNative(); + assertThat(allActiveUsers).hasSize(2); + } + + @Test + public void whenFindAllSortedByNameThenAllSorted() { + List allUsersSortedByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); + assertThat(allUsersSortedByName) + .extracting("name") + .containsSequence("Bob", "Cindy", "John"); + } + + @Test + public void whenFindAllSortedByNameLengthThenException() { + assertThatThrownBy(() -> userRepository.findAll(Sort.by("LENGTH(name)"))) + .isInstanceOf(PropertyReferenceException.class); + } + + @Test + public void whenFindAllUsersSortedByNameThenAllSorted() { + List allUsersSortedByName = userRepository.findAllUsers(Sort.by(Sort.Direction.ASC, "name")); + assertThat(allUsersSortedByName) + .extracting("name") + .containsSequence("Bob", "Cindy", "John"); + } + + @Test + public void whenFindAllUsersSortedByNameLengthThenAllSorted() { + List allUsersSortedByName = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); + assertThat(allUsersSortedByName) + .extracting("name") + .containsSequence("Bob", "John", "Cindy"); + } + + @Test + public void whenFindAllUsersWithPaginationThenPaginated() { + Page page = userRepository.findAllUsersWithPagination(PageRequest.of(0, 1)); + assertThat(page.stream().map(User::getId)) + .hasSize(1) + .containsOnly(1); + } + + @Test + public void whenFindAllUsersWithPaginationNativeThenPaginated() { + Page page = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 1)); + assertThat(page.stream().map(User::getId)) + .hasSize(1) + .containsOnly(2); + } + + @Test + public void whenFindUserByStatusThenFound() { + User user = userRepository.findUserByStatus(0); + assertThat(user.getStatus()).isZero(); + } + + @Test + public void whenFindUserByStatusAndNameThenFound() { + User user = userRepository.findUserByStatusAndName(1, "John"); + assertThat(user.getStatus()).isOne(); + assertThat(user.getName()).isEqualTo("John"); + } + + @Test + public void whenFindUserByStatusNativeThenFound() { + User user = userRepository.findUserByStatusNative(0); + assertThat(user.getStatus()).isZero(); + } + + @Test + public void whenFindUserByStatusAndNameNamedParamsThenFound() { + User user = userRepository.findUserByStatusAndNameNamedParams(1, "John"); + assertThat(user.getStatus()).isOne(); + assertThat(user.getName()).isEqualTo("John"); + } + + @Test + public void whenFindUserByUserStatusAndUserNameThenFound() { + User user = userRepository.findUserByUserStatusAndUserName(1, "John"); + assertThat(user.getStatus()).isOne(); + assertThat(user.getName()).isEqualTo("John"); + } + + @Test + public void whenFindUserByStatusAndNameNamedParamsNativeThenFound() { + User user = userRepository.findUserByStatusAndNameNamedParamsNative(1, "Bob"); + assertThat(user.getStatus()).isOne(); + assertThat(user.getName()).isEqualTo("Bob"); + } + + @Test + public void whenFindUserByNameListThenAllFound() { + List users = userRepository.findUserByNameList(Arrays.asList("Bob", "Cindy")); + assertThat(users) + .extracting("name") + .containsOnly("Bob", "Cindy"); + } + + @Test + public void whenUpdateUserSetStatusForNameThenUpdated() { + int updated = userRepository.updateUserSetStatusForName(0, "John"); + assertThat(updated).isOne(); + + User john = userRepository.findUserByStatusAndName(0, "John"); + assertThat(john).isNotNull(); + } + + @Test + public void whenUpdateUserSetStatusForNameNativeThenUpdated() { + int updated = userRepository.updateUserSetStatusForNameNative(0, "John"); + assertThat(updated).isOne(); + + User john = userRepository.findUserByStatusAndName(0, "John"); + assertThat(john).isNotNull(); + } + + @Test + public void whenInsertUserThenInserted() { + User beforeInsert = userRepository.findUserByStatusAndName(0, "Mandy"); + assertThat(beforeInsert).isNull(); + + userRepository.insertUser("Mandy", 20, "mandy@email.com", 0, true); + + User afterInsert = userRepository.findUserByStatusAndName(0, "Mandy"); + assertThat(afterInsert).isNotNull(); + } +} From c6e380d798ed362a754754a73f82a7553f66dd0d Mon Sep 17 00:00:00 2001 From: krzysztof Date: Wed, 23 Dec 2020 12:46:18 +0100 Subject: [PATCH 352/590] BAEL-4750 Java 12 New Features --- .../newfeatures/CompactNumbersUnitTest.java | 21 ++++++++++++ .../newfeatures/FileMismatchUnitTest.java | 32 +++++++++++++++++++ .../baeldung/newfeatures/StringUnitTest.java | 15 +++++++++ .../newfeatures/TeeingCollectorUnitTest.java | 18 +++++++++++ 4 files changed, 86 insertions(+) create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java new file mode 100644 index 0000000000..08a6d58d72 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java @@ -0,0 +1,21 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.text.NumberFormat; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +public class CompactNumbersUnitTest { + + @Test + public void givenNumber_thenCompactValues() { + NumberFormat likesShort = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT); + likesShort.setMaximumFractionDigits(2); + assertEquals("2.59K", likesShort.format(2592)); + NumberFormat likesLong = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG); + likesLong.setMaximumFractionDigits(2); + assertEquals("2.59 thousand", likesShort.format(2592)); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java new file mode 100644 index 0000000000..7f081fe399 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java @@ -0,0 +1,32 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.Assert.assertEquals; + +public class FileMismatchUnitTest { + + @Test + public void givenIdenticalFiles_thenShouldNotFindMismatch() throws IOException { + Path filePath1 = Files.createTempFile("file1", ".txt"); + Path filePath2 = Files.createTempFile("file2", ".txt"); + Files.writeString(filePath1, "Java 12 Article"); + Files.writeString(filePath2, "Java 12 Article"); + long mismatch = Files.mismatch(filePath1, filePath2); + assertEquals(-1, mismatch); + } + + @Test + public void givenDifferentFiles_thenShouldFindMismatch() throws IOException { + Path filePath3 = Files.createTempFile("file3", ".txt"); + Path filePath4 = Files.createTempFile("file4", ".txt"); + Files.writeString(filePath3, "Java 12 Article"); + Files.writeString(filePath4, "Java 12 Tutorial"); + long mismatch = Files.mismatch(filePath3, filePath4); + assertEquals(8, mismatch); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java new file mode 100644 index 0000000000..5ae51bd960 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java @@ -0,0 +1,15 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class StringUnitTest { + + @Test + public void givenString_thenRevertValue() { + String text = "Baeldung"; + String transformed = text.transform(value -> new StringBuilder(value).reverse().toString()); + assertEquals("gnudleaB", transformed); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java new file mode 100644 index 0000000000..90fc4eda5e --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java @@ -0,0 +1,18 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +public class TeeingCollectorUnitTest { + + @Test + public void givenSetOfNumbers_thenCalculateAverage() { + double mean = Stream.of(1, 2, 3, 4, 5) + .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); + assertEquals(3.0, mean); + } +} From c79e7d8cbdf130e36412289d1f6c24070617a142 Mon Sep 17 00:00:00 2001 From: krzysztof Date: Wed, 23 Dec 2020 12:48:07 +0100 Subject: [PATCH 353/590] BAEL-4750 Java 12 New Features --- .../java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java index 90fc4eda5e..30a5cb40a7 100644 --- a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java @@ -12,7 +12,7 @@ public class TeeingCollectorUnitTest { @Test public void givenSetOfNumbers_thenCalculateAverage() { double mean = Stream.of(1, 2, 3, 4, 5) - .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); + .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); assertEquals(3.0, mean); } } From 500b2f63f8086d75dac536f66e32ba6e6d28aa31 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 23 Dec 2020 18:51:25 +0530 Subject: [PATCH 354/590] JAVA-3520: Moved spring-mvc-basics-3 inside spring-web-modules --- .../spring-mvc-basics-3}/README.md | 0 .../spring-mvc-basics-3}/pom.xml | 2 +- .../src/main/java/com/baeldung/boot/Application.java | 0 .../src/main/java/com/baeldung/boot/config/WebConfig.java | 0 .../com/baeldung/boot/controller/GenericEntityController.java | 0 .../com/baeldung/boot/converter/GenericBigDecimalConverter.java | 0 .../boot/converter/StringToAbstractEntityConverterFactory.java | 0 .../com/baeldung/boot/converter/StringToEmployeeConverter.java | 0 .../java/com/baeldung/boot/converter/StringToEnumConverter.java | 0 .../baeldung/boot/converter/StringToLocalDateTimeConverter.java | 0 .../boot/converter/controller/AbstractEntityController.java | 0 .../controller/StringToEmployeeConverterController.java | 0 .../src/main/java/com/baeldung/boot/domain/AbstractEntity.java | 0 .../src/main/java/com/baeldung/boot/domain/Bar.java | 0 .../src/main/java/com/baeldung/boot/domain/Employee.java | 0 .../src/main/java/com/baeldung/boot/domain/Foo.java | 0 .../src/main/java/com/baeldung/boot/domain/GenericEntity.java | 0 .../src/main/java/com/baeldung/boot/domain/Modes.java | 0 .../com/baeldung/boot/repository/GenericEntityRepository.java | 0 .../boot/web/resolver/HeaderVersionArgumentResolver.java | 0 .../src/main/java/com/baeldung/boot/web/resolver/Version.java | 0 .../baeldung/cachedrequest/CachedBodyHttpServletRequest.java | 0 .../baeldung/cachedrequest/CachedBodyServletInputStream.java | 0 .../java/com/baeldung/cachedrequest/ContentCachingFilter.java | 0 .../java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java | 0 .../src/main/java/com/baeldung/cachedrequest/Person.java | 0 .../main/java/com/baeldung/cachedrequest/PersonController.java | 0 .../com/baeldung/cachedrequest/PrintRequestContentFilter.java | 0 .../main/java/com/baeldung/exclude_urls_filter/Application.java | 0 .../baeldung/exclude_urls_filter/controller/FAQController.java | 0 .../java/com/baeldung/exclude_urls_filter/controller/Ping.java | 0 .../exclude_urls_filter/filter/FilterRegistrationConfig.java | 0 .../exclude_urls_filter/filter/HeaderValidatorFilter.java | 0 .../java/com/baeldung/exclude_urls_filter/filter/LogFilter.java | 0 .../com/baeldung/exclude_urls_filter/service/FAQService.java | 0 .../baeldung/exclude_urls_filter/service/FAQServiceImpl.java | 0 .../main/java/com/baeldung/flash_attributes/Application.java | 0 .../baeldung/flash_attributes/controllers/PoemSubmission.java | 0 .../src/main/java/com/baeldung/flash_attributes/model/Poem.java | 0 .../src/main/java/com/baeldung/form_submission/Application.java | 0 .../com/baeldung/form_submission/controllers/FeedbackForm.java | 0 .../main/java/com/baeldung/form_submission/model/Feedback.java | 0 .../java/com/baeldung/interpolation/MyMessageInterpolator.java | 0 .../main/java/com/baeldung/interpolation/NotNullRequest.java | 0 .../java/com/baeldung/interpolation/ValidationController.java | 0 .../java/com/baeldung/interpolation/ValidationExamples.java | 0 .../src/main/java/com/baeldung/spring/Application.java | 0 .../src/main/java/com/baeldung/spring/config/MvcConfig.java | 0 .../baeldung/spring/config/converter/StringToEnumConverter.java | 0 .../src/main/java/com/baeldung/spring/enums/EnumController.java | 0 .../spring/exceptions/GlobalControllerExceptionHandler.java | 0 .../spring/headers/controller/ReadHeaderRestController.java | 0 .../src/main/java/com/baeldung/spring/model/Modes.java | 0 .../src/main/java/com/baeldung/spring/slash/Application.java | 0 .../java/com/baeldung/spring/slash/SlashParsingController.java | 0 .../listvalidation/SpringListValidationApplication.java | 0 .../validation/listvalidation/constraint/MaxSizeConstraint.java | 0 .../listvalidation/constraint/MaxSizeConstraintValidator.java | 0 .../validation/listvalidation/controller/MovieController.java | 0 .../exception/ConstraintViolationExceptionHandler.java | 0 .../com/baeldung/validation/listvalidation/model/Movie.java | 0 .../validation/listvalidation/service/MovieService.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/templates/feedback.html | 0 .../src/main/resources/templates/submit.html | 0 .../src/main/resources/templates/success.html | 0 .../src/test/java/com/baeldung/AppContextIntegrationTest.java | 0 .../java/com/baeldung/SpringBootApplicationIntegrationTest.java | 0 .../test/java/com/baeldung/SpringBootJPAIntegrationTest.java | 0 .../test/java/com/baeldung/SpringBootMailIntegrationTest.java | 0 .../cachedrequest/CachedBodyHttpServletRequestUnitTest.java | 0 .../cachedrequest/CachedBodyServletInputStreamUnitTest.java | 0 .../baeldung/cachedrequest/ContentCachingFilterUnitTest.java | 0 .../baeldung/cachedrequest/PersonControllerIntegrationTest.java | 0 .../cachedrequest/PrintRequestContentFilterUnitTest.java | 0 .../controller/ReadHeaderRestControllerIntegrationTest.java | 0 .../baeldung/spring/slash/SlashParsingControllerIntTest.java | 0 .../listvalidation/MovieControllerIntegrationTest.java | 0 78 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/README.md (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/pom.xml (98%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/config/WebConfig.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/controller/GenericEntityController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/StringToAbstractEntityConverterFactory.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/StringToEnumConverter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/StringToLocalDateTimeConverter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/controller/AbstractEntityController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/AbstractEntity.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/Bar.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/Employee.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/Foo.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/GenericEntity.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/domain/Modes.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/repository/GenericEntityRepository.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/boot/web/resolver/Version.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/Person.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/PersonController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/flash_attributes/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/flash_attributes/model/Poem.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/form_submission/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/form_submission/model/Feedback.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/interpolation/NotNullRequest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/interpolation/ValidationController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/interpolation/ValidationExamples.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/config/MvcConfig.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/enums/EnumController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/model/Modes.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/slash/Application.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/spring/slash/SlashParsingController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/SpringListValidationApplication.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraint.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraintValidator.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/controller/MovieController.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/exception/ConstraintViolationExceptionHandler.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/model/Movie.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/java/com/baeldung/validation/listvalidation/service/MovieService.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/resources/application.properties (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/resources/templates/feedback.html (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/resources/templates/submit.html (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/main/resources/templates/success.html (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/AppContextIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/SpringBootApplicationIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequestUnitTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/cachedrequest/PersonControllerIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java (100%) rename {spring-mvc-basics-3 => spring-web-modules/spring-mvc-basics-3}/src/test/java/com/baeldung/validation/listvalidation/MovieControllerIntegrationTest.java (100%) diff --git a/spring-mvc-basics-3/README.md b/spring-web-modules/spring-mvc-basics-3/README.md similarity index 100% rename from spring-mvc-basics-3/README.md rename to spring-web-modules/spring-mvc-basics-3/README.md diff --git a/spring-mvc-basics-3/pom.xml b/spring-web-modules/spring-mvc-basics-3/pom.xml similarity index 98% rename from spring-mvc-basics-3/pom.xml rename to spring-web-modules/spring-mvc-basics-3/pom.xml index a929337b25..c6b7763d64 100644 --- a/spring-mvc-basics-3/pom.xml +++ b/spring-web-modules/spring-mvc-basics-3/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/config/WebConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/config/WebConfig.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/config/WebConfig.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/config/WebConfig.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToAbstractEntityConverterFactory.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToAbstractEntityConverterFactory.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToAbstractEntityConverterFactory.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToAbstractEntityConverterFactory.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEnumConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEnumConverter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEnumConverter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToEnumConverter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToLocalDateTimeConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToLocalDateTimeConverter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToLocalDateTimeConverter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/StringToLocalDateTimeConverter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/AbstractEntityController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/AbstractEntityController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/AbstractEntityController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/AbstractEntityController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/AbstractEntity.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/AbstractEntity.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/AbstractEntity.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/AbstractEntity.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Bar.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Bar.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Bar.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Bar.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Modes.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Modes.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Modes.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Modes.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/repository/GenericEntityRepository.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/repository/GenericEntityRepository.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/repository/GenericEntityRepository.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/repository/GenericEntityRepository.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/Version.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/Version.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/Version.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/Version.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/Person.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/Person.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/Person.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/Person.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PersonController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PersonController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PersonController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PersonController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/model/Poem.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/model/Poem.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/model/Poem.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/model/Poem.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/MvcConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/MvcConfig.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/MvcConfig.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/MvcConfig.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/enums/EnumController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/enums/EnumController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/enums/EnumController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/enums/EnumController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/model/Modes.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/model/Modes.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/model/Modes.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/model/Modes.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/SpringListValidationApplication.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/SpringListValidationApplication.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/SpringListValidationApplication.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/SpringListValidationApplication.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraint.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraint.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraint.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraint.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraintValidator.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraintValidator.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraintValidator.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/constraint/MaxSizeConstraintValidator.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/controller/MovieController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/controller/MovieController.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/controller/MovieController.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/controller/MovieController.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/exception/ConstraintViolationExceptionHandler.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/exception/ConstraintViolationExceptionHandler.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/exception/ConstraintViolationExceptionHandler.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/exception/ConstraintViolationExceptionHandler.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/model/Movie.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/model/Movie.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/model/Movie.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/model/Movie.java diff --git a/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/service/MovieService.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/service/MovieService.java similarity index 100% rename from spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/service/MovieService.java rename to spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/validation/listvalidation/service/MovieService.java diff --git a/spring-mvc-basics-3/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics-3/src/main/resources/application.properties similarity index 100% rename from spring-mvc-basics-3/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-basics-3/src/main/resources/application.properties diff --git a/spring-mvc-basics-3/src/main/resources/templates/feedback.html b/spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/feedback.html similarity index 100% rename from spring-mvc-basics-3/src/main/resources/templates/feedback.html rename to spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/feedback.html diff --git a/spring-mvc-basics-3/src/main/resources/templates/submit.html b/spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/submit.html similarity index 100% rename from spring-mvc-basics-3/src/main/resources/templates/submit.html rename to spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/submit.html diff --git a/spring-mvc-basics-3/src/main/resources/templates/success.html b/spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/success.html similarity index 100% rename from spring-mvc-basics-3/src/main/resources/templates/success.html rename to spring-web-modules/spring-mvc-basics-3/src/main/resources/templates/success.html diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/AppContextIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/AppContextIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/AppContextIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/AppContextIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootApplicationIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootApplicationIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootApplicationIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootApplicationIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootJPAIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequestUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequestUnitTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequestUnitTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequestUnitTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PersonControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PersonControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PersonControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PersonControllerIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java diff --git a/spring-mvc-basics-3/src/test/java/com/baeldung/validation/listvalidation/MovieControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/validation/listvalidation/MovieControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-3/src/test/java/com/baeldung/validation/listvalidation/MovieControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/validation/listvalidation/MovieControllerIntegrationTest.java From e0db0ca9f8da49bbd1e979058d540b6968f390c8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 23 Dec 2020 18:51:57 +0530 Subject: [PATCH 355/590] JAVA-3520: added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 9134906364..6900e20994 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -16,6 +16,7 @@ spring-mvc-basics spring-mvc-basics-2 + spring-mvc-basics-3 From 2d9750ec8a1b55c62b0d81c1b48f12bc409f8d92 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 23 Dec 2020 18:52:49 +0530 Subject: [PATCH 356/590] JAVA-3520: Removed module spring-mvc-basics-3 from main pom --- pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 00bc39d49f..ec5586a4ad 100644 --- a/pom.xml +++ b/pom.xml @@ -662,8 +662,7 @@ spring-mobile spring-mockito - - spring-mvc-basics-3 + spring-mvc-basics-4 spring-mvc-forms-jsp @@ -1148,7 +1147,6 @@ spring-mobile spring-mockito - spring-mvc-basics-3 spring-mvc-basics-4 spring-mvc-forms-jsp From dd3513dd532b1e29fa4547a3283cfeb7195fed83 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:27:26 +0800 Subject: [PATCH 357/590] Update README.md --- spring-websockets/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-websockets/README.md b/spring-websockets/README.md index 26e1c6db7c..9cc84f0fda 100644 --- a/spring-websockets/README.md +++ b/spring-websockets/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring WebSockets. ### Relevant articles - [Intro to WebSockets with Spring](https://www.baeldung.com/websockets-spring) - [A Quick Example of Spring Websockets’ @SendToUser Annotation](https://www.baeldung.com/spring-websockets-sendtouser) +- [Scheduled WebSocket Push with Spring Boot](https://www.baeldung.com/spring-boot-scheduled-websocket) From ea4d34438aac13922e72f206690f3036ef52c202 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:30:16 +0800 Subject: [PATCH 358/590] Update README.md --- spring-resttemplate-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-resttemplate-2/README.md b/spring-resttemplate-2/README.md index aab6a188b6..a903757bb4 100644 --- a/spring-resttemplate-2/README.md +++ b/spring-resttemplate-2/README.md @@ -9,3 +9,4 @@ This module contains articles about Spring RestTemplate - [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type) - [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) - [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) +- [Get list of JSON objects with Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-json-list) From 73358da094936652f8727cf5eaaacca2e916c6f0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:32:01 +0800 Subject: [PATCH 359/590] Update README.md --- spring-apache-camel/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-apache-camel/README.md b/spring-apache-camel/README.md index e89eb4fe6c..6a16e1da05 100644 --- a/spring-apache-camel/README.md +++ b/spring-apache-camel/README.md @@ -9,6 +9,7 @@ This module contains articles about Spring with Apache Camel - [Introduction To Apache Camel](http://www.baeldung.com/apache-camel-intro) - [Integration Patterns With Apache Camel](http://www.baeldung.com/camel-integration-patterns) - [Using Apache Camel with Spring](http://www.baeldung.com/spring-apache-camel-tutorial) +- [Unmarshalling a JSON Array Using camel-jackson](https://www.baeldung.com/java-camel-jackson-json-array) ### Framework Versions: @@ -23,4 +24,4 @@ To build this application execute: To run this application you can either run our main class App from your IDE or you can execute following maven command: -`mvn exec:java -Dexec.mainClass="com.baeldung.camel.main.App"` \ No newline at end of file +`mvn exec:java -Dexec.mainClass="com.baeldung.camel.main.App"` From d1bb00ed39ffb41168387aec04c60d10d0bee158 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:34:11 +0800 Subject: [PATCH 360/590] Update README.md --- core-java-modules/core-java-14/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md index d382c4814a..004b3587c4 100644 --- a/core-java-modules/core-java-14/README.md +++ b/core-java-modules/core-java-14/README.md @@ -10,3 +10,4 @@ This module contains articles about Java 14. - [Helpful NullPointerExceptions in Java 14](https://www.baeldung.com/java-14-nullpointerexception) - [Foreign Memory Access API in Java 14](https://www.baeldung.com/java-foreign-memory-access) - [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword) +- [Java 14 – New Features](https://www.baeldung.com/java-14-new-features) From af36328752111b0255cf5094ee5501eb2fff4310 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:36:11 +0800 Subject: [PATCH 361/590] Create README.md --- spring-boot-modules/spring-boot-data-2/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-boot-modules/spring-boot-data-2/README.md diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md new file mode 100644 index 0000000000..d5020ce354 --- /dev/null +++ b/spring-boot-modules/spring-boot-data-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper) From b682fddd885a971fd51ee5384d7c6a24b77b59e9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 23 Dec 2020 22:38:23 +0800 Subject: [PATCH 362/590] Update README.md --- core-java-modules/core-java-collections-maps-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-maps-3/README.md b/core-java-modules/core-java-collections-maps-3/README.md index 7386f7e9b7..918c81fe4b 100644 --- a/core-java-modules/core-java-collections-maps-3/README.md +++ b/core-java-modules/core-java-collections-maps-3/README.md @@ -6,4 +6,5 @@ This module contains articles about Map data structures in Java. - [Java TreeMap vs HashMap](https://www.baeldung.com/java-treemap-vs-hashmap) - [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps) - [The Map.computeIfAbsent() Method](https://www.baeldung.com/java-map-computeifabsent) +- [Collections.synchronizedMap vs. ConcurrentHashMap](https://www.baeldung.com/java-synchronizedmap-vs-concurrenthashmap) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-2) From a07556adaf2381d70955c122188fb61bc479869b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 24 Dec 2020 12:41:29 +0100 Subject: [PATCH 363/590] JAVA-3710: Use hibernate-core in spring-jpa --- persistence-modules/spring-jpa/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-jpa/pom.xml b/persistence-modules/spring-jpa/pom.xml index 410ed592b0..e389886d8d 100644 --- a/persistence-modules/spring-jpa/pom.xml +++ b/persistence-modules/spring-jpa/pom.xml @@ -41,7 +41,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core ${hibernate.version} From 95f98baeb33516967e98096a79a330ad13598c42 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 24 Dec 2020 12:45:51 +0100 Subject: [PATCH 364/590] JAVA-3710: Use hibernate-core in spring-jpa-2 --- persistence-modules/spring-jpa-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-jpa-2/pom.xml b/persistence-modules/spring-jpa-2/pom.xml index 8d8dfe3a7b..7770c0e045 100644 --- a/persistence-modules/spring-jpa-2/pom.xml +++ b/persistence-modules/spring-jpa-2/pom.xml @@ -46,7 +46,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core ${hibernate.version} From 6af6f685fd22cbbd63ef6711b725c463638c61f0 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 24 Dec 2020 13:07:07 +0100 Subject: [PATCH 365/590] JAVA-3710: Replace hibernate-entitymanager dependency with hibernate-core --- atomikos/pom.xml | 2 +- persistence-modules/querydsl/pom.xml | 2 +- spring-jinq/pom.xml | 5 ----- spring-rest-query-language/pom.xml | 2 +- spring-rest-testing/pom.xml | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/atomikos/pom.xml b/atomikos/pom.xml index d680a3ca77..8918de7b77 100644 --- a/atomikos/pom.xml +++ b/atomikos/pom.xml @@ -51,7 +51,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core ${hibernate.version} provided diff --git a/persistence-modules/querydsl/pom.xml b/persistence-modules/querydsl/pom.xml index 9f6802ff77..a611c309b6 100644 --- a/persistence-modules/querydsl/pom.xml +++ b/persistence-modules/querydsl/pom.xml @@ -31,7 +31,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core ${hibernate.version} compile diff --git a/spring-jinq/pom.xml b/spring-jinq/pom.xml index 647c0907a7..1f5d8cd915 100644 --- a/spring-jinq/pom.xml +++ b/spring-jinq/pom.xml @@ -27,11 +27,6 @@ h2 - - org.hibernate - hibernate-entitymanager - - org.springframework.boot spring-boot-starter-data-jpa diff --git a/spring-rest-query-language/pom.xml b/spring-rest-query-language/pom.xml index 2423528743..4458aa0580 100644 --- a/spring-rest-query-language/pom.xml +++ b/spring-rest-query-language/pom.xml @@ -140,7 +140,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core xml-apis diff --git a/spring-rest-testing/pom.xml b/spring-rest-testing/pom.xml index 9bfe9d83a4..0e947260f4 100644 --- a/spring-rest-testing/pom.xml +++ b/spring-rest-testing/pom.xml @@ -120,7 +120,7 @@ org.hibernate - hibernate-entitymanager + hibernate-core xml-apis From 405bb17b46b4a8371abc19a9c9d946fc5e9f5ed9 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 24 Dec 2020 19:58:59 +0530 Subject: [PATCH 366/590] JAVA-3521: Moved spring-mvc-basics-4 inside spring-web-modules --- .../spring-mvc-basics-4}/.gitignore | 0 .../spring-mvc-basics-4}/README.md | 2 +- .../spring-mvc-basics-4}/pom.xml | 2 +- .../src/main/java/com/baeldung/contexts/Greeting.java | 0 .../AnnotationsBasedApplicationAndServletInitializer.java | 0 .../contexts/config/AnnotationsBasedApplicationInitializer.java | 0 .../com/baeldung/contexts/config/ApplicationInitializer.java | 0 .../java/com/baeldung/contexts/config/NormalWebAppConfig.java | 0 .../com/baeldung/contexts/config/RootApplicationConfig.java | 0 .../SecureAnnotationsBasedApplicationAndServletInitializer.java | 0 .../java/com/baeldung/contexts/config/SecureWebAppConfig.java | 0 .../java/com/baeldung/contexts/normal/HelloWorldController.java | 0 .../baeldung/contexts/secure/HelloWorldSecureController.java | 0 .../contexts/services/ApplicationContextUtilService.java | 0 .../java/com/baeldung/contexts/services/GreeterService.java | 0 .../com/baeldung/controller/config/StudentControllerConfig.java | 0 .../src/main/java/com/baeldung/controller/config/WebConfig.java | 0 .../controller/controller/PassParametersController.java | 0 .../baeldung/controller/controller/RestAnnotatedController.java | 0 .../java/com/baeldung/controller/controller/RestController.java | 0 .../java/com/baeldung/controller/controller/TestController.java | 0 .../src/main/java/com/baeldung/controller/student/Student.java | 0 .../java/com/baeldung/jsonparams/config/JsonParamsConfig.java | 0 .../java/com/baeldung/jsonparams/config/JsonParamsInit.java | 0 .../com/baeldung/jsonparams/controller/ProductController.java | 0 .../src/main/java/com/baeldung/jsonparams/model/Product.java | 0 .../com/baeldung/jsonparams/propertyeditor/ProductEditor.java | 0 .../src/main/java/com/baeldung/optionalpathvars/Article.java | 0 .../com/baeldung/optionalpathvars/ArticleViewerController.java | 0 .../optionalpathvars/ArticleViewerWithMapParamController.java | 0 .../ArticleViewerWithOptionalParamController.java | 0 .../ArticleViewerWithRequiredAttributeController.java | 0 .../ArticleViewerWithTwoSeparateMethodsController.java | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-basics-4}/src/main/resources/logback.xml | 0 .../spring-mvc-basics-4}/src/main/resources/test-mvc.xml | 0 .../spring-mvc-basics-4}/src/main/webapp/WEB-INF/greeting.xml | 0 .../spring-mvc-basics-4}/src/main/webapp/WEB-INF/index.jsp | 0 .../src/main/webapp/WEB-INF/normal-webapp-servlet.xml | 0 .../src/main/webapp/WEB-INF/rootApplicationContext.xml | 0 .../src/main/webapp/WEB-INF/secure-webapp-servlet.xml | 0 .../src/main/webapp/WEB-INF/secure/view/welcome.jsp | 0 .../src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/view/scopesExample.jsp | 0 .../src/main/webapp/WEB-INF/view/viewPage.html | 0 .../src/main/webapp/WEB-INF/view/welcome.jsp | 0 .../spring-mvc-basics-4}/src/main/webapp/WEB-INF/web-old.xml | 0 .../spring-mvc-basics-4}/src/main/webapp/WEB-INF/welcome.jsp | 0 .../spring-mvc-basics-4}/src/main/webapp/index.jsp | 0 .../controller/ControllerAnnotationIntegrationTest.java | 0 .../java/com/baeldung/controller/ControllerIntegrationTest.java | 0 .../controller/PassParametersControllerIntegrationTest.java | 0 .../java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java | 0 .../ArticleViewerControllerIntegrationTest.java | 0 ...ArticleViewerControllerWithOptionalParamIntegrationTest.java | 0 ...cleViewerControllerWithRequiredAttributeIntegrationTest.java | 0 .../ArticleViewerWithMapParamIntegrationTest.java | 0 .../ArticleViewerWithTwoSeparateMethodsIntegrationTest.java | 0 .../spring-mvc-basics-4}/src/test/resources/test-mvc.xml | 0 59 files changed, 2 insertions(+), 2 deletions(-) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/.gitignore (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/README.md (90%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/pom.xml (94%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/Greeting.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/services/ApplicationContextUtilService.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/contexts/services/GreeterService.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/config/StudentControllerConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/config/WebConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/controller/PassParametersController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/controller/RestAnnotatedController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/controller/RestController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/controller/TestController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/controller/student/Student.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/jsonparams/controller/ProductController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/jsonparams/model/Product.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/Article.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/resources/application.properties (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/resources/logback.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/resources/test-mvc.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/greeting.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/index.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/normal-webapp-servlet.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/rootApplicationContext.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/secure-webapp-servlet.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/secure/view/welcome.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/view/scopesExample.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/view/viewPage.html (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/view/welcome.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/web-old.xml (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/WEB-INF/welcome.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/main/webapp/index.jsp (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/controller/ControllerAnnotationIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/controller/ControllerIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/controller/PassParametersControllerIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java (100%) rename {spring-mvc-basics-4 => spring-web-modules/spring-mvc-basics-4}/src/test/resources/test-mvc.xml (100%) diff --git a/spring-mvc-basics-4/.gitignore b/spring-web-modules/spring-mvc-basics-4/.gitignore similarity index 100% rename from spring-mvc-basics-4/.gitignore rename to spring-web-modules/spring-mvc-basics-4/.gitignore diff --git a/spring-mvc-basics-4/README.md b/spring-web-modules/spring-mvc-basics-4/README.md similarity index 90% rename from spring-mvc-basics-4/README.md rename to spring-web-modules/spring-mvc-basics-4/README.md index 0da83540ad..d0bca4a303 100644 --- a/spring-mvc-basics-4/README.md +++ b/spring-web-modules/spring-mvc-basics-4/README.md @@ -1,7 +1,7 @@ ## Spring MVC Basics with Java Configuration Example Project ### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring +The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Quick Guide to Spring Controllers](https://www.baeldung.com/spring-controllers) diff --git a/spring-mvc-basics-4/pom.xml b/spring-web-modules/spring-mvc-basics-4/pom.xml similarity index 94% rename from spring-mvc-basics-4/pom.xml rename to spring-web-modules/spring-mvc-basics-4/pom.xml index 8382cd03b8..07dddcde0c 100644 --- a/spring-mvc-basics-4/pom.xml +++ b/spring-web-modules/spring-mvc-basics-4/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/Greeting.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/Greeting.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/Greeting.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/Greeting.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/ApplicationContextUtilService.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/ApplicationContextUtilService.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/ApplicationContextUtilService.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/ApplicationContextUtilService.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/GreeterService.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/GreeterService.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/GreeterService.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/contexts/services/GreeterService.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/StudentControllerConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/StudentControllerConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/StudentControllerConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/StudentControllerConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/WebConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/WebConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/WebConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/config/WebConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/PassParametersController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/PassParametersController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/PassParametersController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/PassParametersController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestAnnotatedController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestAnnotatedController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestAnnotatedController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestAnnotatedController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/RestController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/TestController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/TestController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/TestController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/controller/TestController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/controller/student/Student.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/student/Student.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/controller/student/Student.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/controller/student/Student.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java b/spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java similarity index 100% rename from spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java rename to spring-web-modules/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java diff --git a/spring-mvc-basics-4/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics-4/src/main/resources/application.properties similarity index 100% rename from spring-mvc-basics-4/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-basics-4/src/main/resources/application.properties diff --git a/spring-mvc-basics-4/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-basics-4/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-basics-4/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/resources/logback.xml diff --git a/spring-mvc-basics-4/src/main/resources/test-mvc.xml b/spring-web-modules/spring-mvc-basics-4/src/main/resources/test-mvc.xml similarity index 100% rename from spring-mvc-basics-4/src/main/resources/test-mvc.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/resources/test-mvc.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/greeting.xml b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/greeting.xml similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/greeting.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/greeting.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/index.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/index.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/index.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/index.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/normal-webapp-servlet.xml b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/normal-webapp-servlet.xml similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/normal-webapp-servlet.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/normal-webapp-servlet.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/rootApplicationContext.xml b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/rootApplicationContext.xml similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/rootApplicationContext.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/rootApplicationContext.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure-webapp-servlet.xml b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure-webapp-servlet.xml similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/secure-webapp-servlet.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure-webapp-servlet.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure/view/welcome.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure/view/welcome.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/secure/view/welcome.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/secure/view/welcome.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/scopesExample.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/scopesExample.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/view/scopesExample.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/scopesExample.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/viewPage.html b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/viewPage.html similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/view/viewPage.html rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/viewPage.html diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/welcome.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/view/welcome.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/view/welcome.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/web-old.xml b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/web-old.xml similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/web-old.xml rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/web-old.xml diff --git a/spring-mvc-basics-4/src/main/webapp/WEB-INF/welcome.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/welcome.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/WEB-INF/welcome.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/WEB-INF/welcome.jsp diff --git a/spring-mvc-basics-4/src/main/webapp/index.jsp b/spring-web-modules/spring-mvc-basics-4/src/main/webapp/index.jsp similarity index 100% rename from spring-mvc-basics-4/src/main/webapp/index.jsp rename to spring-web-modules/spring-mvc-basics-4/src/main/webapp/index.jsp diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerAnnotationIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerAnnotationIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerAnnotationIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerAnnotationIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/ControllerIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/controller/PassParametersControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/PassParametersControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/controller/PassParametersControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/controller/PassParametersControllerIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java b/spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java similarity index 100% rename from spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java rename to spring-web-modules/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java diff --git a/spring-mvc-basics-4/src/test/resources/test-mvc.xml b/spring-web-modules/spring-mvc-basics-4/src/test/resources/test-mvc.xml similarity index 100% rename from spring-mvc-basics-4/src/test/resources/test-mvc.xml rename to spring-web-modules/spring-mvc-basics-4/src/test/resources/test-mvc.xml From 6af74b63f18e933322c678669181ac826b40a03a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 24 Dec 2020 19:59:41 +0530 Subject: [PATCH 367/590] JAVA-3521: added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 6900e20994..bf6fda09f4 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -17,6 +17,7 @@ spring-mvc-basics spring-mvc-basics-2 spring-mvc-basics-3 + spring-mvc-basics-4 From ba9e0b9c38d307102addb361153b6ef43f0bc42a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 24 Dec 2020 20:00:29 +0530 Subject: [PATCH 368/590] JAVA-3521: removed spring-mvc-basics-4 from main pom --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index ec5586a4ad..e0ad1ad35a 100644 --- a/pom.xml +++ b/pom.xml @@ -662,8 +662,6 @@ spring-mobile spring-mockito - - spring-mvc-basics-4 spring-mvc-forms-jsp spring-mvc-forms-thymeleaf @@ -1146,8 +1144,6 @@ spring-mobile spring-mockito - - spring-mvc-basics-4 spring-mvc-forms-jsp spring-mvc-forms-thymeleaf From 2d2a64acbe74fdb9da86e582362e6df28590db8c Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Fri, 25 Dec 2020 09:06:51 +0530 Subject: [PATCH 369/590] Added changes to show transaction roll back --- .../baeldung/spring/transaction/Course.java | 35 +++++++++++++++++ .../spring/transaction/CourseDao.java | 24 ++++++++++++ .../spring/transaction/CourseService.java | 38 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java new file mode 100644 index 0000000000..5add1e4a99 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java @@ -0,0 +1,35 @@ +package com.baeldung.spring.transaction; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "course") +public class Course implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "id") + private Long id; + + public Course() { + } + + public Course(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java new file mode 100644 index 0000000000..489784bb40 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.transaction; + +import java.sql.SQLException; + +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.stereotype.Repository; + +import com.baeldung.spring.hibernate.AbstractHibernateDao; + +@Repository +public class CourseDao extends AbstractHibernateDao { + public CourseDao() { + super(); + setClazz(Course.class); + } + + public Course createWithRuntimeException(final Course entity) { + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); + } + + public Course createWithCheckedException(final Course entity) throws SQLException { + throw new SQLException("Throwing exception for demoing Rollback!!!"); + } +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java new file mode 100644 index 0000000000..1478c5bd1d --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -0,0 +1,38 @@ +package com.baeldung.spring.transaction; + +import java.sql.SQLException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +@Service +public class CourseService { + + @Autowired + private CourseDao courseDao; + + @Transactional + public void createCourseDeclarativeWithRuntimeException(Course course) { + courseDao.createWithRuntimeException(course); + } + + @Transactional(rollbackFor = { SQLException.class }) + public void createCourseDeclarativeWithCheckedException(Course course) throws SQLException { + courseDao.createWithCheckedException(course); + } + + public void createCourseDefaultRatingProgramatic(Course course) { + try { + courseDao.createWithRuntimeException(course); + } catch (Exception e) { + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + } + + public Course findById(Long id) { + return courseDao.findOne(id); + } + +} From 4fb5e52080dba3d85df14737ba053c0d3ce21772 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:41:37 +0530 Subject: [PATCH 370/590] JAVA-3506: removed moved modules from main pom --- pom.xml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index ec5586a4ad..4dca7e76c7 100644 --- a/pom.xml +++ b/pom.xml @@ -606,9 +606,6 @@ spring-5-reactive-client spring-5-reactive-oauth spring-5-reactive-security - spring-5-security - spring-5-security-cognito - spring-5-security-oauth spring-5-webflux spring-activiti @@ -658,8 +655,6 @@ spring-kafka spring-katharsis - spring-ldap - spring-mobile spring-mockito @@ -693,11 +688,9 @@ spring-scheduling spring-security-modules - spring-session spring-shell spring-sleuth - spring-soap - spring-social-login + spring-soap spring-spel spring-state-machine spring-static-resources @@ -1092,9 +1085,6 @@ spring-5-reactive-client spring-5-reactive-oauth spring-5-reactive-security - spring-5-security - spring-5-security-cognito - spring-5-security-oauth spring-5-webflux spring-activiti @@ -1142,8 +1132,6 @@ spring-kafka spring-katharsis - spring-ldap - spring-mobile spring-mockito @@ -1177,11 +1165,9 @@ spring-scheduling spring-security-modules - spring-session spring-shell spring-sleuth spring-soap - spring-social-login spring-spel spring-state-machine spring-static-resources From 69e579debe498e3d9eea901fb5ba61f1c8400e13 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:42:29 +0530 Subject: [PATCH 371/590] JAVA-3506: moved spring-5-security inside spring-security-modules --- .../spring-5-security}/README.md | 0 .../spring-5-security}/pom.xml | 2 +- .../java/com/baeldung/authresolver/AuthResolverApplication.java | 0 .../java/com/baeldung/authresolver/AuthResolverController.java | 0 .../com/baeldung/authresolver/CustomWebSecurityConfigurer.java | 0 .../java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java | 0 .../main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java | 0 .../main/java/com/baeldung/dsl/CustomConfigurerApplication.java | 0 .../src/main/java/com/baeldung/dsl/MyController.java | 0 .../src/main/java/com/baeldung/dsl/SecurityConfig.java | 0 .../java/com/baeldung/inmemory/InMemoryAuthApplication.java | 0 .../main/java/com/baeldung/inmemory/InMemoryAuthController.java | 0 .../baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java | 0 .../inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java | 0 .../loginextrafieldscustom/CustomAuthenticationFilter.java | 0 .../loginextrafieldscustom/CustomAuthenticationToken.java | 0 .../CustomUserDetailsAuthenticationProvider.java | 0 .../loginextrafieldscustom/CustomUserDetailsService.java | 0 .../loginextrafieldscustom/CustomUserDetailsServiceImpl.java | 0 .../baeldung/loginextrafieldscustom/CustomUserRepository.java | 0 .../loginextrafieldscustom/ExtraLoginFieldsApplication.java | 0 .../loginextrafieldscustom/PasswordEncoderConfiguration.java | 0 .../com/baeldung/loginextrafieldscustom/SecurityConfig.java | 0 .../src/main/java/com/baeldung/loginextrafieldscustom/User.java | 0 .../com/baeldung/loginextrafieldscustom/UserRepository.java | 0 .../java/com/baeldung/loginextrafieldscustom/WebController.java | 0 .../loginextrafieldssimple/ExtraLoginFieldsApplication.java | 0 .../loginextrafieldssimple/PasswordEncoderConfiguration.java | 0 .../com/baeldung/loginextrafieldssimple/SecurityConfig.java | 0 .../loginextrafieldssimple/SimpleAuthenticationFilter.java | 0 .../loginextrafieldssimple/SimpleUserDetailsService.java | 0 .../baeldung/loginextrafieldssimple/SimpleUserRepository.java | 0 .../src/main/java/com/baeldung/loginextrafieldssimple/User.java | 0 .../com/baeldung/loginextrafieldssimple/UserRepository.java | 0 .../java/com/baeldung/loginextrafieldssimple/WebController.java | 0 .../java/com/baeldung/logoutredirects/LogoutApplication.java | 0 .../logoutredirects/securityconfig/SpringSecurityConfig.java | 0 .../java/com/baeldung/manuallogout/ManualLogoutApplication.java | 0 .../com/baeldung/manuallogout/SimpleSecurityConfiguration.java | 0 .../baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java | 0 .../baeldung/passwordstorage/PasswordStorageApplication.java | 0 .../passwordstorage/PasswordStorageWebSecurityConfigurer.java | 0 .../src/main/java/com/baeldung/securityprofile/Application.java | 0 .../com/baeldung/securityprofile/ApplicationNoSecurity.java | 0 .../java/com/baeldung/securityprofile/ApplicationSecurity.java | 0 .../java/com/baeldung/securityprofile/EmployeeController.java | 0 .../src/main/resources/application-extrafields.properties | 0 .../src/main/resources/application.properties | 0 .../spring-5-security}/src/main/resources/logback.xml | 0 .../spring-5-security}/src/main/resources/static/css/main.css | 0 .../spring-5-security}/src/main/resources/templates/index.html | 0 .../src/main/resources/templatesextrafields/index.html | 0 .../src/main/resources/templatesextrafields/login.html | 0 .../src/main/resources/templatesextrafields/user/index.html | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../com/baeldung/authresolver/AuthResolverIntegrationTest.java | 0 .../inmemory/InMemoryAuthControllerIntegrationTest.java | 0 .../AbstractExtraLoginFieldsIntegrationTest.java | 0 .../loginextrafields/LoginFieldsFullIntegrationTest.java | 0 .../loginextrafields/LoginFieldsSimpleIntegrationTest.java | 0 .../com/baeldung/logoutredirects/LogoutApplicationUnitTest.java | 0 .../com/baeldung/manuallogout/ManualLogoutIntegrationTest.java | 0 .../securityprofile/EmployeeControllerNoSecurityUnitTest.java | 0 .../baeldung/securityprofile/EmployeeControllerUnitTest.java | 0 64 files changed, 1 insertion(+), 1 deletion(-) rename {spring-5-security => spring-security-modules/spring-5-security}/README.md (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/pom.xml (97%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/authresolver/AuthResolverApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/authresolver/AuthResolverController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/authresolver/CustomWebSecurityConfigurer.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/dsl/CustomConfigurerApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/dsl/MyController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/dsl/SecurityConfig.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/inmemory/InMemoryAuthApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/inmemory/InMemoryAuthController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/PasswordEncoderConfiguration.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/User.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/PasswordEncoderConfiguration.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/User.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/manuallogout/ManualLogoutApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/manuallogout/SimpleSecurityConfiguration.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/passwordstorage/PasswordStorageApplication.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/securityprofile/Application.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/java/com/baeldung/securityprofile/EmployeeController.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/application-extrafields.properties (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/application.properties (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/logback.xml (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/static/css/main.css (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/templates/index.html (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/templatesextrafields/index.html (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/templatesextrafields/login.html (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/main/resources/templatesextrafields/user/index.html (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/authresolver/AuthResolverIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/manuallogout/ManualLogoutIntegrationTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java (100%) rename {spring-5-security => spring-security-modules/spring-5-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java (100%) diff --git a/spring-5-security/README.md b/spring-security-modules/spring-5-security/README.md similarity index 100% rename from spring-5-security/README.md rename to spring-security-modules/spring-5-security/README.md diff --git a/spring-5-security/pom.xml b/spring-security-modules/spring-5-security/pom.xml similarity index 97% rename from spring-5-security/pom.xml rename to spring-security-modules/spring-5-security/pom.xml index c486d5346b..09de91491c 100644 --- a/spring-5-security/pom.xml +++ b/spring-security-modules/spring-5-security/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/AuthResolverController.java diff --git a/spring-5-security/src/main/java/com/baeldung/authresolver/CustomWebSecurityConfigurer.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/CustomWebSecurityConfigurer.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/authresolver/CustomWebSecurityConfigurer.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/authresolver/CustomWebSecurityConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java diff --git a/spring-5-security/src/main/java/com/baeldung/dsl/CustomConfigurerApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/CustomConfigurerApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/dsl/CustomConfigurerApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/CustomConfigurerApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/dsl/MyController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/MyController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/dsl/MyController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/MyController.java diff --git a/spring-5-security/src/main/java/com/baeldung/dsl/SecurityConfig.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/dsl/SecurityConfig.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/dsl/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthController.java diff --git a/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryAuthWebSecurityConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/PasswordEncoderConfiguration.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/PasswordEncoderConfiguration.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/PasswordEncoderConfiguration.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/PasswordEncoderConfiguration.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/PasswordEncoderConfiguration.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/PasswordEncoderConfiguration.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/PasswordEncoderConfiguration.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/PasswordEncoderConfiguration.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/manuallogout/ManualLogoutApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/manuallogout/ManualLogoutApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/manuallogout/ManualLogoutApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/manuallogout/ManualLogoutApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/manuallogout/SimpleSecurityConfiguration.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/manuallogout/SimpleSecurityConfiguration.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/manuallogout/SimpleSecurityConfiguration.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/manuallogout/SimpleSecurityConfiguration.java diff --git a/spring-5-security/src/main/java/com/baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/BaeldungPasswordEncoderSetup.java diff --git a/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageApplication.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageApplication.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java rename to spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java diff --git a/spring-5-security/src/main/resources/application-extrafields.properties b/spring-security-modules/spring-5-security/src/main/resources/application-extrafields.properties similarity index 100% rename from spring-5-security/src/main/resources/application-extrafields.properties rename to spring-security-modules/spring-5-security/src/main/resources/application-extrafields.properties diff --git a/spring-5-security/src/main/resources/application.properties b/spring-security-modules/spring-5-security/src/main/resources/application.properties similarity index 100% rename from spring-5-security/src/main/resources/application.properties rename to spring-security-modules/spring-5-security/src/main/resources/application.properties diff --git a/spring-5-security/src/main/resources/logback.xml b/spring-security-modules/spring-5-security/src/main/resources/logback.xml similarity index 100% rename from spring-5-security/src/main/resources/logback.xml rename to spring-security-modules/spring-5-security/src/main/resources/logback.xml diff --git a/spring-5-security/src/main/resources/static/css/main.css b/spring-security-modules/spring-5-security/src/main/resources/static/css/main.css similarity index 100% rename from spring-5-security/src/main/resources/static/css/main.css rename to spring-security-modules/spring-5-security/src/main/resources/static/css/main.css diff --git a/spring-5-security/src/main/resources/templates/index.html b/spring-security-modules/spring-5-security/src/main/resources/templates/index.html similarity index 100% rename from spring-5-security/src/main/resources/templates/index.html rename to spring-security-modules/spring-5-security/src/main/resources/templates/index.html diff --git a/spring-5-security/src/main/resources/templatesextrafields/index.html b/spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/index.html similarity index 100% rename from spring-5-security/src/main/resources/templatesextrafields/index.html rename to spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/index.html diff --git a/spring-5-security/src/main/resources/templatesextrafields/login.html b/spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/login.html similarity index 100% rename from spring-5-security/src/main/resources/templatesextrafields/login.html rename to spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/login.html diff --git a/spring-5-security/src/main/resources/templatesextrafields/user/index.html b/spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/user/index.html similarity index 100% rename from spring-5-security/src/main/resources/templatesextrafields/user/index.html rename to spring-security-modules/spring-5-security/src/main/resources/templatesextrafields/user/index.html diff --git a/spring-5-security/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/authresolver/AuthResolverIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/authresolver/AuthResolverIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/authresolver/AuthResolverIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/authresolver/AuthResolverIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/manuallogout/ManualLogoutIntegrationTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/manuallogout/ManualLogoutIntegrationTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/manuallogout/ManualLogoutIntegrationTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/manuallogout/ManualLogoutIntegrationTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java diff --git a/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java rename to spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java From 3880907db1e077345246556b503283177441e6cc Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:42:51 +0530 Subject: [PATCH 372/590] JAVA-3506: moved spring-5-security-cognito inside spring-security-modules --- .../spring-5-security-cognito}/README.md | 0 .../spring-5-security-cognito}/pom.xml | 2 +- .../main/java/com/baeldung/cognito/CognitoWebConfiguration.java | 0 .../main/java/com/baeldung/cognito/SecurityConfiguration.java | 0 .../java/com/baeldung/cognito/SpringCognitoApplication.java | 0 .../src/main/resources/application.yml | 0 .../spring-5-security-cognito}/src/main/resources/logback.xml | 0 .../src/main/resources/templates/home.html | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/README.md (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/pom.xml (97%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/java/com/baeldung/cognito/SecurityConfiguration.java (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/resources/application.yml (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/resources/logback.xml (100%) rename {spring-5-security-cognito => spring-security-modules/spring-5-security-cognito}/src/main/resources/templates/home.html (100%) diff --git a/spring-5-security-cognito/README.md b/spring-security-modules/spring-5-security-cognito/README.md similarity index 100% rename from spring-5-security-cognito/README.md rename to spring-security-modules/spring-5-security-cognito/README.md diff --git a/spring-5-security-cognito/pom.xml b/spring-security-modules/spring-5-security-cognito/pom.xml similarity index 97% rename from spring-5-security-cognito/pom.xml rename to spring-security-modules/spring-5-security-cognito/pom.xml index 5f8f328086..877dbd52fa 100644 --- a/spring-5-security-cognito/pom.xml +++ b/spring-security-modules/spring-5-security-cognito/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java b/spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java similarity index 100% rename from spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java rename to spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java b/spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java similarity index 100% rename from spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java rename to spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java b/spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java similarity index 100% rename from spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java rename to spring-security-modules/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java diff --git a/spring-5-security-cognito/src/main/resources/application.yml b/spring-security-modules/spring-5-security-cognito/src/main/resources/application.yml similarity index 100% rename from spring-5-security-cognito/src/main/resources/application.yml rename to spring-security-modules/spring-5-security-cognito/src/main/resources/application.yml diff --git a/spring-5-security-cognito/src/main/resources/logback.xml b/spring-security-modules/spring-5-security-cognito/src/main/resources/logback.xml similarity index 100% rename from spring-5-security-cognito/src/main/resources/logback.xml rename to spring-security-modules/spring-5-security-cognito/src/main/resources/logback.xml diff --git a/spring-5-security-cognito/src/main/resources/templates/home.html b/spring-security-modules/spring-5-security-cognito/src/main/resources/templates/home.html similarity index 100% rename from spring-5-security-cognito/src/main/resources/templates/home.html rename to spring-security-modules/spring-5-security-cognito/src/main/resources/templates/home.html From d7afc4a11b2ee728fa52ddf2c10e5b884d16544b Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:43:12 +0530 Subject: [PATCH 373/590] JAVA-3506: moved spring-5-security-oauth inside spring-security-modules --- .../spring-5-security-oauth}/README.md | 0 .../spring-5-security-oauth}/pom.xml | 2 +- .../src/main/java/com/baeldung/jersey/JerseyApplication.java | 0 .../src/main/java/com/baeldung/jersey/JerseyResource.java | 0 .../src/main/java/com/baeldung/jersey/RestConfig.java | 0 .../src/main/java/com/baeldung/jersey/SecurityConfig.java | 0 .../java/com/baeldung/oauth2/CustomRequestSecurityConfig.java | 0 .../src/main/java/com/baeldung/oauth2/LoginController.java | 0 .../src/main/java/com/baeldung/oauth2/MvcConfig.java | 0 .../src/main/java/com/baeldung/oauth2/SecurityConfig.java | 0 .../main/java/com/baeldung/oauth2/SpringOAuthApplication.java | 0 .../com/baeldung/oauth2extractors/ExtractorsApplication.java | 0 .../baeldung/oauth2extractors/configuration/SecurityConfig.java | 0 .../extractor/custom/BaeldungAuthoritiesExtractor.java | 0 .../extractor/custom/BaeldungPrincipalExtractor.java | 0 .../extractor/github/GithubAuthoritiesExtractor.java | 0 .../extractor/github/GithubPrincipalExtractor.java | 0 .../oauth2request/CustomAuthorizationRequestResolver.java | 0 .../baeldung/oauth2request/CustomRequestEntityConverter.java | 0 .../baeldung/oauth2request/CustomTokenResponseConverter.java | 0 .../baeldung/oauth2request/LinkedinTokenResponseConverter.java | 0 .../resources/application-oauth2-extractors-baeldung.properties | 0 .../resources/application-oauth2-extractors-github.properties | 0 .../src/main/resources/application-oauth2.properties | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/default-application.properties | 0 .../src/main/resources/jersey-application.properties | 0 .../spring-5-security-oauth}/src/main/resources/logback.xml | 0 .../src/main/resources/static/css/main.css | 0 .../src/main/resources/templates/index.html | 0 .../src/main/resources/templates/loginFailure.html | 0 .../src/main/resources/templates/loginSuccess.html | 0 .../src/main/resources/templates/oauth2_extractors.html | 0 .../src/main/resources/templates/oauth_login.html | 0 .../src/main/resources/templates/securedPage.html | 0 .../test/java/com/baeldung/jersey/JerseyResourceUnitTest.java | 0 .../java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java | 0 37 files changed, 1 insertion(+), 1 deletion(-) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/README.md (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/pom.xml (98%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/jersey/JerseyApplication.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/jersey/JerseyResource.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/jersey/RestConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/jersey/SecurityConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/LoginController.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/MvcConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SecurityConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-baeldung.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-github.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/application-oauth2.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/application.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/default-application.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/jersey-application.properties (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/logback.xml (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/static/css/main.css (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/index.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/loginFailure.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/loginSuccess.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/oauth2_extractors.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/oauth_login.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/main/resources/templates/securedPage.html (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java (100%) rename {spring-5-security-oauth => spring-security-modules/spring-5-security-oauth}/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java (100%) diff --git a/spring-5-security-oauth/README.md b/spring-security-modules/spring-5-security-oauth/README.md similarity index 100% rename from spring-5-security-oauth/README.md rename to spring-security-modules/spring-5-security-oauth/README.md diff --git a/spring-5-security-oauth/pom.xml b/spring-security-modules/spring-5-security-oauth/pom.xml similarity index 98% rename from spring-5-security-oauth/pom.xml rename to spring-security-modules/spring-5-security-oauth/pom.xml index 19aaa576c8..d31cf293a3 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-security-modules/spring-5-security-oauth/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java b/spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java similarity index 100% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java rename to spring-security-modules/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java diff --git a/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties diff --git a/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties diff --git a/spring-5-security-oauth/src/main/resources/application-oauth2.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/application-oauth2.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/application-oauth2.properties diff --git a/spring-5-security-oauth/src/main/resources/application.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/application.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/application.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/application.properties diff --git a/spring-5-security-oauth/src/main/resources/default-application.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/default-application.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/default-application.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/default-application.properties diff --git a/spring-5-security-oauth/src/main/resources/jersey-application.properties b/spring-security-modules/spring-5-security-oauth/src/main/resources/jersey-application.properties similarity index 100% rename from spring-5-security-oauth/src/main/resources/jersey-application.properties rename to spring-security-modules/spring-5-security-oauth/src/main/resources/jersey-application.properties diff --git a/spring-5-security-oauth/src/main/resources/logback.xml b/spring-security-modules/spring-5-security-oauth/src/main/resources/logback.xml similarity index 100% rename from spring-5-security-oauth/src/main/resources/logback.xml rename to spring-security-modules/spring-5-security-oauth/src/main/resources/logback.xml diff --git a/spring-5-security-oauth/src/main/resources/static/css/main.css b/spring-security-modules/spring-5-security-oauth/src/main/resources/static/css/main.css similarity index 100% rename from spring-5-security-oauth/src/main/resources/static/css/main.css rename to spring-security-modules/spring-5-security-oauth/src/main/resources/static/css/main.css diff --git a/spring-5-security-oauth/src/main/resources/templates/index.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/index.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/index.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/index.html diff --git a/spring-5-security-oauth/src/main/resources/templates/loginFailure.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/loginFailure.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/loginFailure.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/loginFailure.html diff --git a/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/loginSuccess.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html diff --git a/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html diff --git a/spring-5-security-oauth/src/main/resources/templates/oauth_login.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/oauth_login.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/oauth_login.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/oauth_login.html diff --git a/spring-5-security-oauth/src/main/resources/templates/securedPage.html b/spring-security-modules/spring-5-security-oauth/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-5-security-oauth/src/main/resources/templates/securedPage.html rename to spring-security-modules/spring-5-security-oauth/src/main/resources/templates/securedPage.html diff --git a/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java b/spring-security-modules/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java similarity index 100% rename from spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java rename to spring-security-modules/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java diff --git a/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java b/spring-security-modules/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java similarity index 100% rename from spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java rename to spring-security-modules/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java From cca9e25a42f05ebf6f57a53aacc297623acd8c89 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:43:37 +0530 Subject: [PATCH 374/590] JAVA-3506: moved spring-ldap inside spring-security-modules --- .../spring-ldap}/.gitignore | 0 .../spring-ldap}/README.md | 0 {spring-ldap => spring-security-modules/spring-ldap}/pom.xml | 4 ++-- .../src/main/java/com/baeldung/ldap/client/LdapClient.java | 0 .../src/main/java/com/baeldung/ldap/data/repository/User.java | 0 .../com/baeldung/ldap/data/repository/UserRepository.java | 0 .../main/java/com/baeldung/ldap/data/service/LdapClient.java | 0 .../main/java/com/baeldung/ldap/data/service/UserService.java | 0 .../src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java | 0 .../spring-ldap}/src/main/resources/application.properties | 0 .../spring-ldap}/src/main/resources/logback.xml | 0 .../java/com/baeldung/ldap/client/LdapClientLiveTest.java | 0 .../ldap/client/LdapDataRepositoryIntegrationTest.java | 0 .../test/java/com/baeldung/ldap/javaconfig/TestConfig.java | 0 .../src/test/java/org/baeldung/SpringContextTest.java | 0 .../spring-ldap}/src/test/resources/test.ldif | 0 .../src/test/resources/test_application.properties | 0 17 files changed, 2 insertions(+), 2 deletions(-) rename {spring-ldap => spring-security-modules/spring-ldap}/.gitignore (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/README.md (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/pom.xml (98%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/client/LdapClient.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/data/repository/User.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/data/repository/UserRepository.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/data/service/LdapClient.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/data/service/UserService.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/resources/application.properties (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/main/resources/logback.xml (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/java/com/baeldung/ldap/client/LdapClientLiveTest.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/java/com/baeldung/ldap/client/LdapDataRepositoryIntegrationTest.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/java/com/baeldung/ldap/javaconfig/TestConfig.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/java/org/baeldung/SpringContextTest.java (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/resources/test.ldif (100%) rename {spring-ldap => spring-security-modules/spring-ldap}/src/test/resources/test_application.properties (100%) diff --git a/spring-ldap/.gitignore b/spring-security-modules/spring-ldap/.gitignore similarity index 100% rename from spring-ldap/.gitignore rename to spring-security-modules/spring-ldap/.gitignore diff --git a/spring-ldap/README.md b/spring-security-modules/spring-ldap/README.md similarity index 100% rename from spring-ldap/README.md rename to spring-security-modules/spring-ldap/README.md diff --git a/spring-ldap/pom.xml b/spring-security-modules/spring-ldap/pom.xml similarity index 98% rename from spring-ldap/pom.xml rename to spring-security-modules/spring-ldap/pom.xml index a9882ccb52..60da7d4c0d 100644 --- a/spring-ldap/pom.xml +++ b/spring-security-modules/spring-ldap/pom.xml @@ -9,8 +9,8 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + spring-security-modules + 0.0.1-SNAPSHOT diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/client/LdapClient.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/client/LdapClient.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/client/LdapClient.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/client/LdapClient.java diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/User.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/User.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/data/repository/User.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/User.java diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/UserRepository.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/UserRepository.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/data/repository/UserRepository.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/repository/UserRepository.java diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/data/service/LdapClient.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/service/LdapClient.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/data/service/LdapClient.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/service/LdapClient.java diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/data/service/UserService.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/service/UserService.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/data/service/UserService.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/data/service/UserService.java diff --git a/spring-ldap/src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java b/spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java similarity index 100% rename from spring-ldap/src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java rename to spring-security-modules/spring-ldap/src/main/java/com/baeldung/ldap/javaconfig/AppConfig.java diff --git a/spring-ldap/src/main/resources/application.properties b/spring-security-modules/spring-ldap/src/main/resources/application.properties similarity index 100% rename from spring-ldap/src/main/resources/application.properties rename to spring-security-modules/spring-ldap/src/main/resources/application.properties diff --git a/spring-ldap/src/main/resources/logback.xml b/spring-security-modules/spring-ldap/src/main/resources/logback.xml similarity index 100% rename from spring-ldap/src/main/resources/logback.xml rename to spring-security-modules/spring-ldap/src/main/resources/logback.xml diff --git a/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapClientLiveTest.java b/spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapClientLiveTest.java similarity index 100% rename from spring-ldap/src/test/java/com/baeldung/ldap/client/LdapClientLiveTest.java rename to spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapClientLiveTest.java diff --git a/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapDataRepositoryIntegrationTest.java b/spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapDataRepositoryIntegrationTest.java similarity index 100% rename from spring-ldap/src/test/java/com/baeldung/ldap/client/LdapDataRepositoryIntegrationTest.java rename to spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/client/LdapDataRepositoryIntegrationTest.java diff --git a/spring-ldap/src/test/java/com/baeldung/ldap/javaconfig/TestConfig.java b/spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/javaconfig/TestConfig.java similarity index 100% rename from spring-ldap/src/test/java/com/baeldung/ldap/javaconfig/TestConfig.java rename to spring-security-modules/spring-ldap/src/test/java/com/baeldung/ldap/javaconfig/TestConfig.java diff --git a/spring-ldap/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-ldap/src/test/java/org/baeldung/SpringContextTest.java similarity index 100% rename from spring-ldap/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-ldap/src/test/java/org/baeldung/SpringContextTest.java diff --git a/spring-ldap/src/test/resources/test.ldif b/spring-security-modules/spring-ldap/src/test/resources/test.ldif similarity index 100% rename from spring-ldap/src/test/resources/test.ldif rename to spring-security-modules/spring-ldap/src/test/resources/test.ldif diff --git a/spring-ldap/src/test/resources/test_application.properties b/spring-security-modules/spring-ldap/src/test/resources/test_application.properties similarity index 100% rename from spring-ldap/src/test/resources/test_application.properties rename to spring-security-modules/spring-ldap/src/test/resources/test_application.properties From c6f3d465d5d27038911918f0bbfb9a0e0b3ad474 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:44:02 +0530 Subject: [PATCH 375/590] JAVA-3506: moved spring-session inside spring-security-modules --- .../spring-session}/README.md | 0 .../spring-session}/pom.xml | 2 +- .../spring-session}/spring-session-jdbc/README.md | 0 .../spring-session}/spring-session-jdbc/pom.xml | 2 +- .../springsessionjdbc/SpringSessionJdbcApplication.java | 0 .../controller/SpringSessionJdbcController.java | 0 .../src/main/resources/application.properties | 0 .../spring-session-jdbc/src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../springsessionjdbc/SpringSessionJdbcIntegrationTest.java | 0 .../spring-session}/spring-session-mongodb/README.md | 0 .../spring-session}/spring-session-mongodb/pom.xml | 2 +- .../springsessionmongodb/SpringSessionMongoDBApplication.java | 0 .../controller/SpringSessionMongoDBController.java | 0 .../src/main/resources/application.properties | 0 .../spring-session-mongodb/src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../SpringSessionMongoDBIntegrationTest.java | 0 .../src/test/resources/application.properties | 0 .../spring-session}/spring-session-redis/README.md | 0 .../spring-session}/spring-session-redis/pom.xml | 2 +- .../main/java/com/baeldung/spring/session/SecurityConfig.java | 0 .../java/com/baeldung/spring/session/SessionController.java | 0 .../java/com/baeldung/spring/session/SessionWebApplication.java | 0 .../src/main/resources/application.properties | 0 .../spring-session-redis/src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextLiveTest.java | 0 .../spring/session/SessionControllerIntegrationTest.java | 0 28 files changed, 4 insertions(+), 4 deletions(-) rename {spring-session => spring-security-modules/spring-session}/README.md (100%) rename {spring-session => spring-security-modules/spring-session}/pom.xml (93%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/README.md (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/pom.xml (95%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/SpringSessionJdbcApplication.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/main/resources/application.properties (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/main/resources/logback.xml (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/README.md (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/pom.xml (96%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBApplication.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/main/resources/application.properties (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/main/resources/logback.xml (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-mongodb/src/test/resources/application.properties (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/README.md (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/pom.xml (96%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/main/java/com/baeldung/spring/session/SecurityConfig.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionController.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionWebApplication.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/main/resources/application.properties (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/main/resources/logback.xml (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java (100%) rename {spring-session => spring-security-modules/spring-session}/spring-session-redis/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java (100%) diff --git a/spring-session/README.md b/spring-security-modules/spring-session/README.md similarity index 100% rename from spring-session/README.md rename to spring-security-modules/spring-session/README.md diff --git a/spring-session/pom.xml b/spring-security-modules/spring-session/pom.xml similarity index 93% rename from spring-session/pom.xml rename to spring-security-modules/spring-session/pom.xml index 6616a0d1f3..ac10700240 100644 --- a/spring-session/pom.xml +++ b/spring-security-modules/spring-session/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-session/spring-session-jdbc/README.md b/spring-security-modules/spring-session/spring-session-jdbc/README.md similarity index 100% rename from spring-session/spring-session-jdbc/README.md rename to spring-security-modules/spring-session/spring-session-jdbc/README.md diff --git a/spring-session/spring-session-jdbc/pom.xml b/spring-security-modules/spring-session/spring-session-jdbc/pom.xml similarity index 95% rename from spring-session/spring-session-jdbc/pom.xml rename to spring-security-modules/spring-session/spring-session-jdbc/pom.xml index 64cdb4dd09..95c366fc2e 100644 --- a/spring-session/spring-session-jdbc/pom.xml +++ b/spring-security-modules/spring-session/spring-session-jdbc/pom.xml @@ -13,7 +13,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../../parent-boot-2 diff --git a/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/SpringSessionJdbcApplication.java b/spring-security-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/SpringSessionJdbcApplication.java similarity index 100% rename from spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/SpringSessionJdbcApplication.java rename to spring-security-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/SpringSessionJdbcApplication.java diff --git a/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java b/spring-security-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java similarity index 100% rename from spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java rename to spring-security-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java diff --git a/spring-session/spring-session-jdbc/src/main/resources/application.properties b/spring-security-modules/spring-session/spring-session-jdbc/src/main/resources/application.properties similarity index 100% rename from spring-session/spring-session-jdbc/src/main/resources/application.properties rename to spring-security-modules/spring-session/spring-session-jdbc/src/main/resources/application.properties diff --git a/spring-session/spring-session-jdbc/src/main/resources/logback.xml b/spring-security-modules/spring-session/spring-session-jdbc/src/main/resources/logback.xml similarity index 100% rename from spring-session/spring-session-jdbc/src/main/resources/logback.xml rename to spring-security-modules/spring-session/spring-session-jdbc/src/main/resources/logback.xml diff --git a/spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java b/spring-security-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java similarity index 100% rename from spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java rename to spring-security-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java diff --git a/spring-session/spring-session-mongodb/README.md b/spring-security-modules/spring-session/spring-session-mongodb/README.md similarity index 100% rename from spring-session/spring-session-mongodb/README.md rename to spring-security-modules/spring-session/spring-session-mongodb/README.md diff --git a/spring-session/spring-session-mongodb/pom.xml b/spring-security-modules/spring-session/spring-session-mongodb/pom.xml similarity index 96% rename from spring-session/spring-session-mongodb/pom.xml rename to spring-security-modules/spring-session/spring-session-mongodb/pom.xml index 10d4eb595e..82c8520356 100644 --- a/spring-session/spring-session-mongodb/pom.xml +++ b/spring-security-modules/spring-session/spring-session-mongodb/pom.xml @@ -13,7 +13,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../../parent-boot-2 diff --git a/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBApplication.java b/spring-security-modules/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBApplication.java similarity index 100% rename from spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBApplication.java rename to spring-security-modules/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBApplication.java diff --git a/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java b/spring-security-modules/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java similarity index 100% rename from spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java rename to spring-security-modules/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java diff --git a/spring-session/spring-session-mongodb/src/main/resources/application.properties b/spring-security-modules/spring-session/spring-session-mongodb/src/main/resources/application.properties similarity index 100% rename from spring-session/spring-session-mongodb/src/main/resources/application.properties rename to spring-security-modules/spring-session/spring-session-mongodb/src/main/resources/application.properties diff --git a/spring-session/spring-session-mongodb/src/main/resources/logback.xml b/spring-security-modules/spring-session/spring-session-mongodb/src/main/resources/logback.xml similarity index 100% rename from spring-session/spring-session-mongodb/src/main/resources/logback.xml rename to spring-security-modules/spring-session/spring-session-mongodb/src/main/resources/logback.xml diff --git a/spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java b/spring-security-modules/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java similarity index 100% rename from spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java rename to spring-security-modules/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java diff --git a/spring-session/spring-session-mongodb/src/test/resources/application.properties b/spring-security-modules/spring-session/spring-session-mongodb/src/test/resources/application.properties similarity index 100% rename from spring-session/spring-session-mongodb/src/test/resources/application.properties rename to spring-security-modules/spring-session/spring-session-mongodb/src/test/resources/application.properties diff --git a/spring-session/spring-session-redis/README.md b/spring-security-modules/spring-session/spring-session-redis/README.md similarity index 100% rename from spring-session/spring-session-redis/README.md rename to spring-security-modules/spring-session/spring-session-redis/README.md diff --git a/spring-session/spring-session-redis/pom.xml b/spring-security-modules/spring-session/spring-session-redis/pom.xml similarity index 96% rename from spring-session/spring-session-redis/pom.xml rename to spring-security-modules/spring-session/spring-session-redis/pom.xml index 8d225e06ed..36eb632e1c 100644 --- a/spring-session/spring-session-redis/pom.xml +++ b/spring-security-modules/spring-session/spring-session-redis/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../../parent-boot-2 diff --git a/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SecurityConfig.java b/spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SecurityConfig.java similarity index 100% rename from spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SecurityConfig.java rename to spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SecurityConfig.java diff --git a/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionController.java b/spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionController.java similarity index 100% rename from spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionController.java rename to spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionController.java diff --git a/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionWebApplication.java b/spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionWebApplication.java similarity index 100% rename from spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionWebApplication.java rename to spring-security-modules/spring-session/spring-session-redis/src/main/java/com/baeldung/spring/session/SessionWebApplication.java diff --git a/spring-session/spring-session-redis/src/main/resources/application.properties b/spring-security-modules/spring-session/spring-session-redis/src/main/resources/application.properties similarity index 100% rename from spring-session/spring-session-redis/src/main/resources/application.properties rename to spring-security-modules/spring-session/spring-session-redis/src/main/resources/application.properties diff --git a/spring-session/spring-session-redis/src/main/resources/logback.xml b/spring-security-modules/spring-session/spring-session-redis/src/main/resources/logback.xml similarity index 100% rename from spring-session/spring-session-redis/src/main/resources/logback.xml rename to spring-security-modules/spring-session/spring-session-redis/src/main/resources/logback.xml diff --git a/spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-security-modules/spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java similarity index 100% rename from spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java rename to spring-security-modules/spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java diff --git a/spring-session/spring-session-redis/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java b/spring-security-modules/spring-session/spring-session-redis/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java similarity index 100% rename from spring-session/spring-session-redis/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java rename to spring-security-modules/spring-session/spring-session-redis/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java From 49ae245cc2a8d93a23bcf2bc9a5b7132b50fbc00 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:44:25 +0530 Subject: [PATCH 376/590] JAVA-3506: moved spring-social-login inside spring-security-modules --- .../spring-social-login}/README.md | 0 .../spring-social-login}/pom.xml | 2 +- .../src/main/java/com/baeldung/config/Application.java | 0 .../src/main/java/com/baeldung/config/SecurityConfig.java | 0 .../src/main/java/com/baeldung/config/WebConfig.java | 0 .../main/java/com/baeldung/persistence/dao/UserRepository.java | 0 .../src/main/java/com/baeldung/persistence/model/User.java | 0 .../java/com/baeldung/security/FacebookConnectionSignup.java | 0 .../main/java/com/baeldung/security/FacebookSignInAdapter.java | 0 .../main/java/com/baeldung/security/MyUserDetailsService.java | 0 .../src/main/resources/application.properties | 0 .../spring-social-login}/src/main/resources/data.sql | 0 .../spring-social-login}/src/main/resources/logback.xml | 0 .../src/main/resources/templates/index.html | 0 .../src/main/resources/templates/login.html | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 16 files changed, 1 insertion(+), 1 deletion(-) rename {spring-social-login => spring-security-modules/spring-social-login}/README.md (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/pom.xml (97%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/config/Application.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/config/SecurityConfig.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/config/WebConfig.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/persistence/dao/UserRepository.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/security/FacebookConnectionSignup.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/security/FacebookSignInAdapter.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/java/com/baeldung/security/MyUserDetailsService.java (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/resources/application.properties (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/resources/data.sql (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/resources/logback.xml (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/resources/templates/index.html (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/main/resources/templates/login.html (100%) rename {spring-social-login => spring-security-modules/spring-social-login}/src/test/java/com/baeldung/SpringContextTest.java (100%) diff --git a/spring-social-login/README.md b/spring-security-modules/spring-social-login/README.md similarity index 100% rename from spring-social-login/README.md rename to spring-security-modules/spring-social-login/README.md diff --git a/spring-social-login/pom.xml b/spring-security-modules/spring-social-login/pom.xml similarity index 97% rename from spring-social-login/pom.xml rename to spring-security-modules/spring-social-login/pom.xml index 0de20cd087..209a546a5a 100644 --- a/spring-social-login/pom.xml +++ b/spring-security-modules/spring-social-login/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-social-login/src/main/java/com/baeldung/config/Application.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/Application.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/config/Application.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/Application.java diff --git a/spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java diff --git a/spring-social-login/src/main/java/com/baeldung/config/WebConfig.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/WebConfig.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/config/WebConfig.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/config/WebConfig.java diff --git a/spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java diff --git a/spring-social-login/src/main/java/com/baeldung/persistence/model/User.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/persistence/model/User.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java diff --git a/spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java diff --git a/spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java b/spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java similarity index 100% rename from spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java rename to spring-security-modules/spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java diff --git a/spring-social-login/src/main/resources/application.properties b/spring-security-modules/spring-social-login/src/main/resources/application.properties similarity index 100% rename from spring-social-login/src/main/resources/application.properties rename to spring-security-modules/spring-social-login/src/main/resources/application.properties diff --git a/spring-social-login/src/main/resources/data.sql b/spring-security-modules/spring-social-login/src/main/resources/data.sql similarity index 100% rename from spring-social-login/src/main/resources/data.sql rename to spring-security-modules/spring-social-login/src/main/resources/data.sql diff --git a/spring-social-login/src/main/resources/logback.xml b/spring-security-modules/spring-social-login/src/main/resources/logback.xml similarity index 100% rename from spring-social-login/src/main/resources/logback.xml rename to spring-security-modules/spring-social-login/src/main/resources/logback.xml diff --git a/spring-social-login/src/main/resources/templates/index.html b/spring-security-modules/spring-social-login/src/main/resources/templates/index.html similarity index 100% rename from spring-social-login/src/main/resources/templates/index.html rename to spring-security-modules/spring-social-login/src/main/resources/templates/index.html diff --git a/spring-social-login/src/main/resources/templates/login.html b/spring-security-modules/spring-social-login/src/main/resources/templates/login.html similarity index 100% rename from spring-social-login/src/main/resources/templates/login.html rename to spring-security-modules/spring-social-login/src/main/resources/templates/login.html diff --git a/spring-social-login/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-social-login/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-social-login/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-social-login/src/test/java/com/baeldung/SpringContextTest.java From 0513c0b64d052e1a7dc57f5f30e85b0ecb32c5bc Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 25 Dec 2020 22:45:16 +0530 Subject: [PATCH 377/590] JAVA-3506: added modules to new parent's pom --- spring-security-modules/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index e32fadd671..99dea4bc67 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -14,6 +14,10 @@ + spring-ldap + spring-5-security + spring-5-security-cognito + spring-5-security-oauth spring-security-acl spring-security-auth0 spring-security-web-angular/server @@ -38,6 +42,8 @@ spring-security-oauth2-sso spring-security-web-thymeleaf spring-security-web-x509 + spring-session + spring-social-login From d44dacaa2b69659b1d257229650c2c7598c09761 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Sat, 26 Dec 2020 06:14:52 +0530 Subject: [PATCH 378/590] Removed unwanted method --- .../java/com/baeldung/spring/transaction/CourseService.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 1478c5bd1d..21f947a925 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -31,8 +31,4 @@ public class CourseService { } } - public Course findById(Long id) { - return courseDao.findOne(id); - } - } From 698185a55b56a516bb21ce12567bdf427c974a35 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 26 Dec 2020 10:22:35 +0200 Subject: [PATCH 379/590] remove files left after move --- .../spring-boot-libraries/pom.xml | 1 - .../src/main/resources/graphql/blog.graphqls | 24 --- ...GraphQL collection.postman_collection.json | 169 ------------------ 3 files changed, 194 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/resources/graphql/blog.graphqls delete mode 100644 spring-boot-modules/spring-boot/src/test/resources/GraphQL collection.postman_collection.json diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index 3913babaa8..cec035cf93 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -6,7 +6,6 @@ spring-boot-libraries spring-boot-libraries war - This is simple boot application for Spring boot actuator test com.baeldung.spring-boot-modules diff --git a/spring-boot-modules/spring-boot/src/main/resources/graphql/blog.graphqls b/spring-boot-modules/spring-boot/src/main/resources/graphql/blog.graphqls deleted file mode 100644 index aa0c8757e9..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/graphql/blog.graphqls +++ /dev/null @@ -1,24 +0,0 @@ -type Post { - id: ID! - title: String! - text: String! - category: String - author: Author -} - -type Author { - id: ID! - name: String! - thumbnail: String - posts: [Post]! -} - -# The Root Query for the application -type Query { - recentPosts(count: Int, offset: Int): [Post]! -} - -# The Root Mutation for the application -type Mutation { - writePost(title: String!, text: String!, category: String, author: String!) : Post! -} diff --git a/spring-boot-modules/spring-boot/src/test/resources/GraphQL collection.postman_collection.json b/spring-boot-modules/spring-boot/src/test/resources/GraphQL collection.postman_collection.json deleted file mode 100644 index f19bc1febb..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/GraphQL collection.postman_collection.json +++ /dev/null @@ -1,169 +0,0 @@ -{ - "info": { - "_postman_id": "910d9690-f629-4491-bbbd-adb30982a386", - "name": "GraphQL collection", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "mutations", - "item": [ - { - "name": "writePost", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "graphql", - "graphql": { - "query": "mutation writePost ($title: String!, $text: String!, $category: String) {\n writePost (title: $title, text: $text, category: $category) {\n id\n title\n text\n category\n }\n}", - "variables": "{\n \"title\": \"\",\n \"text\": \"\",\n \"category\": \"\"\n}" - }, - "options": { - "graphql": {} - } - }, - "url": { - "raw": "http://localhost:9090/springbootapp/graphql", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "9090", - "path": [ - "springbootapp", - "graphql" - ] - } - }, - "response": [] - } - ], - "protocolProfileBehavior": {} - }, - { - "name": "queries", - "item": [ - { - "name": "get recent posts", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "graphql", - "graphql": { - "query": "{\r\n recentPosts(count: 10, offset: 0) {\r\n id\r\n title\r\n category\r\n text\r\n author {\r\n id\r\n name\r\n thumbnail\r\n }\r\n }\r\n}", - "variables": "" - } - }, - "url": { - "raw": "http://localhost:9090/springbootapp/graphql", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "9090", - "path": [ - "springbootapp", - "graphql" - ] - } - }, - "response": [] - }, - { - "name": "recentPosts - variables", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "graphql", - "graphql": { - "query": "query recentPosts ($count: Int, $offset: Int) {\n recentPosts (count: $count, offset: $offset) {\n id\n title\n text\n category\n }\n}", - "variables": "{\n \"count\": 1,\n \"offset\": 0\n}" - }, - "options": { - "graphql": {} - } - }, - "url": { - "raw": "http://localhost:9090/springbootapp/graphql", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "9090", - "path": [ - "springbootapp", - "graphql" - ] - } - }, - "response": [] - }, - { - "name": "get recent posts - raw", - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/graphql", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "query {\r\n recentPosts(count: 10, offset: 0) {\r\n id\r\n title\r\n category\r\n author {\r\n id\r\n name\r\n thumbnail\r\n }\r\n }\r\n}" - }, - "url": { - "raw": "http://localhost:9090/springbootapp/graphql", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "9090", - "path": [ - "springbootapp", - "graphql" - ] - } - }, - "response": [] - } - ], - "protocolProfileBehavior": {} - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "id": "b54f267b-c450-4f2d-8105-2f23bab4c922", - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "id": "00b575be-03d4-4b29-b137-733ead139638", - "type": "text/javascript", - "exec": [ - "" - ] - } - } - ], - "variable": [ - { - "id": "20a274e5-6d51-40d6-81cb-af9eb115b21b", - "key": "url", - "value": "", - "type": "string" - } - ], - "protocolProfileBehavior": {} -} \ No newline at end of file From fa02e7b10403b51902036dff9ed119fc75d2818c Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 27 Dec 2020 12:16:48 +0530 Subject: [PATCH 380/590] JAVA-3522: Moved spring-mvc-crash inside spring-web-modules --- .../spring-mvc-crash}/.gitignore | 0 .../spring-mvc-crash}/README.md | 0 .../spring-mvc-crash}/pom.xml | 4 ++-- .../src/main/java/com/baeldung/spring/ClientWebConfig.java | 0 .../main/java/com/baeldung/spring/ClientWebConfigJava.java | 0 .../com/baeldung/spring/controller/WelcomeController.java | 0 .../src/main/resources/contentManagementWebMvcConfig.xml | 0 .../spring-mvc-crash}/src/main/resources/logback.xml | 0 .../spring-mvc-crash}/src/main/resources/messages.properties | 0 .../spring-mvc-crash}/src/main/resources/webMvcConfig.xml | 0 .../src/main/webapp/WEB-INF/crash/commands/message.groovy | 0 .../src/main/webapp/WEB-INF/crash/commands/message2.java | 0 .../src/main/webapp/WEB-INF/crash/crash.properties | 0 .../src/main/webapp/WEB-INF/crash/telnet.properties | 0 .../spring-mvc-crash}/src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../spring-mvc-crash}/src/main/webapp/WEB-INF/view/error.jsp | 0 .../src/main/webapp/WEB-INF/view/errorPage.jsp | 0 .../src/main/webapp/WEB-INF/view/welcome.jsp | 0 .../spring-mvc-crash}/src/main/webapp/WEB-INF/web.xml | 0 .../spring-mvc-crash}/src/main/webapp/index.jsp | 0 .../spring-mvc-crash}/src/main/webapp/jsp/ExampleThree.jsp | 0 .../spring-mvc-crash}/src/main/webapp/jsp/ExampleTwo.jsp | 0 .../spring-mvc-crash}/src/main/webapp/jsp/index.jsp | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 24 files changed, 2 insertions(+), 2 deletions(-) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/.gitignore (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/README.md (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/pom.xml (98%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/java/com/baeldung/spring/ClientWebConfig.java (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/java/com/baeldung/spring/ClientWebConfigJava.java (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/java/com/baeldung/spring/controller/WelcomeController.java (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/resources/contentManagementWebMvcConfig.xml (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/resources/logback.xml (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/resources/messages.properties (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/resources/webMvcConfig.xml (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/crash/commands/message.groovy (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/crash/commands/message2.java (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/crash/crash.properties (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/crash/telnet.properties (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/view/error.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/view/errorPage.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/view/welcome.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/index.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/jsp/ExampleThree.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/jsp/ExampleTwo.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/main/webapp/jsp/index.jsp (100%) rename {spring-mvc-crash => spring-web-modules/spring-mvc-crash}/src/test/java/com/baeldung/SpringContextTest.java (100%) diff --git a/spring-mvc-crash/.gitignore b/spring-web-modules/spring-mvc-crash/.gitignore similarity index 100% rename from spring-mvc-crash/.gitignore rename to spring-web-modules/spring-mvc-crash/.gitignore diff --git a/spring-mvc-crash/README.md b/spring-web-modules/spring-mvc-crash/README.md similarity index 100% rename from spring-mvc-crash/README.md rename to spring-web-modules/spring-mvc-crash/README.md diff --git a/spring-mvc-crash/pom.xml b/spring-web-modules/spring-mvc-crash/pom.xml similarity index 98% rename from spring-mvc-crash/pom.xml rename to spring-web-modules/spring-mvc-crash/pom.xml index 8a902d4937..9a0d97bae9 100644 --- a/spring-mvc-crash/pom.xml +++ b/spring-web-modules/spring-mvc-crash/pom.xml @@ -10,8 +10,8 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + spring-web-modules + 0.0.1-SNAPSHOT diff --git a/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfig.java b/spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfig.java similarity index 100% rename from spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfig.java rename to spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfig.java diff --git a/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfigJava.java b/spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfigJava.java similarity index 100% rename from spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfigJava.java rename to spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/ClientWebConfigJava.java diff --git a/spring-mvc-crash/src/main/java/com/baeldung/spring/controller/WelcomeController.java b/spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/controller/WelcomeController.java similarity index 100% rename from spring-mvc-crash/src/main/java/com/baeldung/spring/controller/WelcomeController.java rename to spring-web-modules/spring-mvc-crash/src/main/java/com/baeldung/spring/controller/WelcomeController.java diff --git a/spring-mvc-crash/src/main/resources/contentManagementWebMvcConfig.xml b/spring-web-modules/spring-mvc-crash/src/main/resources/contentManagementWebMvcConfig.xml similarity index 100% rename from spring-mvc-crash/src/main/resources/contentManagementWebMvcConfig.xml rename to spring-web-modules/spring-mvc-crash/src/main/resources/contentManagementWebMvcConfig.xml diff --git a/spring-mvc-crash/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-crash/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-crash/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-crash/src/main/resources/logback.xml diff --git a/spring-mvc-crash/src/main/resources/messages.properties b/spring-web-modules/spring-mvc-crash/src/main/resources/messages.properties similarity index 100% rename from spring-mvc-crash/src/main/resources/messages.properties rename to spring-web-modules/spring-mvc-crash/src/main/resources/messages.properties diff --git a/spring-mvc-crash/src/main/resources/webMvcConfig.xml b/spring-web-modules/spring-mvc-crash/src/main/resources/webMvcConfig.xml similarity index 100% rename from spring-mvc-crash/src/main/resources/webMvcConfig.xml rename to spring-web-modules/spring-mvc-crash/src/main/resources/webMvcConfig.xml diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message.groovy b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message.groovy similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message.groovy rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message.groovy diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message2.java b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message2.java similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message2.java rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/commands/message2.java diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/crash/crash.properties b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/crash.properties similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/crash/crash.properties rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/crash.properties diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/crash/telnet.properties b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/telnet.properties similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/crash/telnet.properties rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/crash/telnet.properties diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/view/error.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/error.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/view/error.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/error.jsp diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/view/errorPage.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/errorPage.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/view/errorPage.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/errorPage.jsp diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/welcome.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/view/welcome.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/view/welcome.jsp diff --git a/spring-mvc-crash/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-mvc-crash/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-mvc-crash/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-crash/src/main/webapp/index.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/index.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/index.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/index.jsp diff --git a/spring-mvc-crash/src/main/webapp/jsp/ExampleThree.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/ExampleThree.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/jsp/ExampleThree.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/ExampleThree.jsp diff --git a/spring-mvc-crash/src/main/webapp/jsp/ExampleTwo.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/ExampleTwo.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/jsp/ExampleTwo.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/ExampleTwo.jsp diff --git a/spring-mvc-crash/src/main/webapp/jsp/index.jsp b/spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/index.jsp similarity index 100% rename from spring-mvc-crash/src/main/webapp/jsp/index.jsp rename to spring-web-modules/spring-mvc-crash/src/main/webapp/jsp/index.jsp diff --git a/spring-mvc-crash/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-crash/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-crash/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-crash/src/test/java/com/baeldung/SpringContextTest.java From 50b03440ea5c09e4707870caa67c8bd029870387 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 27 Dec 2020 12:17:36 +0530 Subject: [PATCH 381/590] JAVA-3522: Moved spring-mvc-forms-jsp to spring-web-modules --- .../spring-mvc-forms-jsp}/README.md | 0 .../spring-mvc-forms-jsp}/pom.xml | 2 +- .../main/java/com/baeldung/jstl/bundles/CustomMessage_en.java | 0 .../java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java | 0 .../main/java/com/baeldung/jstl/controllers/JSTLController.java | 0 .../src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java | 0 .../springmvcforms/configuration/ApplicationConfiguration.java | 0 .../baeldung/springmvcforms/configuration/WebInitializer.java | 0 .../baeldung/springmvcforms/controller/CustomerController.java | 0 .../baeldung/springmvcforms/controller/EmployeeController.java | 0 .../springmvcforms/controller/FileUploadController.java | 0 .../com/baeldung/springmvcforms/controller/UserController.java | 0 .../main/java/com/baeldung/springmvcforms/domain/Customer.java | 0 .../main/java/com/baeldung/springmvcforms/domain/Employee.java | 0 .../src/main/java/com/baeldung/springmvcforms/domain/User.java | 0 .../springmvcforms/interceptor/FileUploadExceptionAdvice.java | 0 .../baeldung/springmvcforms/validator/CustomerValidator.java | 0 .../spring-mvc-forms-jsp}/src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/html/user.html | 0 .../spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/items.xsl | 0 .../src/main/webapp/WEB-INF/views/core_tags.jsp | 0 .../src/main/webapp/WEB-INF/views/core_tags_redirect.jsp | 0 .../src/main/webapp/WEB-INF/views/customerHome.jsp | 0 .../src/main/webapp/WEB-INF/views/customerView.jsp | 0 .../src/main/webapp/WEB-INF/views/employeeHome.jsp | 0 .../src/main/webapp/WEB-INF/views/employeeView.jsp | 0 .../src/main/webapp/WEB-INF/views/error.jsp | 0 .../src/main/webapp/WEB-INF/views/file.jsp | 0 .../src/main/webapp/WEB-INF/views/formatting_tags.jsp | 0 .../src/main/webapp/WEB-INF/views/function_tags.jsp | 0 .../src/main/webapp/WEB-INF/views/sql_tags.jsp | 0 .../src/main/webapp/WEB-INF/views/xml_tags.jsp | 0 .../spring-mvc-forms-jsp}/src/main/webapp/css/user.css | 0 .../spring-mvc-forms-jsp}/src/main/webapp/js/app.js | 0 .../src/test/java/com}/baeldung/SpringContextTest.java | 0 35 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/README.md (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/pom.xml (98%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/jstl/bundles/CustomMessage_en.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/jstl/controllers/JSTLController.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/configuration/ApplicationConfiguration.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/controller/FileUploadController.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/controller/UserController.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/domain/Customer.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/domain/Employee.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/domain/User.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/interceptor/FileUploadExceptionAdvice.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/java/com/baeldung/springmvcforms/validator/CustomerValidator.java (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/resources/logback.xml (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/html/user.html (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/items.xsl (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/core_tags.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/core_tags_redirect.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/customerHome.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/customerView.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/employeeHome.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/employeeView.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/error.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/file.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/formatting_tags.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/function_tags.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/sql_tags.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/WEB-INF/views/xml_tags.jsp (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/css/user.css (100%) rename {spring-mvc-forms-jsp => spring-web-modules/spring-mvc-forms-jsp}/src/main/webapp/js/app.js (100%) rename {spring-mvc-forms-jsp/src/test/java/org => spring-web-modules/spring-mvc-forms-jsp/src/test/java/com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-mvc-forms-jsp/README.md b/spring-web-modules/spring-mvc-forms-jsp/README.md similarity index 100% rename from spring-mvc-forms-jsp/README.md rename to spring-web-modules/spring-mvc-forms-jsp/README.md diff --git a/spring-mvc-forms-jsp/pom.xml b/spring-web-modules/spring-mvc-forms-jsp/pom.xml similarity index 98% rename from spring-mvc-forms-jsp/pom.xml rename to spring-web-modules/spring-mvc-forms-jsp/pom.xml index 4e1c2516f6..aba16236da 100644 --- a/spring-mvc-forms-jsp/pom.xml +++ b/spring-web-modules/spring-mvc-forms-jsp/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-5 0.0.1-SNAPSHOT - ../parent-spring-5 + ../../parent-spring-5 diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_en.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_en.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_en.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_en.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/bundles/CustomMessage_fr_FR.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/controllers/JSTLController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/controllers/JSTLController.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/controllers/JSTLController.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/controllers/JSTLController.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/jstl/dbaccess/SQLConnection.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/ApplicationConfiguration.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/ApplicationConfiguration.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/ApplicationConfiguration.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/ApplicationConfiguration.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/FileUploadController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/FileUploadController.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/FileUploadController.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/FileUploadController.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Customer.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Customer.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Customer.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Customer.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/interceptor/FileUploadExceptionAdvice.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/interceptor/FileUploadExceptionAdvice.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/interceptor/FileUploadExceptionAdvice.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/interceptor/FileUploadExceptionAdvice.java diff --git a/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/validator/CustomerValidator.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/validator/CustomerValidator.java similarity index 100% rename from spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/validator/CustomerValidator.java rename to spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/validator/CustomerValidator.java diff --git a/spring-mvc-forms-jsp/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-forms-jsp/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-forms-jsp/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-forms-jsp/src/main/resources/logback.xml diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/html/user.html b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/html/user.html similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/html/user.html rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/html/user.html diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/items.xsl b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/items.xsl similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/items.xsl rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/items.xsl diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags_redirect.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags_redirect.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags_redirect.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/core_tags_redirect.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerHome.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerHome.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerHome.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerHome.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerView.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerView.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerView.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/customerView.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeView.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeView.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeView.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeView.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/error.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/error.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/error.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/error.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/file.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/file.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/file.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/file.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/formatting_tags.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/formatting_tags.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/formatting_tags.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/formatting_tags.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/function_tags.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/function_tags.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/function_tags.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/function_tags.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/sql_tags.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/sql_tags.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/sql_tags.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/sql_tags.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/xml_tags.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/xml_tags.jsp similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/xml_tags.jsp rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/xml_tags.jsp diff --git a/spring-mvc-forms-jsp/src/main/webapp/css/user.css b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/css/user.css similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/css/user.css rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/css/user.css diff --git a/spring-mvc-forms-jsp/src/main/webapp/js/app.js b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/js/app.js similarity index 100% rename from spring-mvc-forms-jsp/src/main/webapp/js/app.js rename to spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/js/app.js diff --git a/spring-mvc-forms-jsp/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-forms-jsp/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-forms-jsp/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-forms-jsp/src/test/java/com/baeldung/SpringContextTest.java From 950ec2f8df4dae6919ded9462c7ef42d6385d196 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 27 Dec 2020 12:18:06 +0530 Subject: [PATCH 382/590] JAVA-3522: Added modules to new parent's pom --- spring-web-modules/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index bf6fda09f4..b957b46afa 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -18,6 +18,8 @@ spring-mvc-basics-2 spring-mvc-basics-3 spring-mvc-basics-4 + spring-mvc-crash + spring-mvc-forms-jsp From 8ab0faa372a941186da10782d3b95f87f2d42aec Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 27 Dec 2020 12:19:07 +0530 Subject: [PATCH 383/590] JAVA-3522: removed modules from main pom --- pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pom.xml b/pom.xml index a28089e05a..c37992df44 100644 --- a/pom.xml +++ b/pom.xml @@ -658,7 +658,6 @@ spring-mobile spring-mockito - spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 @@ -1133,7 +1132,6 @@ spring-mobile spring-mockito - spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 @@ -1142,7 +1140,6 @@ spring-mvc-views spring-mvc-webflow spring-mvc-xml - spring-mvc-crash spring-protobuf spring-quartz From 8fc0ea77cccbef74a06abbe003c5b2c3851a42f8 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 27 Dec 2020 12:59:42 +0100 Subject: [PATCH 384/590] JAVA-3543: Move spring-thymeleaf into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-thymeleaf}/README.md | 0 .../spring-thymeleaf}/pom.xml | 2 +- .../main/java/com/baeldung/thymeleaf/config/InitSecurity.java | 0 .../src/main/java/com/baeldung/thymeleaf/config/WebApp.java | 0 .../main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java | 0 .../main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java | 0 .../java/com/baeldung/thymeleaf/controller/BookController.java | 0 .../java/com/baeldung/thymeleaf/controller/DatesController.java | 0 .../controller/ExpressionUtilityObjectsController.java | 0 .../com/baeldung/thymeleaf/controller/FragmentsController.java | 0 .../java/com/baeldung/thymeleaf/controller/HomeController.java | 0 .../com/baeldung/thymeleaf/controller/InliningController.java | 0 .../baeldung/thymeleaf/controller/LayoutDialectController.java | 0 .../com/baeldung/thymeleaf/controller/StudentController.java | 0 .../com/baeldung/thymeleaf/controller/TeacherController.java | 0 .../java/com/baeldung/thymeleaf/formatter/NameFormatter.java | 0 .../src/main/java/com/baeldung/thymeleaf/model/Book.java | 0 .../src/main/java/com/baeldung/thymeleaf/model/Student.java | 0 .../src/main/java/com/baeldung/thymeleaf/model/Teacher.java | 0 .../main/java/com/baeldung/thymeleaf/service/BookService.java | 0 .../src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java | 0 .../src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java | 0 .../main/java/com/baeldung/thymeleaf/utils/StudentUtils.java | 0 .../main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java | 0 .../spring-thymeleaf}/src/main/resources/logback.xml | 0 .../spring-thymeleaf}/src/main/resources/messages_en.properties | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/css/styles.css | 0 .../src/main/webapp/WEB-INF/js/studentCheck.js | 0 .../src/main/webapp/WEB-INF/txt/studentsList.txt | 0 .../src/main/webapp/WEB-INF/views/addStudent.html | 0 .../src/main/webapp/WEB-INF/views/content.html | 0 .../src/main/webapp/WEB-INF/views/csrfAttack.html | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/views/dates.html | 0 .../src/main/webapp/WEB-INF/views/fragments.html | 0 .../src/main/webapp/WEB-INF/views/fragments/forms.html | 0 .../src/main/webapp/WEB-INF/views/fragments/general.html | 0 .../src/main/webapp/WEB-INF/views/fragments/menus.html | 0 .../src/main/webapp/WEB-INF/views/fragments/subtitle.html | 0 .../src/main/webapp/WEB-INF/views/fragments/tables.html | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/views/home.html | 0 .../src/main/webapp/WEB-INF/views/inliningExample.html | 0 .../src/main/webapp/WEB-INF/views/listBooks.html | 0 .../src/main/webapp/WEB-INF/views/listStudents.html | 0 .../src/main/webapp/WEB-INF/views/listTeachers.html | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/views/markup.html | 0 .../src/main/webapp/WEB-INF/views/objects.html | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/views/other.html | 0 .../spring-thymeleaf}/src/main/webapp/WEB-INF/views/params.html | 0 .../src/main/webapp/WEB-INF/views/template.html | 0 .../src/test/java/com/baeldung/thymeleaf/SpringContextTest.java | 0 .../ExpressionUtilityObjectsControllerIntegrationTest.java | 0 .../baeldung/thymeleaf/controller/FragmentsIntegrationTest.java | 0 .../controller/LayoutDialectControllerIntegrationTest.java | 0 .../thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java | 0 56 files changed, 2 insertions(+), 3 deletions(-) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/README.md (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/pom.xml (99%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/config/InitSecurity.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/config/WebApp.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/BookController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/DatesController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/InliningController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/controller/TeacherController.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/model/Book.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/model/Student.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/model/Teacher.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/service/BookService.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/utils/StudentUtils.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/resources/logback.xml (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/resources/messages_en.properties (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/css/styles.css (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/js/studentCheck.js (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/txt/studentsList.txt (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/addStudent.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/content.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/csrfAttack.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/dates.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments/forms.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments/general.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments/menus.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments/subtitle.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/fragments/tables.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/home.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/inliningExample.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/listBooks.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/listStudents.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/listTeachers.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/markup.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/objects.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/other.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/params.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/main/webapp/WEB-INF/views/template.html (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/test/java/com/baeldung/thymeleaf/SpringContextTest.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java (100%) rename {spring-thymeleaf => spring-web-modules/spring-thymeleaf}/src/test/java/com/baeldung/thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index a28089e05a..86de8a389c 100644 --- a/pom.xml +++ b/pom.xml @@ -695,7 +695,6 @@ spring-swagger-codegen spring-threads - spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 @@ -1169,7 +1168,6 @@ spring-static-resources spring-swagger-codegen - spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index bf6fda09f4..bda3edda6a 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -18,6 +18,7 @@ spring-mvc-basics-2 spring-mvc-basics-3 spring-mvc-basics-4 + spring-thymeleaf diff --git a/spring-thymeleaf/README.md b/spring-web-modules/spring-thymeleaf/README.md similarity index 100% rename from spring-thymeleaf/README.md rename to spring-web-modules/spring-thymeleaf/README.md diff --git a/spring-thymeleaf/pom.xml b/spring-web-modules/spring-thymeleaf/pom.xml similarity index 99% rename from spring-thymeleaf/pom.xml rename to spring-web-modules/spring-thymeleaf/pom.xml index 30f77dd73e..7b0cd2c510 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-web-modules/spring-thymeleaf/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-5 0.0.1-SNAPSHOT - ../parent-spring-5 + ../../parent-spring-5 diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/InitSecurity.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/InitSecurity.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/InitSecurity.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/InitSecurity.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/DatesController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/DatesController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/DatesController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/DatesController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/InliningController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/InliningController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/InliningController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/InliningController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/TeacherController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/TeacherController.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/TeacherController.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/TeacherController.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Book.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Book.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Book.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Book.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Teacher.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Teacher.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Teacher.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Teacher.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/service/BookService.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/service/BookService.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/service/BookService.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/service/BookService.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/ArrayUtil.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/BookUtils.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/StudentUtils.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/StudentUtils.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/StudentUtils.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/StudentUtils.java diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java similarity index 100% rename from spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java rename to spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/utils/TeacherUtils.java diff --git a/spring-thymeleaf/src/main/resources/logback.xml b/spring-web-modules/spring-thymeleaf/src/main/resources/logback.xml similarity index 100% rename from spring-thymeleaf/src/main/resources/logback.xml rename to spring-web-modules/spring-thymeleaf/src/main/resources/logback.xml diff --git a/spring-thymeleaf/src/main/resources/messages_en.properties b/spring-web-modules/spring-thymeleaf/src/main/resources/messages_en.properties similarity index 100% rename from spring-thymeleaf/src/main/resources/messages_en.properties rename to spring-web-modules/spring-thymeleaf/src/main/resources/messages_en.properties diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/js/studentCheck.js b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/studentCheck.js similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/js/studentCheck.js rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/studentCheck.js diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/txt/studentsList.txt b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/txt/studentsList.txt similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/txt/studentsList.txt rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/txt/studentsList.txt diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/csrfAttack.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/csrfAttack.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/csrfAttack.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/csrfAttack.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/dates.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/dates.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/dates.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/dates.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/home.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/home.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/home.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/home.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/inliningExample.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/inliningExample.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/inliningExample.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/inliningExample.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listBooks.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listBooks.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/listBooks.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listBooks.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listTeachers.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listTeachers.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/listTeachers.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/listTeachers.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/template.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/template.html similarity index 100% rename from spring-thymeleaf/src/main/webapp/WEB-INF/views/template.html rename to spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/template.html diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/SpringContextTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/SpringContextTest.java similarity index 100% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/SpringContextTest.java rename to spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/SpringContextTest.java diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java similarity index 100% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java rename to spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java similarity index 100% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java rename to spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/security/csrf/CsrfEnabledIntegrationTest.java From eb8724a0d71eecef9530ff157ba264674a8d6ec5 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 28 Dec 2020 12:10:31 +0100 Subject: [PATCH 385/590] JAVA-3544: Move spring-thymeleaf-2 into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-thymeleaf-2}/README.md | 0 .../spring-thymeleaf-2}/pom.xml | 2 +- .../src/main/java/com/baeldung/thymeleaf/Application.java | 0 .../src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java | 0 .../com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java | 0 .../booleanexpressions/BooleanExpressionsController.java | 0 .../src/main/java/com/baeldung/thymeleaf/customhtml/Course.java | 0 .../thymeleaf/customhtml/CourseRegistrationController.java | 0 .../src/main/java/com/baeldung/thymeleaf/enums/Color.java | 0 .../src/main/java/com/baeldung/thymeleaf/enums/Widget.java | 0 .../java/com/baeldung/thymeleaf/enums/WidgetController.java | 0 .../main/java/com/baeldung/thymeleaf/lists/ListsController.java | 0 .../main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java | 0 .../java/com/baeldung/thymeleaf/mvcdata/EmailController.java | 0 .../com/baeldung/thymeleaf/mvcdata/repository/EmailData.java | 0 .../main/java/com/baeldung/thymeleaf/pathvariables/Detail.java | 0 .../main/java/com/baeldung/thymeleaf/pathvariables/Item.java | 0 .../thymeleaf/pathvariables/PathVariablesController.java | 0 .../thymeleaf/requestparameters/ParticipantController.java | 0 .../com/baeldung/thymeleaf/templatedir/HelloController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/templates-2/hello.html | 0 .../src/main/resources/templates-2/participants.html | 0 .../src/main/resources/templates/booleans.html | 0 .../src/main/resources/templates/continents.html | 0 .../src/main/resources/templates/courseRegistration.html | 0 .../src/main/resources/templates/enums/new.html | 0 .../src/main/resources/templates/enums/view.html | 0 .../src/main/resources/templates/lists/contains.html | 0 .../src/main/resources/templates/lists/isEmpty.html | 0 .../src/main/resources/templates/lists/size.html | 0 .../src/main/resources/templates/lists/sort.html | 0 .../src/main/resources/templates/lists/toList.html | 0 .../src/main/resources/templates/mvcdata/email-bean-data.html | 0 .../resources/templates/mvcdata/email-model-attributes.html | 0 .../resources/templates/mvcdata/email-request-parameters.html | 0 .../main/resources/templates/mvcdata/email-servlet-context.html | 0 .../resources/templates/mvcdata/email-session-attributes.html | 0 .../src/main/resources/templates/pathvariables/index.html | 0 .../src/main/resources/templates/pathvariables/view.html | 0 .../thymeleaf/lists/ListsControllerIntegrationTest.java | 0 .../com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java | 0 44 files changed, 2 insertions(+), 3 deletions(-) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/README.md (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/pom.xml (97%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/Application.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/booleanexpressions/BooleanExpressionsController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/customhtml/Course.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/customhtml/CourseRegistrationController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/enums/Color.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/enums/Widget.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/lists/ListsController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/mvcdata/EmailController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/mvcdata/repository/EmailData.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/pathvariables/Detail.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/pathvariables/Item.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/pathvariables/PathVariablesController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/requestparameters/ParticipantController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/java/com/baeldung/thymeleaf/templatedir/HelloController.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/application.properties (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates-2/hello.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates-2/participants.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/booleans.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/continents.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/courseRegistration.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/enums/new.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/enums/view.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/lists/contains.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/lists/isEmpty.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/lists/size.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/lists/sort.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/lists/toList.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/mvcdata/email-bean-data.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/mvcdata/email-model-attributes.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/mvcdata/email-request-parameters.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/mvcdata/email-servlet-context.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/mvcdata/email-session-attributes.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/pathvariables/index.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/main/resources/templates/pathvariables/view.html (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/test/java/com/baeldung/thymeleaf/lists/ListsControllerIntegrationTest.java (100%) rename {spring-thymeleaf-2 => spring-web-modules/spring-thymeleaf-2}/src/test/java/com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java (100%) diff --git a/pom.xml b/pom.xml index 204b873c58..f66433c612 100644 --- a/pom.xml +++ b/pom.xml @@ -694,7 +694,6 @@ spring-swagger-codegen spring-threads - spring-thymeleaf-2 spring-thymeleaf-3 spring-vault @@ -1165,7 +1164,6 @@ spring-static-resources spring-swagger-codegen - spring-thymeleaf-2 spring-thymeleaf-3 spring-vault diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c1a85188d2..910af6a1bc 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,7 @@ spring-mvc-crash spring-mvc-forms-jsp spring-thymeleaf + spring-thymeleaf-2 diff --git a/spring-thymeleaf-2/README.md b/spring-web-modules/spring-thymeleaf-2/README.md similarity index 100% rename from spring-thymeleaf-2/README.md rename to spring-web-modules/spring-thymeleaf-2/README.md diff --git a/spring-thymeleaf-2/pom.xml b/spring-web-modules/spring-thymeleaf-2/pom.xml similarity index 97% rename from spring-thymeleaf-2/pom.xml rename to spring-web-modules/spring-thymeleaf-2/pom.xml index 43f36d9887..ddcd1e1005 100644 --- a/spring-thymeleaf-2/pom.xml +++ b/spring-web-modules/spring-thymeleaf-2/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/ThymeleafConfig.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/arrays/ThymeleafArrayController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/booleanexpressions/BooleanExpressionsController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/booleanexpressions/BooleanExpressionsController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/booleanexpressions/BooleanExpressionsController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/booleanexpressions/BooleanExpressionsController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/Course.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/Course.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/Course.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/Course.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/CourseRegistrationController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/CourseRegistrationController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/CourseRegistrationController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/customhtml/CourseRegistrationController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/lists/ListsController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/lists/ListsController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/lists/ListsController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/lists/ListsController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/BeanConfig.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/EmailController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/EmailController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/EmailController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/EmailController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/repository/EmailData.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/repository/EmailData.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/repository/EmailData.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/mvcdata/repository/EmailData.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Detail.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Detail.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Detail.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Detail.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Item.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Item.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Item.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/Item.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/PathVariablesController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/PathVariablesController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/PathVariablesController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/pathvariables/PathVariablesController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/requestparameters/ParticipantController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/requestparameters/ParticipantController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/requestparameters/ParticipantController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/requestparameters/ParticipantController.java diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/templatedir/HelloController.java b/spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/templatedir/HelloController.java similarity index 100% rename from spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/templatedir/HelloController.java rename to spring-web-modules/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/templatedir/HelloController.java diff --git a/spring-thymeleaf-2/src/main/resources/application.properties b/spring-web-modules/spring-thymeleaf-2/src/main/resources/application.properties similarity index 100% rename from spring-thymeleaf-2/src/main/resources/application.properties rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/application.properties diff --git a/spring-thymeleaf-2/src/main/resources/templates-2/hello.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates-2/hello.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates-2/hello.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates-2/hello.html diff --git a/spring-thymeleaf-2/src/main/resources/templates-2/participants.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates-2/participants.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates-2/participants.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates-2/participants.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/booleans.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/booleans.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/booleans.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/booleans.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/continents.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/continents.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/continents.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/continents.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/courseRegistration.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/courseRegistration.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/courseRegistration.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/courseRegistration.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/enums/new.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/enums/new.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/enums/new.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/enums/new.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/enums/view.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/enums/view.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/enums/view.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/enums/view.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/lists/contains.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/contains.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/lists/contains.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/contains.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/lists/isEmpty.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/isEmpty.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/lists/isEmpty.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/isEmpty.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/lists/size.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/size.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/lists/size.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/size.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/lists/sort.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/sort.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/lists/sort.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/sort.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/lists/toList.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/toList.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/lists/toList.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/lists/toList.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-bean-data.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-bean-data.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-bean-data.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-bean-data.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-model-attributes.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-model-attributes.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-model-attributes.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-model-attributes.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-request-parameters.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-request-parameters.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-request-parameters.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-request-parameters.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-servlet-context.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-servlet-context.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-servlet-context.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-servlet-context.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-session-attributes.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-session-attributes.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-session-attributes.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/mvcdata/email-session-attributes.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/pathvariables/index.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/pathvariables/index.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/pathvariables/index.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/pathvariables/index.html diff --git a/spring-thymeleaf-2/src/main/resources/templates/pathvariables/view.html b/spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/pathvariables/view.html similarity index 100% rename from spring-thymeleaf-2/src/main/resources/templates/pathvariables/view.html rename to spring-web-modules/spring-thymeleaf-2/src/main/resources/templates/pathvariables/view.html diff --git a/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/lists/ListsControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/lists/ListsControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/lists/ListsControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/lists/ListsControllerIntegrationTest.java diff --git a/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java b/spring-web-modules/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java similarity index 100% rename from spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java rename to spring-web-modules/spring-thymeleaf-2/src/test/java/com/baeldung/thymeleaf/mvcdata/EmailControllerUnitTest.java From d1af00c8c95be12b016fc0996600178e12c058d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 28 Dec 2020 14:51:36 +0100 Subject: [PATCH 386/590] JAVA-3545: Move spring-thymeleaf-3 into spring-web-modules --- pom.xml | 3 --- spring-web-modules/pom.xml | 1 + .../spring-thymeleaf-3}/README.md | 0 .../spring-thymeleaf-3}/pom.xml | 2 +- .../src/main/java/com/baeldung/thymeleaf/Application.java | 0 .../src/main/java/com/baeldung/thymeleaf/articles/Article.java | 0 .../com/baeldung/thymeleaf/articles/ArticlesController.java | 0 .../main/java/com/baeldung/thymeleaf/blog/BlogController.java | 0 .../src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java | 0 .../conditionalclasses/ConditionalClassesController.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsController.java | 0 .../baeldung/thymeleaf/currencies/CurrenciesController.java | 0 .../src/main/java/com/baeldung/thymeleaf/option/Student.java | 0 .../java/com/baeldung/thymeleaf/option/StudentController.java | 0 .../src/main/resources/static/js/cssandjs/actions.js | 0 .../src/main/resources/static/styles/cssandjs/main.css | 0 .../src/main/resources/templates/articles/articles-list.html | 0 .../src/main/resources/templates/blog/blog-new.html | 0 .../templates/conditionalclasses/conditionalclasses.html | 0 .../src/main/resources/templates/cssandjs/styledPage.html | 0 .../src/main/resources/templates/currencies/currencies.html | 0 .../src/main/resources/templates/option/studentForm.html | 0 .../com/baeldung/thymeleaf/ApplicationIntegrationTest.java | 0 .../thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java | 0 .../currencies/CurrenciesControllerIntegrationTest.java | 0 26 files changed, 2 insertions(+), 4 deletions(-) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/README.md (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/pom.xml (98%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/Application.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/Article.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/Student.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/StudentController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/js/cssandjs/actions.js (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/styles/cssandjs/main.css (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/articles/articles-list.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/blog/blog-new.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/conditionalclasses/conditionalclasses.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/cssandjs/styledPage.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/currencies/currencies.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/option/studentForm.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index f66433c612..14565fe87d 100644 --- a/pom.xml +++ b/pom.xml @@ -694,7 +694,6 @@ spring-swagger-codegen spring-threads - spring-thymeleaf-3 spring-vault spring-vertx @@ -1164,8 +1163,6 @@ spring-static-resources spring-swagger-codegen - spring-thymeleaf-3 - spring-vault spring-vertx diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 910af6a1bc..c5d9b33dd1 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-thymeleaf spring-thymeleaf-2 + spring-thymeleaf-3 diff --git a/spring-thymeleaf-3/README.md b/spring-web-modules/spring-thymeleaf-3/README.md similarity index 100% rename from spring-thymeleaf-3/README.md rename to spring-web-modules/spring-thymeleaf-3/README.md diff --git a/spring-thymeleaf-3/pom.xml b/spring-web-modules/spring-thymeleaf-3/pom.xml similarity index 98% rename from spring-thymeleaf-3/pom.xml rename to spring-web-modules/spring-thymeleaf-3/pom.xml index 7c58115d11..6dd1267e8a 100644 --- a/spring-thymeleaf-3/pom.xml +++ b/spring-web-modules/spring-thymeleaf-3/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java diff --git a/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js diff --git a/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css diff --git a/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java From 559fb4eb7f650bf9158bd1825b8c590e7567291e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 28 Dec 2020 22:42:11 +0100 Subject: [PATCH 387/590] JAVA-3545: Move spring-thymeleaf-3 into spring-web-modules --- pom.xml | 3 --- spring-web-modules/pom.xml | 1 + .../spring-thymeleaf-3}/README.md | 0 .../spring-thymeleaf-3}/pom.xml | 2 +- .../src/main/java/com/baeldung/thymeleaf/Application.java | 0 .../src/main/java/com/baeldung/thymeleaf/articles/Article.java | 0 .../com/baeldung/thymeleaf/articles/ArticlesController.java | 0 .../main/java/com/baeldung/thymeleaf/blog/BlogController.java | 0 .../src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java | 0 .../conditionalclasses/ConditionalClassesController.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsController.java | 0 .../baeldung/thymeleaf/currencies/CurrenciesController.java | 0 .../src/main/java/com/baeldung/thymeleaf/option/Student.java | 0 .../java/com/baeldung/thymeleaf/option/StudentController.java | 0 .../src/main/resources/static/js/cssandjs/actions.js | 0 .../src/main/resources/static/styles/cssandjs/main.css | 0 .../src/main/resources/templates/articles/articles-list.html | 0 .../src/main/resources/templates/blog/blog-new.html | 0 .../templates/conditionalclasses/conditionalclasses.html | 0 .../src/main/resources/templates/cssandjs/styledPage.html | 0 .../src/main/resources/templates/currencies/currencies.html | 0 .../src/main/resources/templates/option/studentForm.html | 0 .../com/baeldung/thymeleaf/ApplicationIntegrationTest.java | 0 .../thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java | 0 .../currencies/CurrenciesControllerIntegrationTest.java | 0 26 files changed, 2 insertions(+), 4 deletions(-) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/README.md (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/pom.xml (98%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/Application.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/Article.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/Student.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/StudentController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/js/cssandjs/actions.js (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/styles/cssandjs/main.css (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/articles/articles-list.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/blog/blog-new.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/conditionalclasses/conditionalclasses.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/cssandjs/styledPage.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/currencies/currencies.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/option/studentForm.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index f66433c612..14565fe87d 100644 --- a/pom.xml +++ b/pom.xml @@ -694,7 +694,6 @@ spring-swagger-codegen spring-threads - spring-thymeleaf-3 spring-vault spring-vertx @@ -1164,8 +1163,6 @@ spring-static-resources spring-swagger-codegen - spring-thymeleaf-3 - spring-vault spring-vertx diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 910af6a1bc..c5d9b33dd1 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-thymeleaf spring-thymeleaf-2 + spring-thymeleaf-3 diff --git a/spring-thymeleaf-3/README.md b/spring-web-modules/spring-thymeleaf-3/README.md similarity index 100% rename from spring-thymeleaf-3/README.md rename to spring-web-modules/spring-thymeleaf-3/README.md diff --git a/spring-thymeleaf-3/pom.xml b/spring-web-modules/spring-thymeleaf-3/pom.xml similarity index 98% rename from spring-thymeleaf-3/pom.xml rename to spring-web-modules/spring-thymeleaf-3/pom.xml index 7c58115d11..6dd1267e8a 100644 --- a/spring-thymeleaf-3/pom.xml +++ b/spring-web-modules/spring-thymeleaf-3/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java diff --git a/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js diff --git a/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css diff --git a/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java From 061cf1a1ed4d1e654c46dca6c02562e38ef3e5c8 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 29 Dec 2020 00:22:02 +0100 Subject: [PATCH 388/590] JAVA-3496: Use a single common QueryApplication --- .../{UserApplication.java => QueryApplication.java} | 4 ++-- .../spring/data/jpa/query/datetime/Application.java | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) rename persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/{UserApplication.java => QueryApplication.java} (72%) delete mode 100644 persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/datetime/Application.java diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/QueryApplication.java similarity index 72% rename from persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/QueryApplication.java index 0f7b19ec47..48c29eda23 100644 --- a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/UserApplication.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/QueryApplication.java @@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class UserApplication { +public class QueryApplication { public static void main(String[] args) { - SpringApplication.run(UserApplication.class, args); + SpringApplication.run(QueryApplication.class, args); } } diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/datetime/Application.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/datetime/Application.java deleted file mode 100644 index 81e5a2f790..0000000000 --- a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/spring/data/jpa/query/datetime/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.spring.data.jpa.query.datetime; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} From 05c7fa926932fae40dc04c6d049775694ea5e033 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:36:14 +0530 Subject: [PATCH 389/590] JAVA-3524: Moved spring-mvc-forms-thymeleaf inside spring-web-modules --- .../spring-mvc-forms-thymeleaf}/README.md | 0 .../spring-mvc-forms-thymeleaf}/pom.xml | 2 +- .../src/main/java/com/baeldung/listbindingexample/Book.java | 0 .../main/java/com/baeldung/listbindingexample/BookService.java | 0 .../java/com/baeldung/listbindingexample/BooksCreationDto.java | 0 .../src/main/java/com/baeldung/listbindingexample/Config.java | 0 .../com/baeldung/listbindingexample/InMemoryBookService.java | 0 .../com/baeldung/listbindingexample/ListBindingApplication.java | 0 .../baeldung/listbindingexample/MultipleBooksController.java | 0 .../src/main/java/com/baeldung/sessionattrs/Config.java | 0 .../java/com/baeldung/sessionattrs/SessionAttrsApplication.java | 0 .../baeldung/sessionattrs/TodoControllerWithScopedProxy.java | 0 .../sessionattrs/TodoControllerWithSessionAttributes.java | 0 .../src/main/java/com/baeldung/sessionattrs/TodoItem.java | 0 .../src/main/java/com/baeldung/sessionattrs/TodoList.java | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-forms-thymeleaf}/src/main/resources/logback.xml | 0 .../src/main/resources/templates/books/allBooks.html | 0 .../src/main/resources/templates/books/createBooksForm.html | 0 .../src/main/resources/templates/books/editBooksForm.html | 0 .../src/main/resources/templates/books/index.html | 0 .../src/main/resources/templates/sessionattrs/index.html | 0 .../main/resources/templates/sessionattrs/scopedproxyform.html | 0 .../main/resources/templates/sessionattrs/scopedproxytodos.html | 0 .../resources/templates/sessionattrs/sessionattributesform.html | 0 .../templates/sessionattrs/sessionattributestodos.html | 0 .../com}/baeldung/listbindingexample/SpringContextTest.java | 0 .../sessionattrs/SessionAttrsApplicationIntegrationTest.java | 0 .../test/java/com}/baeldung/sessionattrs/SpringContextTest.java | 0 .../src/test/java/com/baeldung/sessionattrs/TestConfig.java | 0 .../TodoControllerWithScopedProxyIntegrationTest.java | 0 .../TodoControllerWithSessionAttributesIntegrationTest.java | 0 32 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/README.md (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/pom.xml (96%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/Book.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/BookService.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/Config.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/Config.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoItem.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoList.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/application.properties (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/logback.xml (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/allBooks.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/createBooksForm.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/editBooksForm.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/index.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/index.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/scopedproxyform.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/scopedproxytodos.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/sessionattributesform.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/sessionattributestodos.html (100%) rename {spring-mvc-forms-thymeleaf/src/test/java/org => spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com}/baeldung/listbindingexample/SpringContextTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java (100%) rename {spring-mvc-forms-thymeleaf/src/test/java/org => spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com}/baeldung/sessionattrs/SpringContextTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TestConfig.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java (100%) diff --git a/spring-mvc-forms-thymeleaf/README.md b/spring-web-modules/spring-mvc-forms-thymeleaf/README.md similarity index 100% rename from spring-mvc-forms-thymeleaf/README.md rename to spring-web-modules/spring-mvc-forms-thymeleaf/README.md diff --git a/spring-mvc-forms-thymeleaf/pom.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml similarity index 96% rename from spring-mvc-forms-thymeleaf/pom.xml rename to spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml index 2aed7f70ad..641f64b93c 100644 --- a/spring-mvc-forms-thymeleaf/pom.xml +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/application.properties b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/application.properties similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/application.properties diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html diff --git a/spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/listbindingexample/SpringContextTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/listbindingexample/SpringContextTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/listbindingexample/SpringContextTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/listbindingexample/SpringContextTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/sessionattrs/SpringContextTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SpringContextTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/sessionattrs/SpringContextTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SpringContextTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java From bcfbe6102ca657416983f90559194089eddc1412 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:37:05 +0530 Subject: [PATCH 390/590] JAVA-3524: Added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 910af6a1bc..730647d9e2 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-forms-thymeleaf spring-thymeleaf spring-thymeleaf-2 From 1e89df8bcfddb6107f68f76949395c1b22750bec Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:38:10 +0530 Subject: [PATCH 391/590] JAVA-3524: removed module spring-mvc-forms-thymeleaf from main pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index f66433c612..7db1c5bc54 100644 --- a/pom.xml +++ b/pom.xml @@ -658,7 +658,6 @@ spring-mobile spring-mockito - spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 @@ -1130,7 +1129,6 @@ spring-mobile spring-mockito - spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 From 9b1abb07fbafaadcb5151dedb1f7b435eff9841e Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Tue, 29 Dec 2020 11:02:52 +0200 Subject: [PATCH 392/590] BAEL-4472- Binary Semaphore vs a ReentrantLock - Unit test added --- ...inarySemaphoreVsReentrantLockUnitTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java new file mode 100644 index 0000000000..f456e82f39 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.binarysemaphorereentrantlock; + +import static org.junit.Assert.assertEquals; +import java.util.concurrent.Semaphore; +import java.util.concurrent.locks.ReentrantLock; + +import org.junit.Test; + +public class BinarySemaphoreVsReentrantLockUnitTest { + + @Test + public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { + Semaphore binarySemaphore = new Semaphore(1); + try { + binarySemaphore.acquire(); + assertEquals(0, binarySemaphore.availablePermits()); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + binarySemaphore.release(); + assertEquals(1, binarySemaphore.availablePermits()); + } + } + + @Test + public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + + @Test + public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + reentrantLock.lock(); + assertEquals(2, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + +} From 80c8a10520b30fdff29e8454c501909e628a017f Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Tue, 29 Dec 2020 10:38:58 +0100 Subject: [PATCH 393/590] BAEL-4745 Update "How to Configure Spring Boot Tomcat" article --- .../src/main/resources/application-tomcat.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-runtime/src/main/resources/application-tomcat.properties b/spring-boot-modules/spring-boot-runtime/src/main/resources/application-tomcat.properties index 42d03a066e..ba91c5f3b2 100644 --- a/spring-boot-modules/spring-boot-runtime/src/main/resources/application-tomcat.properties +++ b/spring-boot-modules/spring-boot-runtime/src/main/resources/application-tomcat.properties @@ -9,7 +9,7 @@ server.error.include-exception=true server.error.include-stacktrace=always ## Server connections configuration -server.tomcat.max-threads=200 +server.tomcat.threads.max=200 server.connection-timeout=5s server.max-http-header-size=8KB server.tomcat.max-swallow-size=2MB From 7a308db8023bc41e4ac8145abf567822f5a1b14c Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 29 Dec 2020 12:12:50 +0200 Subject: [PATCH 394/590] Update README.md --- spring-boot-modules/spring-boot-deployment/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-deployment/README.md b/spring-boot-modules/spring-boot-deployment/README.md index b6aa468098..85f288d33b 100644 --- a/spring-boot-modules/spring-boot-deployment/README.md +++ b/spring-boot-modules/spring-boot-deployment/README.md @@ -5,6 +5,5 @@ This module contains articles about deployment of a Spring Boot Application ### Relevant Articles: - [Deploy a Spring Boot WAR into a Tomcat Server](https://www.baeldung.com/spring-boot-war-tomcat-deploy) - [Spring Boot Console Application](https://www.baeldung.com/spring-boot-console-app) - - [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) - [Comparing Embedded Servlet Containers in Spring Boot](https://www.baeldung.com/spring-boot-servlet-containers) - [Graceful Shutdown of a Spring Boot Application](https://www.baeldung.com/spring-boot-graceful-shutdown) From 3329202a44be7b2b530ff0a2e55283016556fb29 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 29 Dec 2020 12:13:03 +0200 Subject: [PATCH 395/590] Update README.md --- spring-boot-modules/spring-boot-runtime/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-runtime/README.md b/spring-boot-modules/spring-boot-runtime/README.md index 62727ecc76..271093421c 100644 --- a/spring-boot-modules/spring-boot-runtime/README.md +++ b/spring-boot-modules/spring-boot-runtime/README.md @@ -10,4 +10,5 @@ This module contains articles about administering a Spring Boot runtime - [Spring Boot Embedded Tomcat Logs](https://www.baeldung.com/spring-boot-embedded-tomcat-logs) - [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring) - [CORS with Spring](https://www.baeldung.com/spring-cors) - - [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging) \ No newline at end of file + - [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging) + - [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) From ee174737ab038b0f0a76421a78ec8840d4ddb9b7 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 29 Dec 2020 12:15:04 +0100 Subject: [PATCH 396/590] JAVA-3534: Move spring-rest-http into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-http}/README.md | 0 .../spring-rest-http}/pom.xml | 2 +- .../java/com/baeldung/CustomerSpringBootRestApplication.java | 0 .../src/main/java/com/baeldung/config/MvcConfig.java | 0 .../java/com/baeldung/controllers/DeferredResultController.java | 0 .../src/main/java/com/baeldung/model/Customer.java | 0 .../baeldung/requestmapping/BarMappingExamplesController.java | 0 .../requestmapping/BazzNewMappingsExampleController.java | 0 .../baeldung/requestmapping/FooMappingExamplesController.java | 0 .../src/main/java/com/baeldung/service/CustomerIdGenerator.java | 0 .../src/main/java/com/baeldung/service/CustomerService.java | 0 .../java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java | 0 .../java/com/baeldung/service/impl/CustomerServiceImpl.java | 0 .../web/controller/customer/CustomerRestController.java | 0 .../com/baeldung/web/controller/status/ExampleController.java | 0 .../com/baeldung/web/controller/status/ForbiddenException.java | 0 .../src/main/java/com/baeldung/web/dto/Bazz.java | 0 .../src/main/java/com/baeldung/web/dto/Foo.java | 0 .../com/baeldung/web/exception/CustomerNotFoundException.java | 0 .../openapi-dates-definitions/openapi-3-date-format.yaml | 0 .../openapi-dates-definitions/openapi-3-date-pattern.yaml | 0 .../openapi-dates-definitions/openapi-3-datetime-format.yaml | 0 .../resources/openapi-queryparam-definitions/openapi-2.yaml | 0 .../resources/openapi-queryparam-definitions/openapi-3.yaml | 0 .../requestmapping/BazzNewMappingsExampleIntegrationTest.java | 0 .../requestmapping/FooMappingExamplesControllerUnitTest.java | 0 .../com/baeldung/responseheaders/ResponseHeaderLiveTest.java | 0 .../baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java | 0 .../com/baeldung/service/impl/CustomerServiceImplUnitTest.java | 0 .../baeldung/uribuilder/SpringUriBuilderIntegrationTest.java | 0 .../customer/CustomerRestControllerIntegrationTest.java | 0 .../web/controller/customer/CustomerRestControllerUnitTest.java | 0 .../web/controller/status/ExampleControllerIntegrationTest.java | 0 35 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-http => spring-web-modules/spring-rest-http}/README.md (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/pom.xml (97%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/CustomerSpringBootRestApplication.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/config/MvcConfig.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/controllers/DeferredResultController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/model/Customer.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/service/CustomerIdGenerator.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/service/CustomerService.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/service/impl/CustomerServiceImpl.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/controller/customer/CustomerRestController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/controller/status/ExampleController.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/dto/Bazz.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/dto/Foo.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/java/com/baeldung/web/exception/CustomerNotFoundException.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/resources/openapi-dates-definitions/openapi-3-date-format.yaml (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/resources/openapi-dates-definitions/openapi-3-date-pattern.yaml (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/resources/openapi-dates-definitions/openapi-3-datetime-format.yaml (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/requestmapping/BazzNewMappingsExampleIntegrationTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/responseheaders/ResponseHeaderLiveTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/service/impl/CustomerServiceImplUnitTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/uribuilder/SpringUriBuilderIntegrationTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerIntegrationTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerUnitTest.java (100%) rename {spring-rest-http => spring-web-modules/spring-rest-http}/src/test/java/com/baeldung/web/controller/status/ExampleControllerIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index 14565fe87d..f8e84c09e1 100644 --- a/pom.xml +++ b/pom.xml @@ -673,7 +673,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-http spring-rest-http-2 spring-rest-query-language spring-rest-shell @@ -1144,7 +1143,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-http spring-rest-query-language spring-rest-shell spring-rest-simple diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c5d9b33dd1..3dea8fc36e 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-rest-http spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 diff --git a/spring-rest-http/README.md b/spring-web-modules/spring-rest-http/README.md similarity index 100% rename from spring-rest-http/README.md rename to spring-web-modules/spring-rest-http/README.md diff --git a/spring-rest-http/pom.xml b/spring-web-modules/spring-rest-http/pom.xml similarity index 97% rename from spring-rest-http/pom.xml rename to spring-web-modules/spring-rest-http/pom.xml index 18b7e0af05..422bcd32f7 100644 --- a/spring-rest-http/pom.xml +++ b/spring-web-modules/spring-rest-http/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-http/src/main/java/com/baeldung/CustomerSpringBootRestApplication.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/CustomerSpringBootRestApplication.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/CustomerSpringBootRestApplication.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/CustomerSpringBootRestApplication.java diff --git a/spring-rest-http/src/main/java/com/baeldung/config/MvcConfig.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/config/MvcConfig.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/config/MvcConfig.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/config/MvcConfig.java diff --git a/spring-rest-http/src/main/java/com/baeldung/controllers/DeferredResultController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/controllers/DeferredResultController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/controllers/DeferredResultController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/controllers/DeferredResultController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/model/Customer.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/model/Customer.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/model/Customer.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/model/Customer.java diff --git a/spring-rest-http/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/service/CustomerIdGenerator.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/CustomerIdGenerator.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/service/CustomerIdGenerator.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/CustomerIdGenerator.java diff --git a/spring-rest-http/src/main/java/com/baeldung/service/CustomerService.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/CustomerService.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/service/CustomerService.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/CustomerService.java diff --git a/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerIdGeneratorImpl.java diff --git a/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerServiceImpl.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerServiceImpl.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerServiceImpl.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/service/impl/CustomerServiceImpl.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/controller/customer/CustomerRestController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/customer/CustomerRestController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/controller/customer/CustomerRestController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/customer/CustomerRestController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ExampleController.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ExampleController.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/controller/status/ExampleController.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ExampleController.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/dto/Bazz.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/dto/Bazz.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/dto/Bazz.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/dto/Bazz.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/dto/Foo.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/dto/Foo.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/dto/Foo.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/dto/Foo.java diff --git a/spring-rest-http/src/main/java/com/baeldung/web/exception/CustomerNotFoundException.java b/spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/exception/CustomerNotFoundException.java similarity index 100% rename from spring-rest-http/src/main/java/com/baeldung/web/exception/CustomerNotFoundException.java rename to spring-web-modules/spring-rest-http/src/main/java/com/baeldung/web/exception/CustomerNotFoundException.java diff --git a/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-format.yaml b/spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-format.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-format.yaml rename to spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-format.yaml diff --git a/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-pattern.yaml b/spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-pattern.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-pattern.yaml rename to spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-date-pattern.yaml diff --git a/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-datetime-format.yaml b/spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-datetime-format.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-datetime-format.yaml rename to spring-web-modules/spring-rest-http/src/main/resources/openapi-dates-definitions/openapi-3-datetime-format.yaml diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml b/spring-web-modules/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml rename to spring-web-modules/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml b/spring-web-modules/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml rename to spring-web-modules/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml diff --git a/spring-rest-http/src/test/java/com/baeldung/requestmapping/BazzNewMappingsExampleIntegrationTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/requestmapping/BazzNewMappingsExampleIntegrationTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/requestmapping/BazzNewMappingsExampleIntegrationTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/requestmapping/BazzNewMappingsExampleIntegrationTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/requestmapping/FooMappingExamplesControllerUnitTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/responseheaders/ResponseHeaderLiveTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/responseheaders/ResponseHeaderLiveTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/responseheaders/ResponseHeaderLiveTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/responseheaders/ResponseHeaderLiveTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerIdGeneratorImplUnitTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerServiceImplUnitTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerServiceImplUnitTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerServiceImplUnitTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/service/impl/CustomerServiceImplUnitTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/uribuilder/SpringUriBuilderIntegrationTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/uribuilder/SpringUriBuilderIntegrationTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/uribuilder/SpringUriBuilderIntegrationTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/uribuilder/SpringUriBuilderIntegrationTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerIntegrationTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerIntegrationTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerIntegrationTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerIntegrationTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerUnitTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerUnitTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerUnitTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/customer/CustomerRestControllerUnitTest.java diff --git a/spring-rest-http/src/test/java/com/baeldung/web/controller/status/ExampleControllerIntegrationTest.java b/spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/status/ExampleControllerIntegrationTest.java similarity index 100% rename from spring-rest-http/src/test/java/com/baeldung/web/controller/status/ExampleControllerIntegrationTest.java rename to spring-web-modules/spring-rest-http/src/test/java/com/baeldung/web/controller/status/ExampleControllerIntegrationTest.java From d84de4ccdfc9c65bd0de800ea956ff86dbb25ed6 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 29 Dec 2020 14:43:19 +0100 Subject: [PATCH 397/590] JAVA-3533: Move spring-rest-http-2 into spring-web-modules --- pom.xml | 1 - spring-web-modules/pom.xml | 1 + .../spring-rest-http-2}/README.md | 0 .../spring-rest-http-2}/pom.xml | 2 +- .../src/main/java/com/baeldung/SpringBootRest2Application.java | 0 .../com/baeldung/swaggerui/disable/config/SwaggerConfig.java | 0 .../swaggerui/disable/controllers/VersionController.java | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/README.md (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/pom.xml (95%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/SpringBootRest2Application.java (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..520343431b 100644 --- a/pom.xml +++ b/pom.xml @@ -673,7 +673,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-http-2 spring-rest-query-language spring-rest-shell spring-rest-simple diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..2b1dfc367a 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,7 @@ spring-mvc-crash spring-mvc-forms-jsp spring-rest-http + spring-rest-http-2 spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 diff --git a/spring-rest-http-2/README.md b/spring-web-modules/spring-rest-http-2/README.md similarity index 100% rename from spring-rest-http-2/README.md rename to spring-web-modules/spring-rest-http-2/README.md diff --git a/spring-rest-http-2/pom.xml b/spring-web-modules/spring-rest-http-2/pom.xml similarity index 95% rename from spring-rest-http-2/pom.xml rename to spring-web-modules/spring-rest-http-2/pom.xml index 8678d7243d..6aa8be365c 100644 --- a/spring-rest-http-2/pom.xml +++ b/spring-web-modules/spring-rest-http-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java diff --git a/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java diff --git a/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java From 1a63c83f55f5141b3247f005352b8e3e8433f5b3 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Tue, 29 Dec 2020 16:42:52 +0100 Subject: [PATCH 398/590] [BAEL-4015] fix integration tests --- .../spring-cloud-eureka-feign-client-integration-test/pom.xml | 2 +- ...rationTest.java => ServiceDiscoveryBooksClientLiveTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/{ServiceDiscoveryBooksClientIntegrationTest.java => ServiceDiscoveryBooksClientLiveTest.java} (97%) diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml index 3348dbb24f..95b1275e2c 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml @@ -88,7 +88,7 @@ maven-surefire-plugin 1 - true + false diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientLiveTest.java similarity index 97% rename from spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientLiveTest.java index 027579d20d..3ac067b8f8 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientIntegrationTest.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/src/test/java/com/baeldung/spring/cloud/client/ServiceDiscoveryBooksClientLiveTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ContextConfiguration(classes = { MockBookServiceConfig.class }, initializers = { EurekaContainerConfig.Initializer.class }) -class ServiceDiscoveryBooksClientIntegrationTest { +class ServiceDiscoveryBooksClientLiveTest { @Autowired private BooksClient booksClient; From 469e5c5c861fdefbbaf83afd9bb601a553d259f6 Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 29 Dec 2020 18:52:31 +0100 Subject: [PATCH 399/590] JAVA-3539 Move spring-resttemplate-2 module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-resttemplate-2}/README.md | 0 .../spring-resttemplate-2}/pom.xml | 2 +- .../compress/CompressingClientHttpRequestInterceptor.java | 0 .../src/main/java/com/baeldung/compress/GzipUtils.java | 0 .../java/com/baeldung/compress/JettyWebServerConfiguration.java | 0 .../src/main/java/com/baeldung/compress/Message.java | 0 .../src/main/java/com/baeldung/compress/MessageController.java | 0 .../java/com/baeldung/compress/RestTemplateConfiguration.java | 0 .../com/baeldung/compress/SpringCompressRequestApplication.java | 0 .../resttemplate/RestTemplateConfigurationApplication.java | 0 .../resttemplate/json/consumer/service/UserConsumerService.java | 0 .../json/consumer/service/UserConsumerServiceImpl.java | 0 .../main/java/com/baeldung/resttemplate/json/model/Address.java | 0 .../main/java/com/baeldung/resttemplate/json/model/User.java | 0 .../resttemplate/logging/web/controller/PersonController.java | 0 .../com/baeldung/resttemplate/web/controller/PersonAPI.java | 0 .../src/main/java/com/baeldung/resttemplate/web/dto/Person.java | 0 .../com/baeldung/resttemplate/web/service/PersonService.java | 0 .../baeldung/resttemplate/web/service/PersonServiceImpl.java | 0 .../src/main/java/com/baeldung/sampleapp/config/WebConfig.java | 0 .../web/controller/mediatypes/CustomMediaTypeController.java | 0 .../main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java | 0 .../java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java | 0 .../src/main/resources/application.properties | 0 .../src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java | 0 .../java/com/baeldung/compress/MessageControllerUnitTest.java | 0 .../json/consumer/service/UserConsumerServiceImplUnitTest.java | 0 .../com/baeldung/resttemplate/logging/LoggingInterceptor.java | 0 .../resttemplate/logging/RestTemplateLoggingLiveTest.java | 0 .../com/baeldung/resttemplate/postjson/PersonAPILiveTest.java | 0 .../com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java | 0 .../resttemplate/proxy/RestTemplateCustomizerLiveTest.java | 0 .../mediatypes/CustomMediaTypeControllerIntegrationTest.java | 0 .../mediatypes/CustomMediaTypeControllerLiveTest.java | 0 .../java/com/baeldung/web/controller/mediatypes/TestConfig.java | 0 .../src/test/resources/application.properties | 0 38 files changed, 2 insertions(+), 3 deletions(-) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/README.md (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/pom.xml (97%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/GzipUtils.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/Message.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/MessageController.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/json/model/Address.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/json/model/User.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/dto/Person.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/config/WebConfig.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/main/resources/application.properties (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java (100%) rename {spring-resttemplate-2 => spring-web-modules/spring-resttemplate-2}/src/test/resources/application.properties (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..14de77891b 100644 --- a/pom.xml +++ b/pom.xml @@ -678,7 +678,6 @@ spring-rest-shell spring-rest-simple spring-resttemplate - spring-resttemplate-2 spring-rest-testing spring-roo @@ -1147,7 +1146,6 @@ spring-rest-shell spring-rest-simple spring-resttemplate - spring-resttemplate-2 spring-rest-testing spring-roo diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..67580e9b91 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,7 @@ spring-mvc-crash spring-mvc-forms-jsp spring-rest-http + spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 diff --git a/spring-resttemplate-2/README.md b/spring-web-modules/spring-resttemplate-2/README.md similarity index 100% rename from spring-resttemplate-2/README.md rename to spring-web-modules/spring-resttemplate-2/README.md diff --git a/spring-resttemplate-2/pom.xml b/spring-web-modules/spring-resttemplate-2/pom.xml similarity index 97% rename from spring-resttemplate-2/pom.xml rename to spring-web-modules/spring-resttemplate-2/pom.xml index 1404a35f33..04be058638 100644 --- a/spring-resttemplate-2/pom.xml +++ b/spring-web-modules/spring-resttemplate-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + parent-boot-2/pom.xml diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/CompressingClientHttpRequestInterceptor.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/GzipUtils.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/JettyWebServerConfiguration.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/Message.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/MessageController.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/RestTemplateConfiguration.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/compress/SpringCompressRequestApplication.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerService.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImpl.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/Address.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/json/model/User.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java similarity index 100% rename from spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java diff --git a/spring-resttemplate-2/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate-2/src/main/resources/application.properties similarity index 100% rename from spring-resttemplate-2/src/main/resources/application.properties rename to spring-web-modules/spring-resttemplate-2/src/main/resources/application.properties diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/compress/GzipUtilsUnitTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/compress/MessageControllerUnitTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/json/consumer/service/UserConsumerServiceImplUnitTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java similarity index 100% rename from spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java diff --git a/spring-resttemplate-2/src/test/resources/application.properties b/spring-web-modules/spring-resttemplate-2/src/test/resources/application.properties similarity index 100% rename from spring-resttemplate-2/src/test/resources/application.properties rename to spring-web-modules/spring-resttemplate-2/src/test/resources/application.properties From 11dae9ea5a1a1d941a969f843b03a2e817d7e522 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:44:00 +0530 Subject: [PATCH 400/590] JAVA-3526: Moved spring-mvc-java inside spring-web-modules --- .../spring-mvc-java}/.gitignore | 0 .../spring-mvc-java}/README.md | 2 +- .../spring-mvc-java}/persons.xls | Bin .../spring-mvc-java}/persons.xlsx | Bin .../spring-mvc-java}/pom.xml | 2 +- .../java/com/baeldung/SpringMVCApplication.java | 0 .../main/java/com/baeldung/accessparamsjs/App.java | 0 .../com/baeldung/accessparamsjs/Controller.java | 0 .../main/java/com/baeldung/cache/BookService.java | 0 .../java/com/baeldung/cache/CustomKeyGenerator.java | 0 .../java/com/baeldung/excel/ExcelPOIHelper.java | 0 .../src/main/java/com/baeldung/excel/MyCell.java | 0 .../java/com/baeldung/filters/EmptyParamFilter.java | 0 .../java/com/baeldung/listeners/AppListener.java | 0 .../com/baeldung/listeners/RequestListener.java | 0 .../src/main/java/com/baeldung/model/Article.java | 0 .../src/main/java/com/baeldung/model/Book.java | 0 .../java/com/baeldung/model/FormDataWithFile.java | 0 .../src/main/java/com/baeldung/model/Greeting.java | 0 .../src/main/java/com/baeldung/model/User.java | 0 .../java/com/baeldung/servlets/CounterServlet.java | 0 .../com/baeldung/servlets/UppercaseServlet.java | 0 .../spring/web/config/ApplicationCacheConfig.java | 0 .../spring/web/config/MainWebAppInitializer.java | 0 .../com/baeldung/spring/web/config/WebConfig.java | 0 .../src/main/java/com/baeldung/web/BeanA.java | 0 .../src/main/java/com/baeldung/web/BeanB.java | 0 .../baeldung/web/controller/ExcelController.java | 0 .../web/controller/FileUploadController.java | 0 .../baeldung/web/controller/GreetController.java | 0 .../baeldung/web/controller/ImageController.java | 0 .../MultipartFileUploadStubController.java | 0 .../baeldung/web/controller/SampleController.java | 0 .../com/baeldung/web/controller/UserController.java | 0 .../web/controller/message/MessageController.java | 0 .../optionalpathvars/ArticleViewerController.java | 0 .../ArticleViewerWithMapParamController.java | 0 .../ArticleViewerWithOptionalParamController.java | 0 ...rticleViewerWithRequiredAttributeController.java | 0 ...ticleViewerWithTwoSeparateMethodsController.java | 0 .../src/main/resources/annotations.properties | 0 .../src/main/resources/annotations.xml | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-java}/src/main/resources/logback.xml | 0 .../src/main/resources/messages_en.properties | 0 .../src/main/resources/mvc-configuration.xml | 0 .../main/resources/templates/thymeleaf/index.html | 0 .../main/webapp/WEB-INF/images/image-example.jpg | Bin .../src/main/webapp/WEB-INF/jsp/index.jsp | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/templates/footer.html | 0 .../src/main/webapp/WEB-INF/templates/hello.html | 0 .../src/main/webapp/WEB-INF/templates/index.html | 0 .../src/main/webapp/WEB-INF/templates/message.html | 0 .../src/main/webapp/WEB-INF/view/excel.jsp | 0 .../src/main/webapp/WEB-INF/view/fileUploadForm.jsp | 0 .../src/main/webapp/WEB-INF/view/fileUploadView.jsp | 0 .../src/main/webapp/WEB-INF/view/index.jsp | 0 .../src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/web_old.xml | 0 .../spring-mvc-java}/src/main/webapp/js/jquery.js | 0 .../src/main/webapp/js/script-async-jquery.js | 0 .../src/main/webapp/js/script-async.js | 0 .../spring-mvc-java}/src/main/webapp/js/script.js | 0 .../baeldung/accessparamsjs/ControllerUnitTest.java | 0 .../baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java | 0 .../htmlunit/HtmlUnitAndSpringLiveTest.java | 0 .../htmlunit/HtmlUnitWebScrapingLiveTest.java | 0 .../test/java/com/baeldung/htmlunit/TestConfig.java | 0 .../controller/GreetControllerIntegrationTest.java | 0 .../GreetControllerRealIntegrationTest.java | 0 .../web/controller/GreetControllerUnitTest.java | 0 .../test/java/com/baeldung/web/controller/README.md | 0 .../ArticleViewerControllerIntegrationTest.java | 0 ...rControllerWithOptionalParamIntegrationTest.java | 0 ...trollerWithRequiredAttributeIntegrationTest.java | 0 .../ArticleViewerWithMapParamIntegrationTest.java | 0 ...ViewerWithTwoSeparateMethodsIntegrationTest.java | 0 .../spring-mvc-java}/src/test/resources/.gitignore | 0 .../src/test/resources/logback-test.xml | 0 80 files changed, 2 insertions(+), 2 deletions(-) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/.gitignore (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/README.md (92%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/persons.xls (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/persons.xlsx (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/pom.xml (99%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/SpringMVCApplication.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/accessparamsjs/App.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/accessparamsjs/Controller.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/cache/BookService.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/cache/CustomKeyGenerator.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/excel/ExcelPOIHelper.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/excel/MyCell.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/filters/EmptyParamFilter.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/listeners/AppListener.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/listeners/RequestListener.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Article.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Book.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/FormDataWithFile.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Greeting.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/User.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/servlets/CounterServlet.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/servlets/UppercaseServlet.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/WebConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/BeanA.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/BeanB.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/ExcelController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/FileUploadController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/GreetController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/ImageController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/SampleController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/UserController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/message/MessageController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/annotations.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/annotations.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/application.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/logback.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/messages_en.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/mvc-configuration.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/templates/thymeleaf/index.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/images/image-example.jpg (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/jsp/index.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/footer.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/hello.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/index.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/message.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/excel.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/fileUploadForm.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/fileUploadView.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/index.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/web_old.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/jquery.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script-async-jquery.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script-async.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/TestConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/README.md (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/resources/.gitignore (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/resources/logback-test.xml (100%) diff --git a/spring-mvc-java/.gitignore b/spring-web-modules/spring-mvc-java/.gitignore similarity index 100% rename from spring-mvc-java/.gitignore rename to spring-web-modules/spring-mvc-java/.gitignore diff --git a/spring-mvc-java/README.md b/spring-web-modules/spring-mvc-java/README.md similarity index 92% rename from spring-mvc-java/README.md rename to spring-web-modules/spring-mvc-java/README.md index 877d92901a..afd1aea3bf 100644 --- a/spring-mvc-java/README.md +++ b/spring-web-modules/spring-mvc-java/README.md @@ -4,7 +4,7 @@ This module contains articles about Spring MVC with Java configuration ### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring +The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring) diff --git a/spring-mvc-java/persons.xls b/spring-web-modules/spring-mvc-java/persons.xls similarity index 100% rename from spring-mvc-java/persons.xls rename to spring-web-modules/spring-mvc-java/persons.xls diff --git a/spring-mvc-java/persons.xlsx b/spring-web-modules/spring-mvc-java/persons.xlsx similarity index 100% rename from spring-mvc-java/persons.xlsx rename to spring-web-modules/spring-mvc-java/persons.xlsx diff --git a/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml similarity index 99% rename from spring-mvc-java/pom.xml rename to spring-web-modules/spring-mvc-java/pom.xml index a45e9c8521..179ac0fb54 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Article.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Article.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Article.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Article.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Book.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Book.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Book.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Book.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/User.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/User.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/User.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/User.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java diff --git a/spring-mvc-java/src/main/resources/annotations.properties b/spring-web-modules/spring-mvc-java/src/main/resources/annotations.properties similarity index 100% rename from spring-mvc-java/src/main/resources/annotations.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/annotations.properties diff --git a/spring-mvc-java/src/main/resources/annotations.xml b/spring-web-modules/spring-mvc-java/src/main/resources/annotations.xml similarity index 100% rename from spring-mvc-java/src/main/resources/annotations.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/annotations.xml diff --git a/spring-mvc-java/src/main/resources/application.properties b/spring-web-modules/spring-mvc-java/src/main/resources/application.properties similarity index 100% rename from spring-mvc-java/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/application.properties diff --git a/spring-mvc-java/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-java/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-java/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/logback.xml diff --git a/spring-mvc-java/src/main/resources/messages_en.properties b/spring-web-modules/spring-mvc-java/src/main/resources/messages_en.properties similarity index 100% rename from spring-mvc-java/src/main/resources/messages_en.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/messages_en.properties diff --git a/spring-mvc-java/src/main/resources/mvc-configuration.xml b/spring-web-modules/spring-mvc-java/src/main/resources/mvc-configuration.xml similarity index 100% rename from spring-mvc-java/src/main/resources/mvc-configuration.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/mvc-configuration.xml diff --git a/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html b/spring-web-modules/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html similarity index 100% rename from spring-mvc-java/src/main/resources/templates/thymeleaf/index.html rename to spring-web-modules/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml diff --git a/spring-mvc-java/src/main/webapp/js/jquery.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/jquery.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/jquery.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/jquery.js diff --git a/spring-mvc-java/src/main/webapp/js/script-async-jquery.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async-jquery.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script-async-jquery.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async-jquery.js diff --git a/spring-mvc-java/src/main/webapp/js/script-async.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script-async.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async.js diff --git a/spring-mvc-java/src/main/webapp/js/script.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script.js diff --git a/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java diff --git a/spring-mvc-java/src/test/resources/.gitignore b/spring-web-modules/spring-mvc-java/src/test/resources/.gitignore similarity index 100% rename from spring-mvc-java/src/test/resources/.gitignore rename to spring-web-modules/spring-mvc-java/src/test/resources/.gitignore diff --git a/spring-mvc-java/src/test/resources/logback-test.xml b/spring-web-modules/spring-mvc-java/src/test/resources/logback-test.xml similarity index 100% rename from spring-mvc-java/src/test/resources/logback-test.xml rename to spring-web-modules/spring-mvc-java/src/test/resources/logback-test.xml From 81b21f361c772f7cddf2460b80409a405ea25aac Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:44:51 +0530 Subject: [PATCH 401/590] JAVA-3525: Moved spring-mvc-java-2 inside spring-web-modules --- .../spring-mvc-java-2}/.gitignore | 0 .../spring-mvc-java-2}/README.md | 0 .../spring-mvc-java-2}/pom.xml | 2 +- .../main/java/com/baeldung/cache/CacheControlController.java | 0 .../src/main/java/com/baeldung/cache/CacheWebConfig.java | 0 .../src/main/java/com/baeldung/datetime/DateTimeConfig.java | 0 .../src/main/java/com/baeldung/datetime/DateTimeController.java | 0 .../main/java/com/baeldung/matrix/config/MatrixWebConfig.java | 0 .../java/com/baeldung/matrix/controller/CompanyController.java | 0 .../java/com/baeldung/matrix/controller/EmployeeController.java | 0 .../src/main/java/com/baeldung/matrix/model/Company.java | 0 .../src/main/java/com/baeldung/matrix/model/Employee.java | 0 .../multiparttesting/MultipartPostRequestController.java | 0 .../CustomWebMvcConfigurationSupport.java | 0 .../com/baeldung/pathvariable.dottruncated/SiteController.java | 0 .../baeldung/pathvariable/PathVariableAnnotationController.java | 0 .../spring-mvc-java-2}/src/main/resources/targetFile.tmp | 0 .../spring-mvc-java-2}/src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/companyHome.jsp | 0 .../src/main/webapp/WEB-INF/view/companyView.jsp | 0 .../src/main/webapp/WEB-INF/view/employeeHome.jsp | 0 .../src/main/webapp/WEB-INF/view/employeeView.jsp | 0 .../spring-mvc-java-2}/src/main/webapp/WEB-INF/web.xml | 0 .../spring-mvc-java-2}/src/main/webapp/resources/hello.css | 0 .../baeldung/cache/CacheControlControllerIntegrationTest.java | 0 .../java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java | 0 .../java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java | 0 .../baeldung/multipart/file/ConvertMultipartFileUnitTest.java | 0 .../MultipartPostRequestControllerUnitTest.java | 0 29 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/.gitignore (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/README.md (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/pom.xml (97%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/cache/CacheControlController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/cache/CacheWebConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/datetime/DateTimeConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/datetime/DateTimeController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/controller/CompanyController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/controller/EmployeeController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/model/Company.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/model/Employee.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/resources/targetFile.tmp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/companyHome.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/companyView.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/employeeHome.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/employeeView.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/resources/hello.css (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java (100%) diff --git a/spring-mvc-java-2/.gitignore b/spring-web-modules/spring-mvc-java-2/.gitignore similarity index 100% rename from spring-mvc-java-2/.gitignore rename to spring-web-modules/spring-mvc-java-2/.gitignore diff --git a/spring-mvc-java-2/README.md b/spring-web-modules/spring-mvc-java-2/README.md similarity index 100% rename from spring-mvc-java-2/README.md rename to spring-web-modules/spring-mvc-java-2/README.md diff --git a/spring-mvc-java-2/pom.xml b/spring-web-modules/spring-mvc-java-2/pom.xml similarity index 97% rename from spring-mvc-java-2/pom.xml rename to spring-web-modules/spring-mvc-java-2/pom.xml index 533a24771a..8a025defac 100644 --- a/spring-mvc-java-2/pom.xml +++ b/spring-web-modules/spring-mvc-java-2/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java diff --git a/spring-mvc-java-2/src/main/resources/targetFile.tmp b/spring-web-modules/spring-mvc-java-2/src/main/resources/targetFile.tmp similarity index 100% rename from spring-mvc-java-2/src/main/resources/targetFile.tmp rename to spring-web-modules/spring-mvc-java-2/src/main/resources/targetFile.tmp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-java-2/src/main/webapp/resources/hello.css b/spring-web-modules/spring-mvc-java-2/src/main/webapp/resources/hello.css similarity index 100% rename from spring-mvc-java-2/src/main/webapp/resources/hello.css rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/resources/hello.css diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java From 824fd5496f94c2bae686ec94c183a043cb64481e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:46:11 +0530 Subject: [PATCH 402/590] Added module to new parent's pom --- spring-web-modules/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 730647d9e2..b41033bc30 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,8 @@ spring-mvc-crash spring-mvc-forms-jsp spring-mvc-forms-thymeleaf + spring-mvc-java + spring-mvc-java-2 spring-thymeleaf spring-thymeleaf-2 From 4eec2e35a290fe470351cc733d4718ccdd2b0590 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:46:47 +0530 Subject: [PATCH 403/590] Removed modules from main pom --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7db1c5bc54..e6cb9fd686 100644 --- a/pom.xml +++ b/pom.xml @@ -658,9 +658,6 @@ spring-mobile spring-mockito - spring-mvc-java - spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow @@ -1129,9 +1126,6 @@ spring-mobile spring-mockito - spring-mvc-java - spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow From 1c07f40727bac7e91007cd4e46b62459ad24f1b1 Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 29 Dec 2020 20:31:13 +0100 Subject: [PATCH 404/590] JAVA-3523 Move spring-rest-angular module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-angular}/README.md | 0 .../spring-rest-angular}/pom.xml | 2 +- .../src/main/java/com/baeldung/web/dao/StudentRepository.java | 0 .../src/main/java/com/baeldung/web/entity/Student.java | 0 .../com/baeldung/web/exception/MyResourceNotFoundException.java | 0 .../src/main/java/com/baeldung/web/main/Application.java | 0 .../src/main/java/com/baeldung/web/main/PersistenceConfig.java | 0 .../com/baeldung/web/rest/StudentDirectoryRestController.java | 0 .../src/main/java/com/baeldung/web/service/IOperations.java | 0 .../src/main/java/com/baeldung/web/service/StudentService.java | 0 .../main/java/com/baeldung/web/service/StudentServiceImpl.java | 0 .../src/main/resources/application.properties | 0 .../spring-rest-angular}/src/main/resources/data.sql | 0 .../spring-rest-angular}/src/main/resources/logback.xml | 0 .../spring-rest-angular}/src/main/webapp/WEB-INF/web.xml | 0 .../spring-rest-angular}/src/main/webapp/index.html | 0 .../spring-rest-angular}/src/main/webapp/view/app.js | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../com/baeldung/web/service/StudentServiceIntegrationTest.java | 0 21 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/README.md (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/pom.xml (97%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/dao/StudentRepository.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/entity/Student.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/main/Application.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/main/PersistenceConfig.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/rest/StudentDirectoryRestController.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/service/IOperations.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/service/StudentService.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/java/com/baeldung/web/service/StudentServiceImpl.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/resources/application.properties (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/resources/data.sql (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/resources/logback.xml (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/webapp/index.html (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/main/webapp/view/app.js (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-angular => spring-web-modules/spring-rest-angular}/src/test/java/com/baeldung/web/service/StudentServiceIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..dbada3d4dd 100644 --- a/pom.xml +++ b/pom.xml @@ -672,7 +672,6 @@ spring-reactor spring-remoting - spring-rest-angular spring-rest-http-2 spring-rest-query-language spring-rest-shell @@ -1142,7 +1141,6 @@ spring-reactor spring-remoting - spring-rest-angular spring-rest-query-language spring-rest-shell spring-rest-simple diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..3fc89f7717 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-rest-angular spring-rest-http spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-angular/README.md b/spring-web-modules/spring-rest-angular/README.md similarity index 100% rename from spring-rest-angular/README.md rename to spring-web-modules/spring-rest-angular/README.md diff --git a/spring-rest-angular/pom.xml b/spring-web-modules/spring-rest-angular/pom.xml similarity index 97% rename from spring-rest-angular/pom.xml rename to spring-web-modules/spring-rest-angular/pom.xml index 1d50b4c76c..eb1ec8696c 100644 --- a/spring-rest-angular/pom.xml +++ b/spring-web-modules/spring-rest-angular/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/dao/StudentRepository.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/dao/StudentRepository.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/dao/StudentRepository.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/dao/StudentRepository.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/entity/Student.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/entity/Student.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/entity/Student.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/entity/Student.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/main/Application.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/main/Application.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/main/Application.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/main/Application.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/main/PersistenceConfig.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/main/PersistenceConfig.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/main/PersistenceConfig.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/main/PersistenceConfig.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/rest/StudentDirectoryRestController.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/rest/StudentDirectoryRestController.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/rest/StudentDirectoryRestController.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/rest/StudentDirectoryRestController.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/service/IOperations.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/IOperations.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/service/IOperations.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/IOperations.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentService.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentService.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/service/StudentService.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentService.java diff --git a/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentServiceImpl.java b/spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentServiceImpl.java similarity index 100% rename from spring-rest-angular/src/main/java/com/baeldung/web/service/StudentServiceImpl.java rename to spring-web-modules/spring-rest-angular/src/main/java/com/baeldung/web/service/StudentServiceImpl.java diff --git a/spring-rest-angular/src/main/resources/application.properties b/spring-web-modules/spring-rest-angular/src/main/resources/application.properties similarity index 100% rename from spring-rest-angular/src/main/resources/application.properties rename to spring-web-modules/spring-rest-angular/src/main/resources/application.properties diff --git a/spring-rest-angular/src/main/resources/data.sql b/spring-web-modules/spring-rest-angular/src/main/resources/data.sql similarity index 100% rename from spring-rest-angular/src/main/resources/data.sql rename to spring-web-modules/spring-rest-angular/src/main/resources/data.sql diff --git a/spring-rest-angular/src/main/resources/logback.xml b/spring-web-modules/spring-rest-angular/src/main/resources/logback.xml similarity index 100% rename from spring-rest-angular/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-angular/src/main/resources/logback.xml diff --git a/spring-rest-angular/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-angular/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-angular/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-angular/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-angular/src/main/webapp/index.html b/spring-web-modules/spring-rest-angular/src/main/webapp/index.html similarity index 100% rename from spring-rest-angular/src/main/webapp/index.html rename to spring-web-modules/spring-rest-angular/src/main/webapp/index.html diff --git a/spring-rest-angular/src/main/webapp/view/app.js b/spring-web-modules/spring-rest-angular/src/main/webapp/view/app.js similarity index 100% rename from spring-rest-angular/src/main/webapp/view/app.js rename to spring-web-modules/spring-rest-angular/src/main/webapp/view/app.js diff --git a/spring-rest-angular/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-angular/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-angular/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-angular/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-angular/src/test/java/com/baeldung/web/service/StudentServiceIntegrationTest.java b/spring-web-modules/spring-rest-angular/src/test/java/com/baeldung/web/service/StudentServiceIntegrationTest.java similarity index 100% rename from spring-rest-angular/src/test/java/com/baeldung/web/service/StudentServiceIntegrationTest.java rename to spring-web-modules/spring-rest-angular/src/test/java/com/baeldung/web/service/StudentServiceIntegrationTest.java From e0ad1261c04fdadcf4490db438324184f4519d89 Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 29 Dec 2020 22:31:40 +0100 Subject: [PATCH 405/590] JAVA-3529 Move spring-mvc-views module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-mvc-views}/README.md | 0 .../spring-mvc-views}/pom.xml | 2 +- .../main/java/com/baeldung/themes/config/DataSourceConfig.java | 0 .../src/main/java/com/baeldung/themes/config/InitSecurity.java | 0 .../main/java/com/baeldung/themes/config/SecurityConfig.java | 0 .../main/java/com/baeldung/themes/config/ThemeMVCConfig.java | 0 .../baeldung/themes/config/TilesApplicationConfiguration.java | 0 .../main/java/com/baeldung/themes/config/WebInitializer.java | 0 .../java/com/baeldung/themes/controllers/AppController.java | 0 .../java/com/baeldung/themes/controllers/TilesController.java | 0 .../main/java/com/baeldung/themes/domain/UserPreference.java | 0 .../baeldung/themes/repository/UserPreferenceRepository.java | 0 .../baeldung/themes/resolver/UserPreferenceThemeResolver.java | 0 .../spring-mvc-views}/src/main/resources/dark.properties | 0 .../spring-mvc-views}/src/main/resources/dark_en_US.properties | 0 .../spring-mvc-views}/src/main/resources/db/sql/create-db.sql | 0 .../spring-mvc-views}/src/main/resources/db/sql/insert-data.sql | 0 .../spring-mvc-views}/src/main/resources/light.properties | 0 .../spring-mvc-views}/src/main/resources/light_en_US.properties | 0 .../spring-mvc-views}/src/main/resources/themes/black.css | 0 .../spring-mvc-views}/src/main/resources/themes/white.css | 0 .../spring-mvc-views}/src/main/webapp/WEB-INF/index.jsp | 0 .../src/main/webapp/WEB-INF/views/pages/apachetiles.jsp | 0 .../src/main/webapp/WEB-INF/views/pages/home.jsp | 0 .../src/main/webapp/WEB-INF/views/pages/springmvc.jsp | 0 .../main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp | 0 .../main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp | 0 .../main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp | 0 .../main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp | 0 .../src/main/webapp/WEB-INF/views/tiles/tiles.xml | 0 .../spring-mvc-views}/src/main/webapp/static/css/app.css | 0 33 files changed, 2 insertions(+), 3 deletions(-) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/README.md (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/pom.xml (98%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/DataSourceConfig.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/InitSecurity.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/SecurityConfig.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/ThemeMVCConfig.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/config/WebInitializer.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/controllers/AppController.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/controllers/TilesController.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/domain/UserPreference.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/repository/UserPreferenceRepository.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/java/com/baeldung/themes/resolver/UserPreferenceThemeResolver.java (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/dark.properties (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/dark_en_US.properties (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/db/sql/create-db.sql (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/db/sql/insert-data.sql (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/light.properties (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/light_en_US.properties (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/themes/black.css (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/resources/themes/white.css (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/index.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/pages/home.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/pages/springmvc.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/tiles.xml (100%) rename {spring-mvc-views => spring-web-modules/spring-mvc-views}/src/main/webapp/static/css/app.css (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..3e360b58cc 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-views spring-mvc-webflow spring-mvc-xml @@ -1133,7 +1132,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-views spring-mvc-webflow spring-mvc-xml diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..1da3612493 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-views spring-rest-http spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-mvc-views/README.md b/spring-web-modules/spring-mvc-views/README.md similarity index 100% rename from spring-mvc-views/README.md rename to spring-web-modules/spring-mvc-views/README.md diff --git a/spring-mvc-views/pom.xml b/spring-web-modules/spring-mvc-views/pom.xml similarity index 98% rename from spring-mvc-views/pom.xml rename to spring-web-modules/spring-mvc-views/pom.xml index 452805bd53..2c3be5a33e 100644 --- a/spring-mvc-views/pom.xml +++ b/spring-web-modules/spring-mvc-views/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-5 0.0.1-SNAPSHOT - ../parent-spring-5 + parent-spring-5/pom.xml diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/DataSourceConfig.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/DataSourceConfig.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/DataSourceConfig.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/DataSourceConfig.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/InitSecurity.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/InitSecurity.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/InitSecurity.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/InitSecurity.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/SecurityConfig.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/SecurityConfig.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/SecurityConfig.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/SecurityConfig.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/ThemeMVCConfig.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/ThemeMVCConfig.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/ThemeMVCConfig.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/ThemeMVCConfig.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/AppController.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/AppController.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/controllers/AppController.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/AppController.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/domain/UserPreference.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/domain/UserPreference.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/domain/UserPreference.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/domain/UserPreference.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/repository/UserPreferenceRepository.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/repository/UserPreferenceRepository.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/repository/UserPreferenceRepository.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/repository/UserPreferenceRepository.java diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/resolver/UserPreferenceThemeResolver.java b/spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/resolver/UserPreferenceThemeResolver.java similarity index 100% rename from spring-mvc-views/src/main/java/com/baeldung/themes/resolver/UserPreferenceThemeResolver.java rename to spring-web-modules/spring-mvc-views/src/main/java/com/baeldung/themes/resolver/UserPreferenceThemeResolver.java diff --git a/spring-mvc-views/src/main/resources/dark.properties b/spring-web-modules/spring-mvc-views/src/main/resources/dark.properties similarity index 100% rename from spring-mvc-views/src/main/resources/dark.properties rename to spring-web-modules/spring-mvc-views/src/main/resources/dark.properties diff --git a/spring-mvc-views/src/main/resources/dark_en_US.properties b/spring-web-modules/spring-mvc-views/src/main/resources/dark_en_US.properties similarity index 100% rename from spring-mvc-views/src/main/resources/dark_en_US.properties rename to spring-web-modules/spring-mvc-views/src/main/resources/dark_en_US.properties diff --git a/spring-mvc-views/src/main/resources/db/sql/create-db.sql b/spring-web-modules/spring-mvc-views/src/main/resources/db/sql/create-db.sql similarity index 100% rename from spring-mvc-views/src/main/resources/db/sql/create-db.sql rename to spring-web-modules/spring-mvc-views/src/main/resources/db/sql/create-db.sql diff --git a/spring-mvc-views/src/main/resources/db/sql/insert-data.sql b/spring-web-modules/spring-mvc-views/src/main/resources/db/sql/insert-data.sql similarity index 100% rename from spring-mvc-views/src/main/resources/db/sql/insert-data.sql rename to spring-web-modules/spring-mvc-views/src/main/resources/db/sql/insert-data.sql diff --git a/spring-mvc-views/src/main/resources/light.properties b/spring-web-modules/spring-mvc-views/src/main/resources/light.properties similarity index 100% rename from spring-mvc-views/src/main/resources/light.properties rename to spring-web-modules/spring-mvc-views/src/main/resources/light.properties diff --git a/spring-mvc-views/src/main/resources/light_en_US.properties b/spring-web-modules/spring-mvc-views/src/main/resources/light_en_US.properties similarity index 100% rename from spring-mvc-views/src/main/resources/light_en_US.properties rename to spring-web-modules/spring-mvc-views/src/main/resources/light_en_US.properties diff --git a/spring-mvc-views/src/main/resources/themes/black.css b/spring-web-modules/spring-mvc-views/src/main/resources/themes/black.css similarity index 100% rename from spring-mvc-views/src/main/resources/themes/black.css rename to spring-web-modules/spring-mvc-views/src/main/resources/themes/black.css diff --git a/spring-mvc-views/src/main/resources/themes/white.css b/spring-web-modules/spring-mvc-views/src/main/resources/themes/white.css similarity index 100% rename from spring-mvc-views/src/main/resources/themes/white.css rename to spring-web-modules/spring-mvc-views/src/main/resources/themes/white.css diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/index.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/index.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/index.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/index.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml b/spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml similarity index 100% rename from spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml rename to spring-web-modules/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml diff --git a/spring-mvc-views/src/main/webapp/static/css/app.css b/spring-web-modules/spring-mvc-views/src/main/webapp/static/css/app.css similarity index 100% rename from spring-mvc-views/src/main/webapp/static/css/app.css rename to spring-web-modules/spring-mvc-views/src/main/webapp/static/css/app.css From 55d36768129a31ff428fc77b230d0b011659dc7b Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 29 Dec 2020 22:56:18 +0100 Subject: [PATCH 406/590] JAVA-3530 Move spring-mvc-webflow module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-mvc-webflow}/README.md | 0 .../spring-mvc-webflow}/pom.xml | 0 .../src/main/java/org/baeldung/servlet/WebInitializer.java | 0 .../src/main/java/org/baeldung/spring/WebFlowConfig.java | 0 .../src/main/java/org/baeldung/spring/WebMvcConfig.java | 0 .../spring-mvc-webflow}/src/main/resources/flow-definition.xml | 0 .../spring-mvc-webflow}/src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/flows/activation-flow.xml | 0 .../src/main/webapp/WEB-INF/view/activation.jsp | 0 .../src/main/webapp/WEB-INF/view/failure.jsp | 0 .../spring-mvc-webflow}/src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/view/success.jsp | 0 .../src/test/java/org/baeldung/SpringContextTest.java | 0 15 files changed, 1 insertion(+), 2 deletions(-) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/README.md (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/pom.xml (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/java/org/baeldung/servlet/WebInitializer.java (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/java/org/baeldung/spring/WebFlowConfig.java (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/java/org/baeldung/spring/WebMvcConfig.java (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/resources/flow-definition.xml (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/resources/logback.xml (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/webapp/WEB-INF/flows/activation-flow.xml (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/webapp/WEB-INF/view/activation.jsp (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/webapp/WEB-INF/view/failure.jsp (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/main/webapp/WEB-INF/view/success.jsp (100%) rename {spring-mvc-webflow => spring-web-modules/spring-mvc-webflow}/src/test/java/org/baeldung/SpringContextTest.java (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..a0c412de9c 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-mvc-velocity spring-mvc-views - spring-mvc-webflow spring-mvc-xml spring-protobuf @@ -1134,7 +1133,6 @@ spring-mvc-velocity spring-mvc-views - spring-mvc-webflow spring-mvc-xml spring-protobuf diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..8c426fe9c0 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-webflow spring-rest-http spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-mvc-webflow/README.md b/spring-web-modules/spring-mvc-webflow/README.md similarity index 100% rename from spring-mvc-webflow/README.md rename to spring-web-modules/spring-mvc-webflow/README.md diff --git a/spring-mvc-webflow/pom.xml b/spring-web-modules/spring-mvc-webflow/pom.xml similarity index 100% rename from spring-mvc-webflow/pom.xml rename to spring-web-modules/spring-mvc-webflow/pom.xml diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java b/spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java similarity index 100% rename from spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java rename to spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java b/spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java similarity index 100% rename from spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java rename to spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java b/spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java similarity index 100% rename from spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java rename to spring-web-modules/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java diff --git a/spring-mvc-webflow/src/main/resources/flow-definition.xml b/spring-web-modules/spring-mvc-webflow/src/main/resources/flow-definition.xml similarity index 100% rename from spring-mvc-webflow/src/main/resources/flow-definition.xml rename to spring-web-modules/spring-mvc-webflow/src/main/resources/flow-definition.xml diff --git a/spring-mvc-webflow/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-webflow/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-webflow/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-webflow/src/main/resources/logback.xml diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml b/spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml similarity index 100% rename from spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml rename to spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp b/spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp similarity index 100% rename from spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp rename to spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp b/spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp similarity index 100% rename from spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp rename to spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp b/spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp similarity index 100% rename from spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp rename to spring-web-modules/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp diff --git a/spring-mvc-webflow/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-webflow/src/test/java/org/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-webflow/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-webflow/src/test/java/org/baeldung/SpringContextTest.java From 1cc511ae5e2d554ee3fcd5e250dccf68e88ea61d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 Dec 2020 13:32:07 +0530 Subject: [PATCH 407/590] BAEL-4301 - Updated assertTrue to assertEqual - Added examples --- .../CharacterGeneralCategoryTypeUnitTest.java | 13 ++++++------ .../character/IsLetterOrAlphabetUnitTest.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java index 4bb41211a9..9fab13df45 100644 --- a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java @@ -3,35 +3,36 @@ package com.baeldung.character; import org.junit.Test; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; public class CharacterGeneralCategoryTypeUnitTest { @Test public void givenACharacter_whenUpperCaseLetter_thenAssertTrue() { - assertTrue(Character.getType('U') == Character.UPPERCASE_LETTER); + assertEquals(Character.UPPERCASE_LETTER, Character.getType('U')); } @Test public void givenACharacter_whenLowerCaseLetter_thenAssertTrue() { - assertTrue(Character.getType('u') == Character.LOWERCASE_LETTER); + assertEquals(Character.LOWERCASE_LETTER, Character.getType('u')); } @Test public void givenACharacter_whenTitleCaseLetter_thenAssertTrue() { - assertTrue(Character.getType('\u01f2') == Character.TITLECASE_LETTER); + assertEquals(Character.TITLECASE_LETTER, Character.getType('\u01f2')); } @Test public void givenACharacter_whenModifierLetter_thenAssertTrue() { - assertTrue(Character.getType('\u02b0') == Character.MODIFIER_LETTER); + assertEquals(Character.MODIFIER_LETTER, Character.getType('\u02b0')); } @Test public void givenACharacter_whenOtherLetter_thenAssertTrue() { - assertTrue(Character.getType('\u05d0') == Character.OTHER_LETTER); + assertEquals(Character.OTHER_LETTER, Character.getType('\u05d0')); } @Test public void givenACharacter_whenLetterNumber_thenAssertTrue() { - assertTrue(Character.getType('\u2164') == Character.LETTER_NUMBER); + assertEquals(Character.LETTER_NUMBER, Character.getType('\u2164')); } } diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java index 734762ec7b..3de3a16e6a 100644 --- a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java @@ -6,6 +6,27 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; public class IsLetterOrAlphabetUnitTest { + + @Test + public void givenACharacter_whenUpperCaseLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic('A')); + } + + @Test + public void givenACharacter_whenTitleCaseLetter_thenAssertIsAlphabeticTrue() { + assertTrue(Character.isAlphabetic('\u01f2')); + } + + @Test + public void givenACharacter_whenLowerCaseLetter_thenAssertIsLetterTrue() { + assertTrue(Character.isAlphabetic('a')); + } + + @Test + public void givenACharacter_whenModifierLetter_thenAssertIsLetterTrue() { + assertTrue(Character.isAlphabetic('\u02b0')); + } + @Test public void givenACharacter_whenLetter_thenAssertIsLetterTrue() { assertTrue(Character.isLetter('a')); From 9b808b2fde14d6be5e7fd95254936ff09e824181 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 30 Dec 2020 16:34:08 +0800 Subject: [PATCH 408/590] Update README.md --- spring-cloud/spring-cloud-eureka/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-eureka/README.md b/spring-cloud/spring-cloud-eureka/README.md index badf4c8d50..5fc96256f4 100644 --- a/spring-cloud/spring-cloud-eureka/README.md +++ b/spring-cloud/spring-cloud-eureka/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Introduction to Spring Cloud Netflix – Eureka](http://www.baeldung.com/spring-cloud-netflix-eureka) +- [Integration Tests With Spring Cloud Netflix and Feign](https://www.baeldung.com/spring-cloud-feign-integration-tests) From c99f74a6a1b316a15bc68bfb4477afdf829ba4bd Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 12:14:14 +0100 Subject: [PATCH 409/590] JAVA-3535 Move spring rest query language module --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-rest-query-language}/.gitignore | 0 .../spring-rest-query-language}/README.md | 0 .../spring-rest-query-language}/pom.xml | 2 +- .../dao/GenericSpecificationsBuilder.java | 200 +++++----- .../baeldung/persistence/dao/IUserDAO.java | 0 .../persistence/dao/MyUserPredicate.java | 0 .../dao/MyUserPredicatesBuilder.java | 0 .../persistence/dao/MyUserRepository.java | 0 .../com/baeldung/persistence/dao/UserDAO.java | 0 .../persistence/dao/UserRepository.java | 0 .../dao/UserSearchQueryCriteriaConsumer.java | 0 .../persistence/dao/UserSpecification.java | 0 .../dao/UserSpecificationsBuilder.java | 140 +++---- .../dao/rsql/CustomRsqlVisitor.java | 0 .../dao/rsql/GenericRsqlSpecBuilder.java | 0 .../dao/rsql/GenericRsqlSpecification.java | 0 .../dao/rsql/RsqlSearchOperation.java | 0 .../baeldung/persistence/model/MyUser.java | 0 .../com/baeldung/persistence/model/User.java | 0 .../com/baeldung/persistence/model/User_.java | 0 .../java/com/baeldung/spring/Application.java | 0 .../baeldung/spring/PersistenceConfig.java | 0 .../java/com/baeldung/spring/WebConfig.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/UserController.java | 342 ++++++++--------- .../RestResponseEntityExceptionHandler.java | 0 .../MyResourceNotFoundException.java | 0 .../com/baeldung/web/util/CriteriaParser.java | 0 .../com/baeldung/web/util/SearchCriteria.java | 0 .../baeldung/web/util/SearchOperation.java | 72 ++-- .../baeldung/web/util/SpecSearchCriteria.java | 164 ++++---- .../src/main/resources/application.properties | 0 .../src/main/resources/data.sql | 0 .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../JPACriteriaQueryIntegrationTest.java | 0 .../query/JPAQuerydslIntegrationTest.java | 0 .../JPASpecificationIntegrationTest.java | 360 +++++++++--------- .../query/JPASpecificationLiveTest.java | 294 +++++++------- .../query/RsqlIntegrationTest.java | 0 .../java/com/baeldung/web/MyUserLiveTest.java | 0 .../src/test/resources/.gitignore | 0 50 files changed, 788 insertions(+), 789 deletions(-) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/.gitignore (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/README.md (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/pom.xml (99%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/IUserDAO.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserDAO.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserRepository.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSpecification.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/MyUser.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/User_.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/WebConfig.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/controller/HomeController.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/controller/UserController.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/CriteriaParser.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SearchCriteria.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SearchOperation.java (96%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java (96%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/application.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/data.sql (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/logback.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/persistence-h2.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/persistence-mysql.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/web/MyUserLiveTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/resources/.gitignore (100%) diff --git a/pom.xml b/pom.xml index 79bf7d72b7..88b0a4e23d 100644 --- a/pom.xml +++ b/pom.xml @@ -674,7 +674,6 @@ spring-reactor spring-remoting spring-rest-http-2 - spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate @@ -1141,7 +1140,6 @@ spring-reactor spring-remoting - spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index ce0524f957..19ec1c2a74 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-rest-angular spring-rest-http + spring-rest-query-language spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-query-language/.gitignore b/spring-web-modules/spring-rest-query-language/.gitignore similarity index 100% rename from spring-rest-query-language/.gitignore rename to spring-web-modules/spring-rest-query-language/.gitignore diff --git a/spring-rest-query-language/README.md b/spring-web-modules/spring-rest-query-language/README.md similarity index 100% rename from spring-rest-query-language/README.md rename to spring-web-modules/spring-rest-query-language/README.md diff --git a/spring-rest-query-language/pom.xml b/spring-web-modules/spring-rest-query-language/pom.xml similarity index 99% rename from spring-rest-query-language/pom.xml rename to spring-web-modules/spring-rest-query-language/pom.xml index 4458aa0580..5e7ca023dd 100644 --- a/spring-rest-query-language/pom.xml +++ b/spring-web-modules/spring-rest-query-language/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java index 75fb4456c4..b6623e8885 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java @@ -1,100 +1,100 @@ -package com.baeldung.persistence.dao; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.springframework.data.jpa.domain.Specification; - -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -public class GenericSpecificationsBuilder { - - private final List params; - - public GenericSpecificationsBuilder() { - this.params = new ArrayList<>(); - } - - public final GenericSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { - return with(null, key, operation, value, prefix, suffix); - } - - public final GenericSpecificationsBuilder with(final String precedenceIndicator, final String key, final String operation, final Object value, final String prefix, final String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) // the operation may be complex operation - { - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - params.add(new SpecSearchCriteria(precedenceIndicator, key, op, value)); - } - return this; - } - - public Specification build(Function> converter) { - - if (params.size() == 0) { - return null; - } - - final List> specs = params.stream() - .map(converter) - .collect(Collectors.toCollection(ArrayList::new)); - - Specification result = specs.get(0); - - for (int idx = 1; idx < specs.size(); idx++) { - result = params.get(idx) - .isOrPredicate() - ? Specification.where(result) - .or(specs.get(idx)) - : Specification.where(result) - .and(specs.get(idx)); - } - - return result; - } - - public Specification build(Deque postFixedExprStack, Function> converter) { - - Deque> specStack = new LinkedList<>(); - - Collections.reverse((List) postFixedExprStack); - - while (!postFixedExprStack.isEmpty()) { - Object mayBeOperand = postFixedExprStack.pop(); - - if (!(mayBeOperand instanceof String)) { - specStack.push(converter.apply((SpecSearchCriteria) mayBeOperand)); - } else { - Specification operand1 = specStack.pop(); - Specification operand2 = specStack.pop(); - if (mayBeOperand.equals(SearchOperation.AND_OPERATOR)) - specStack.push(Specification.where(operand1) - .and(operand2)); - else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR)) - specStack.push(Specification.where(operand1) - .or(operand2)); - } - - } - return specStack.pop(); - - } - -} +package com.baeldung.persistence.dao; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.springframework.data.jpa.domain.Specification; + +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +public class GenericSpecificationsBuilder { + + private final List params; + + public GenericSpecificationsBuilder() { + this.params = new ArrayList<>(); + } + + public final GenericSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { + return with(null, key, operation, value, prefix, suffix); + } + + public final GenericSpecificationsBuilder with(final String precedenceIndicator, final String key, final String operation, final Object value, final String prefix, final String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) // the operation may be complex operation + { + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + params.add(new SpecSearchCriteria(precedenceIndicator, key, op, value)); + } + return this; + } + + public Specification build(Function> converter) { + + if (params.size() == 0) { + return null; + } + + final List> specs = params.stream() + .map(converter) + .collect(Collectors.toCollection(ArrayList::new)); + + Specification result = specs.get(0); + + for (int idx = 1; idx < specs.size(); idx++) { + result = params.get(idx) + .isOrPredicate() + ? Specification.where(result) + .or(specs.get(idx)) + : Specification.where(result) + .and(specs.get(idx)); + } + + return result; + } + + public Specification build(Deque postFixedExprStack, Function> converter) { + + Deque> specStack = new LinkedList<>(); + + Collections.reverse((List) postFixedExprStack); + + while (!postFixedExprStack.isEmpty()) { + Object mayBeOperand = postFixedExprStack.pop(); + + if (!(mayBeOperand instanceof String)) { + specStack.push(converter.apply((SpecSearchCriteria) mayBeOperand)); + } else { + Specification operand1 = specStack.pop(); + Specification operand2 = specStack.pop(); + if (mayBeOperand.equals(SearchOperation.AND_OPERATOR)) + specStack.push(Specification.where(operand1) + .and(operand2)); + else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR)) + specStack.push(Specification.where(operand1) + .or(operand2)); + } + + } + return specStack.pop(); + + } + +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java index 72d7274226..eac1562294 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java @@ -1,70 +1,70 @@ -package com.baeldung.persistence.dao; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.data.jpa.domain.Specification; - -import com.baeldung.persistence.model.User; -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -public final class UserSpecificationsBuilder { - - private final List params; - - public UserSpecificationsBuilder() { - params = new ArrayList<>(); - } - - // API - - public final UserSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { - return with(null, key, operation, value, prefix, suffix); - } - - public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) { // the operation may be complex operation - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - params.add(new SpecSearchCriteria(orPredicate, key, op, value)); - } - return this; - } - - public Specification build() { - if (params.size() == 0) - return null; - - Specification result = new UserSpecification(params.get(0)); - - for (int i = 1; i < params.size(); i++) { - result = params.get(i).isOrPredicate() - ? Specification.where(result).or(new UserSpecification(params.get(i))) - : Specification.where(result).and(new UserSpecification(params.get(i))); - } - - return result; - } - - public final UserSpecificationsBuilder with(UserSpecification spec) { - params.add(spec.getCriteria()); - return this; - } - - public final UserSpecificationsBuilder with(SpecSearchCriteria criteria) { - params.add(criteria); - return this; - } -} +package com.baeldung.persistence.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.data.jpa.domain.Specification; + +import com.baeldung.persistence.model.User; +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +public final class UserSpecificationsBuilder { + + private final List params; + + public UserSpecificationsBuilder() { + params = new ArrayList<>(); + } + + // API + + public final UserSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { + return with(null, key, operation, value, prefix, suffix); + } + + public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) { // the operation may be complex operation + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + params.add(new SpecSearchCriteria(orPredicate, key, op, value)); + } + return this; + } + + public Specification build() { + if (params.size() == 0) + return null; + + Specification result = new UserSpecification(params.get(0)); + + for (int i = 1; i < params.size(); i++) { + result = params.get(i).isOrPredicate() + ? Specification.where(result).or(new UserSpecification(params.get(i))) + : Specification.where(result).and(new UserSpecification(params.get(i))); + } + + return result; + } + + public final UserSpecificationsBuilder with(UserSpecification spec) { + params.add(spec.getCriteria()); + return this; + } + + public final UserSpecificationsBuilder with(SpecSearchCriteria criteria) { + params.add(criteria); + return this; + } +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java index 54e8618b27..73a97f84ae 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java @@ -1,171 +1,171 @@ -package com.baeldung.web.controller; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.querydsl.binding.QuerydslPredicate; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -import com.baeldung.persistence.dao.GenericSpecificationsBuilder; -import com.baeldung.persistence.dao.IUserDAO; -import com.baeldung.persistence.dao.MyUserPredicatesBuilder; -import com.baeldung.persistence.dao.MyUserRepository; -import com.baeldung.persistence.dao.UserRepository; -import com.baeldung.persistence.dao.UserSpecification; -import com.baeldung.persistence.dao.UserSpecificationsBuilder; -import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor; -import com.baeldung.persistence.model.MyUser; -import com.baeldung.persistence.model.User; -import com.baeldung.web.util.CriteriaParser; -import com.baeldung.web.util.SearchCriteria; -import com.baeldung.web.util.SearchOperation; -import com.google.common.base.Joiner; -import com.google.common.base.Preconditions; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; - -import cz.jirutka.rsql.parser.RSQLParser; -import cz.jirutka.rsql.parser.ast.Node; - -//@EnableSpringDataWebSupport -@Controller -@RequestMapping(value = "/auth/") -public class UserController { - - @Autowired - private IUserDAO service; - - @Autowired - private UserRepository dao; - - @Autowired - private MyUserRepository myUserRepository; - - public UserController() { - super(); - } - - // API - READ - - @RequestMapping(method = RequestMethod.GET, value = "/users") - @ResponseBody - public List search(@RequestParam(value = "search", required = false) String search) { - List params = new ArrayList(); - if (search != null) { - Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); - } - } - return service.searchUser(params); - } - - @RequestMapping(method = RequestMethod.GET, value = "/users/spec") - @ResponseBody - public List findAllBySpecification(@RequestParam(value = "search") String search) { - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - String operationSetExper = Joiner.on("|") - .join(SearchOperation.SIMPLE_OPERATION_SET); - Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); - } - - Specification spec = builder.build(); - return dao.findAll(spec); - } - - @GetMapping(value = "/users/espec") - @ResponseBody - public List findAllByOrPredicate(@RequestParam(value = "search") String search) { - Specification spec = resolveSpecification(search); - return dao.findAll(spec); - } - - @GetMapping(value = "/users/spec/adv") - @ResponseBody - public List findAllByAdvPredicate(@RequestParam(value = "search") String search) { - Specification spec = resolveSpecificationFromInfixExpr(search); - return dao.findAll(spec); - } - - protected Specification resolveSpecificationFromInfixExpr(String searchParameters) { - CriteriaParser parser = new CriteriaParser(); - GenericSpecificationsBuilder specBuilder = new GenericSpecificationsBuilder<>(); - return specBuilder.build(parser.parse(searchParameters), UserSpecification::new); - } - - protected Specification resolveSpecification(String searchParameters) { - - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - String operationSetExper = Joiner.on("|") - .join(SearchOperation.SIMPLE_OPERATION_SET); - Pattern pattern = Pattern.compile("(\\p{Punct}?)(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); - Matcher matcher = pattern.matcher(searchParameters + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(5), matcher.group(4), matcher.group(6)); - } - return builder.build(); - } - - @RequestMapping(method = RequestMethod.GET, value = "/myusers") - @ResponseBody - public Iterable findAllByQuerydsl(@RequestParam(value = "search") String search) { - MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); - if (search != null) { - Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); - } - } - BooleanExpression exp = builder.build(); - return myUserRepository.findAll(exp); - } - - @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") - @ResponseBody - public List findAllByRsql(@RequestParam(value = "search") String search) { - Node rootNode = new RSQLParser().parse(search); - Specification spec = rootNode.accept(new CustomRsqlVisitor()); - return dao.findAll(spec); - } - - @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") - @ResponseBody - public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) { - return myUserRepository.findAll(predicate); - } - - // API - WRITE - - @RequestMapping(method = RequestMethod.POST, value = "/users") - @ResponseStatus(HttpStatus.CREATED) - public void create(@RequestBody User resource) { - Preconditions.checkNotNull(resource); - dao.save(resource); - } - - @RequestMapping(method = RequestMethod.POST, value = "/myusers") - @ResponseStatus(HttpStatus.CREATED) - public void addMyUser(@RequestBody MyUser resource) { - Preconditions.checkNotNull(resource); - myUserRepository.save(resource); - - } - -} +package com.baeldung.web.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.querydsl.binding.QuerydslPredicate; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import com.baeldung.persistence.dao.GenericSpecificationsBuilder; +import com.baeldung.persistence.dao.IUserDAO; +import com.baeldung.persistence.dao.MyUserPredicatesBuilder; +import com.baeldung.persistence.dao.MyUserRepository; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.dao.UserSpecification; +import com.baeldung.persistence.dao.UserSpecificationsBuilder; +import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor; +import com.baeldung.persistence.model.MyUser; +import com.baeldung.persistence.model.User; +import com.baeldung.web.util.CriteriaParser; +import com.baeldung.web.util.SearchCriteria; +import com.baeldung.web.util.SearchOperation; +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.BooleanExpression; + +import cz.jirutka.rsql.parser.RSQLParser; +import cz.jirutka.rsql.parser.ast.Node; + +//@EnableSpringDataWebSupport +@Controller +@RequestMapping(value = "/auth/") +public class UserController { + + @Autowired + private IUserDAO service; + + @Autowired + private UserRepository dao; + + @Autowired + private MyUserRepository myUserRepository; + + public UserController() { + super(); + } + + // API - READ + + @RequestMapping(method = RequestMethod.GET, value = "/users") + @ResponseBody + public List search(@RequestParam(value = "search", required = false) String search) { + List params = new ArrayList(); + if (search != null) { + Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); + } + } + return service.searchUser(params); + } + + @RequestMapping(method = RequestMethod.GET, value = "/users/spec") + @ResponseBody + public List findAllBySpecification(@RequestParam(value = "search") String search) { + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + String operationSetExper = Joiner.on("|") + .join(SearchOperation.SIMPLE_OPERATION_SET); + Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); + } + + Specification spec = builder.build(); + return dao.findAll(spec); + } + + @GetMapping(value = "/users/espec") + @ResponseBody + public List findAllByOrPredicate(@RequestParam(value = "search") String search) { + Specification spec = resolveSpecification(search); + return dao.findAll(spec); + } + + @GetMapping(value = "/users/spec/adv") + @ResponseBody + public List findAllByAdvPredicate(@RequestParam(value = "search") String search) { + Specification spec = resolveSpecificationFromInfixExpr(search); + return dao.findAll(spec); + } + + protected Specification resolveSpecificationFromInfixExpr(String searchParameters) { + CriteriaParser parser = new CriteriaParser(); + GenericSpecificationsBuilder specBuilder = new GenericSpecificationsBuilder<>(); + return specBuilder.build(parser.parse(searchParameters), UserSpecification::new); + } + + protected Specification resolveSpecification(String searchParameters) { + + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + String operationSetExper = Joiner.on("|") + .join(SearchOperation.SIMPLE_OPERATION_SET); + Pattern pattern = Pattern.compile("(\\p{Punct}?)(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); + Matcher matcher = pattern.matcher(searchParameters + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(5), matcher.group(4), matcher.group(6)); + } + return builder.build(); + } + + @RequestMapping(method = RequestMethod.GET, value = "/myusers") + @ResponseBody + public Iterable findAllByQuerydsl(@RequestParam(value = "search") String search) { + MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); + if (search != null) { + Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); + } + } + BooleanExpression exp = builder.build(); + return myUserRepository.findAll(exp); + } + + @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") + @ResponseBody + public List findAllByRsql(@RequestParam(value = "search") String search) { + Node rootNode = new RSQLParser().parse(search); + Specification spec = rootNode.accept(new CustomRsqlVisitor()); + return dao.findAll(spec); + } + + @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") + @ResponseBody + public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) { + return myUserRepository.findAll(predicate); + } + + // API - WRITE + + @RequestMapping(method = RequestMethod.POST, value = "/users") + @ResponseStatus(HttpStatus.CREATED) + public void create(@RequestBody User resource) { + Preconditions.checkNotNull(resource); + dao.save(resource); + } + + @RequestMapping(method = RequestMethod.POST, value = "/myusers") + @ResponseStatus(HttpStatus.CREATED) + public void addMyUser(@RequestBody MyUser resource) { + Preconditions.checkNotNull(resource); + myUserRepository.save(resource); + + } + +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java similarity index 96% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java index acc9e0c0a8..86ad9ad749 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java @@ -1,36 +1,36 @@ -package com.baeldung.web.util; - -public enum SearchOperation { - EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS; - - public static final String[] SIMPLE_OPERATION_SET = { ":", "!", ">", "<", "~" }; - - public static final String OR_PREDICATE_FLAG = "'"; - - public static final String ZERO_OR_MORE_REGEX = "*"; - - public static final String OR_OPERATOR = "OR"; - - public static final String AND_OPERATOR = "AND"; - - public static final String LEFT_PARANTHESIS = "("; - - public static final String RIGHT_PARANTHESIS = ")"; - - public static SearchOperation getSimpleOperation(final char input) { - switch (input) { - case ':': - return EQUALITY; - case '!': - return NEGATION; - case '>': - return GREATER_THAN; - case '<': - return LESS_THAN; - case '~': - return LIKE; - default: - return null; - } - } -} +package com.baeldung.web.util; + +public enum SearchOperation { + EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS; + + public static final String[] SIMPLE_OPERATION_SET = { ":", "!", ">", "<", "~" }; + + public static final String OR_PREDICATE_FLAG = "'"; + + public static final String ZERO_OR_MORE_REGEX = "*"; + + public static final String OR_OPERATOR = "OR"; + + public static final String AND_OPERATOR = "AND"; + + public static final String LEFT_PARANTHESIS = "("; + + public static final String RIGHT_PARANTHESIS = ")"; + + public static SearchOperation getSimpleOperation(final char input) { + switch (input) { + case ':': + return EQUALITY; + case '!': + return NEGATION; + case '>': + return GREATER_THAN; + case '<': + return LESS_THAN; + case '~': + return LIKE; + default: + return null; + } + } +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java similarity index 96% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java index 73b690673b..22b55c78fb 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java @@ -1,82 +1,82 @@ -package com.baeldung.web.util; - -public class SpecSearchCriteria { - - private String key; - private SearchOperation operation; - private Object value; - private boolean orPredicate; - - public SpecSearchCriteria() { - - } - - public SpecSearchCriteria(final String key, final SearchOperation operation, final Object value) { - super(); - this.key = key; - this.operation = operation; - this.value = value; - } - - public SpecSearchCriteria(final String orPredicate, final String key, final SearchOperation operation, final Object value) { - super(); - this.orPredicate = orPredicate != null && orPredicate.equals(SearchOperation.OR_PREDICATE_FLAG); - this.key = key; - this.operation = operation; - this.value = value; - } - - public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) { // the operation may be complex operation - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - } - this.key = key; - this.operation = op; - this.value = value; - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public SearchOperation getOperation() { - return operation; - } - - public void setOperation(final SearchOperation operation) { - this.operation = operation; - } - - public Object getValue() { - return value; - } - - public void setValue(final Object value) { - this.value = value; - } - - public boolean isOrPredicate() { - return orPredicate; - } - - public void setOrPredicate(boolean orPredicate) { - this.orPredicate = orPredicate; - } - -} +package com.baeldung.web.util; + +public class SpecSearchCriteria { + + private String key; + private SearchOperation operation; + private Object value; + private boolean orPredicate; + + public SpecSearchCriteria() { + + } + + public SpecSearchCriteria(final String key, final SearchOperation operation, final Object value) { + super(); + this.key = key; + this.operation = operation; + this.value = value; + } + + public SpecSearchCriteria(final String orPredicate, final String key, final SearchOperation operation, final Object value) { + super(); + this.orPredicate = orPredicate != null && orPredicate.equals(SearchOperation.OR_PREDICATE_FLAG); + this.key = key; + this.operation = operation; + this.value = value; + } + + public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) { // the operation may be complex operation + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + } + this.key = key; + this.operation = op; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public SearchOperation getOperation() { + return operation; + } + + public void setOperation(final SearchOperation operation) { + this.operation = operation; + } + + public Object getValue() { + return value; + } + + public void setValue(final Object value) { + this.value = value; + } + + public boolean isOrPredicate() { + return orPredicate; + } + + public void setOrPredicate(boolean orPredicate) { + this.orPredicate = orPredicate; + } + +} diff --git a/spring-rest-query-language/src/main/resources/application.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/application.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/application.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/application.properties diff --git a/spring-rest-query-language/src/main/resources/data.sql b/spring-web-modules/spring-rest-query-language/src/main/resources/data.sql similarity index 100% rename from spring-rest-query-language/src/main/resources/data.sql rename to spring-web-modules/spring-rest-query-language/src/main/resources/data.sql diff --git a/spring-rest-query-language/src/main/resources/logback.xml b/spring-web-modules/spring-rest-query-language/src/main/resources/logback.xml similarity index 100% rename from spring-rest-query-language/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-query-language/src/main/resources/logback.xml diff --git a/spring-rest-query-language/src/main/resources/persistence-h2.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/persistence-h2.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/persistence-h2.properties diff --git a/spring-rest-query-language/src/main/resources/persistence-mysql.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/persistence-mysql.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/persistence-mysql.properties diff --git a/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml b/spring-web-modules/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml rename to spring-web-modules/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java similarity index 97% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java index 707426769e..f6fff10506 100644 --- a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java +++ b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java @@ -1,180 +1,180 @@ -package com.baeldung.persistence.query; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.persistence.dao.GenericSpecificationsBuilder; -import com.baeldung.persistence.dao.UserRepository; -import com.baeldung.persistence.dao.UserSpecification; -import com.baeldung.persistence.dao.UserSpecificationsBuilder; -import com.baeldung.persistence.model.User; -import com.baeldung.spring.PersistenceConfig; -import com.baeldung.web.util.CriteriaParser; -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -import java.util.List; -import java.util.function.Function; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIn.isIn; -import static org.hamcrest.core.IsNot.not; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { PersistenceConfig.class }) -@Transactional -@Rollback -public class JPASpecificationIntegrationTest { - - @Autowired - private UserRepository repository; - - private User userJohn; - - private User userTom; - - private User userPercy; - - @Before - public void init() { - userJohn = new User(); - userJohn.setFirstName("john"); - userJohn.setLastName("doe"); - userJohn.setEmail("john@doe.com"); - userJohn.setAge(22); - repository.save(userJohn); - - userTom = new User(); - userTom.setFirstName("tom"); - userTom.setLastName("doe"); - userTom.setEmail("tom@doe.com"); - userTom.setAge(26); - repository.save(userTom); - - userPercy = new User(); - userPercy.setFirstName("percy"); - userPercy.setLastName("blackney"); - userPercy.setEmail("percy@blackney.com"); - userPercy.setAge(30); - repository.save(userPercy); - } - - @Test - public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john")); - final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe")); - final List results = repository.findAll(Specification - .where(spec) - .and(spec1)); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - - SpecSearchCriteria spec = new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"); - SpecSearchCriteria spec1 = new SpecSearchCriteria("'","lastName", SearchOperation.EQUALITY, "doe"); - - List results = repository.findAll(builder - .with(spec) - .with(spec1) - .build()); - - assertThat(results, hasSize(2)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, isIn(results)); - } - - @Test - public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() { - GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); - Function> converter = UserSpecification::new; - - CriteriaParser parser=new CriteriaParser(); - List results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter)); - - assertThat(results, hasSize(1)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstOrLastNameGenericBuilder_whenGettingListOfUsers_thenCorrect() { - GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); - Function> converter = UserSpecification::new; - - builder.with("firstName", ":", "john", null, null); - builder.with("'", "lastName", ":", "doe", null, null); - - List results = repository.findAll(builder.build(converter)); - - assertThat(results, hasSize(2)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, isIn(results)); - } - - @Test - public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john")); - final List results = repository.findAll(Specification.where(spec)); - - assertThat(userTom, isIn(results)); - assertThat(userJohn, not(isIn(results))); - } - - @Test - public void givenMinAge_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25")); - final List results = repository.findAll(Specification.where(spec)); - assertThat(userTom, isIn(results)); - assertThat(userJohn, not(isIn(results))); - } - - @Test - public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo")); - final List results = repository.findAll(spec); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.ENDS_WITH, "n")); - final List results = repository.findAll(spec); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.CONTAINS, "oh")); - final List results = repository.findAll(spec); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20")); - final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25")); - final List results = repository.findAll(Specification - .where(spec) - .and(spec1)); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } -} +package com.baeldung.persistence.query; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.persistence.dao.GenericSpecificationsBuilder; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.dao.UserSpecification; +import com.baeldung.persistence.dao.UserSpecificationsBuilder; +import com.baeldung.persistence.model.User; +import com.baeldung.spring.PersistenceConfig; +import com.baeldung.web.util.CriteriaParser; +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +import java.util.List; +import java.util.function.Function; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.hamcrest.collection.IsIn.isIn; +import static org.hamcrest.core.IsNot.not; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }) +@Transactional +@Rollback +public class JPASpecificationIntegrationTest { + + @Autowired + private UserRepository repository; + + private User userJohn; + + private User userTom; + + private User userPercy; + + @Before + public void init() { + userJohn = new User(); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); + userJohn.setEmail("john@doe.com"); + userJohn.setAge(22); + repository.save(userJohn); + + userTom = new User(); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); + userTom.setEmail("tom@doe.com"); + userTom.setAge(26); + repository.save(userTom); + + userPercy = new User(); + userPercy.setFirstName("percy"); + userPercy.setLastName("blackney"); + userPercy.setEmail("percy@blackney.com"); + userPercy.setAge(30); + repository.save(userPercy); + } + + @Test + public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john")); + final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe")); + final List results = repository.findAll(Specification + .where(spec) + .and(spec1)); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + + SpecSearchCriteria spec = new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"); + SpecSearchCriteria spec1 = new SpecSearchCriteria("'","lastName", SearchOperation.EQUALITY, "doe"); + + List results = repository.findAll(builder + .with(spec) + .with(spec1) + .build()); + + assertThat(results, hasSize(2)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, isIn(results)); + } + + @Test + public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() { + GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); + Function> converter = UserSpecification::new; + + CriteriaParser parser=new CriteriaParser(); + List results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter)); + + assertThat(results, hasSize(1)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstOrLastNameGenericBuilder_whenGettingListOfUsers_thenCorrect() { + GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); + Function> converter = UserSpecification::new; + + builder.with("firstName", ":", "john", null, null); + builder.with("'", "lastName", ":", "doe", null, null); + + List results = repository.findAll(builder.build(converter)); + + assertThat(results, hasSize(2)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, isIn(results)); + } + + @Test + public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john")); + final List results = repository.findAll(Specification.where(spec)); + + assertThat(userTom, isIn(results)); + assertThat(userJohn, not(isIn(results))); + } + + @Test + public void givenMinAge_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25")); + final List results = repository.findAll(Specification.where(spec)); + assertThat(userTom, isIn(results)); + assertThat(userJohn, not(isIn(results))); + } + + @Test + public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo")); + final List results = repository.findAll(spec); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.ENDS_WITH, "n")); + final List results = repository.findAll(spec); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.CONTAINS, "oh")); + final List results = repository.findAll(spec); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20")); + final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25")); + final List results = repository.findAll(Specification + .where(spec) + .and(spec1)); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } +} diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java similarity index 97% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java index ad6a4259e7..d1fded3f10 100644 --- a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java +++ b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java @@ -1,147 +1,147 @@ -package com.baeldung.persistence.query; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import io.restassured.RestAssured; -import io.restassured.response.Response; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.test.context.ActiveProfiles; - -import com.baeldung.persistence.model.User; - -//@RunWith(SpringJUnit4ClassRunner.class) -//@ContextConfiguration(classes = { ConfigTest.class, -// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) -@ActiveProfiles("test") -public class JPASpecificationLiveTest { - - // @Autowired - // private UserRepository repository; - - private User userJohn; - - private User userTom; - - private final String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec?search="; - - @Before - public void init() { - userJohn = new User(); - userJohn.setFirstName("john"); - userJohn.setLastName("doe"); - userJohn.setEmail("john@doe.com"); - userJohn.setAge(22); - // repository.save(userJohn); - - userTom = new User(); - userTom.setFirstName("tom"); - userTom.setLastName("doe"); - userTom.setEmail("tom@doe.com"); - userTom.setAge(26); - // repository.save(userTom); - } - - private final String EURL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/espec?search="; - - @Test - public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); - final String result = response.body() - .asString(); - assertTrue(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName!john"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userTom.getEmail())); - assertFalse(result.contains(userJohn.getEmail())); - } - - @Test - public void givenMinAge_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "age>25"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userTom.getEmail())); - assertFalse(result.contains(userJohn.getEmail())); - } - - @Test - public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:jo*"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "age>20,age<25"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - private final String ADV_URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec/adv?search="; - - @Test - public void givenFirstOrLastName_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = RestAssured.get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); - final String result = response.body() - .asString(); - assertTrue(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); - final String result = response.body() - .asString(); - assertFalse(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - -} +package com.baeldung.persistence.query; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import io.restassured.RestAssured; +import io.restassured.response.Response; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.persistence.model.User; + +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration(classes = { ConfigTest.class, +// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +@ActiveProfiles("test") +public class JPASpecificationLiveTest { + + // @Autowired + // private UserRepository repository; + + private User userJohn; + + private User userTom; + + private final String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec?search="; + + @Before + public void init() { + userJohn = new User(); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); + userJohn.setEmail("john@doe.com"); + userJohn.setAge(22); + // repository.save(userJohn); + + userTom = new User(); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); + userTom.setEmail("tom@doe.com"); + userTom.setAge(26); + // repository.save(userTom); + } + + private final String EURL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/espec?search="; + + @Test + public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); + final String result = response.body() + .asString(); + assertTrue(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName!john"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userTom.getEmail())); + assertFalse(result.contains(userJohn.getEmail())); + } + + @Test + public void givenMinAge_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "age>25"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userTom.getEmail())); + assertFalse(result.contains(userJohn.getEmail())); + } + + @Test + public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:jo*"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "age>20,age<25"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + private final String ADV_URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec/adv?search="; + + @Test + public void givenFirstOrLastName_whenGettingAdvListOfUsers_thenCorrect() { + final Response response = RestAssured.get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); + final String result = response.body() + .asString(); + assertTrue(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { + final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); + final String result = response.body() + .asString(); + assertFalse(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + +} diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java diff --git a/spring-rest-query-language/src/test/resources/.gitignore b/spring-web-modules/spring-rest-query-language/src/test/resources/.gitignore similarity index 100% rename from spring-rest-query-language/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-query-language/src/test/resources/.gitignore From 6a0313b4db0deecd005308fd39bc2aeb3b91702b Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 12:34:37 +0100 Subject: [PATCH 410/590] JAVA-3528 Move spring-mvc-velocity module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-mvc-velocity}/README.md | 0 .../spring-mvc-velocity}/pom.xml | 2 +- .../com/baeldung/mvc/velocity/controller/MainController.java | 0 .../main/java/com/baeldung/mvc/velocity/domain/Tutorial.java | 0 .../com/baeldung/mvc/velocity/service/ITutorialsService.java | 0 .../com/baeldung/mvc/velocity/service/TutorialsService.java | 0 .../mvc/velocity/spring/config/MainWebAppInitializer.java | 0 .../java/com/baeldung/mvc/velocity/spring/config/WebConfig.java | 0 .../spring-mvc-velocity}/src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/fragments/footer.vm | 0 .../src/main/webapp/WEB-INF/fragments/header.vm | 0 .../src/main/webapp/WEB-INF/layouts/layout.vm | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/spring-context.xml | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/views/index.vm | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/views/list.vm | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/web_old.xml | 0 .../mvc/velocity/test/DataContentControllerIntegrationTest.java | 0 .../java/com/baeldung/mvc/velocity/test/config/TestConfig.java | 0 .../src/test/java/org/baeldung/SpringContextTest.java | 0 .../spring-mvc-velocity}/src/test/resources/mvc-servlet.xml | 0 23 files changed, 2 insertions(+), 3 deletions(-) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/README.md (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/pom.xml (98%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/resources/logback.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/fragments/footer.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/fragments/header.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/layouts/layout.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/spring-context.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/views/index.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/views/list.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/web_old.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/org/baeldung/SpringContextTest.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/resources/mvc-servlet.xml (100%) diff --git a/pom.xml b/pom.xml index 79bf7d72b7..228b068fab 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-mvc-java spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow spring-mvc-xml @@ -1131,7 +1130,6 @@ spring-mvc-java spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow spring-mvc-xml diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index ce0524f957..382ed99603 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-velocity spring-rest-angular spring-rest-http spring-resttemplate-2 diff --git a/spring-mvc-velocity/README.md b/spring-web-modules/spring-mvc-velocity/README.md similarity index 100% rename from spring-mvc-velocity/README.md rename to spring-web-modules/spring-mvc-velocity/README.md diff --git a/spring-mvc-velocity/pom.xml b/spring-web-modules/spring-mvc-velocity/pom.xml similarity index 98% rename from spring-mvc-velocity/pom.xml rename to spring-web-modules/spring-mvc-velocity/pom.xml index 2269f05fa4..05016962a5 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-web-modules/spring-mvc-velocity/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-4 0.0.1-SNAPSHOT - ../parent-spring-4 + ../../parent-spring-4 diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java diff --git a/spring-mvc-velocity/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-velocity/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-velocity/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-velocity/src/main/resources/logback.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml diff --git a/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java b/spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java similarity index 100% rename from spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java diff --git a/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java b/spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java similarity index 100% rename from spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java diff --git a/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java diff --git a/spring-mvc-velocity/src/test/resources/mvc-servlet.xml b/spring-web-modules/spring-mvc-velocity/src/test/resources/mvc-servlet.xml similarity index 100% rename from spring-mvc-velocity/src/test/resources/mvc-servlet.xml rename to spring-web-modules/spring-mvc-velocity/src/test/resources/mvc-servlet.xml From 078169109d789fd0a96cc5401485117f60f120bb Mon Sep 17 00:00:00 2001 From: kwoyke Date: Wed, 30 Dec 2020 12:39:45 +0100 Subject: [PATCH 411/590] BAEL-4755: Add Files.list example (#10356) --- .../main/java/com/baeldung/listfiles/ListFiles.java | 13 ++++++++++++- .../com/baeldung/listfiles/ListFilesUnitTest.java | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java b/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java index 2275128dfe..c108d9ed96 100644 --- a/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java +++ b/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java @@ -24,9 +24,20 @@ public class ListFiles { .collect(Collectors.toSet()); } + public Set listFilesUsingFilesList(String dir) throws IOException { + try (Stream stream = Files.list(Paths.get(dir))) { + return stream + .filter(file -> !Files.isDirectory(file)) + .map(Path::getFileName) + .map(Path::toString) + .collect(Collectors.toSet()); + } + } + public Set listFilesUsingFileWalk(String dir, int depth) throws IOException { try (Stream stream = Files.walk(Paths.get(dir), depth)) { - return stream.filter(file -> !Files.isDirectory(file)) + return stream + .filter(file -> !Files.isDirectory(file)) .map(Path::getFileName) .map(Path::toString) .collect(Collectors.toSet()); diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java index a87097f085..5b4efc9e58 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java @@ -25,10 +25,15 @@ public class ListFilesUnitTest { }; @Test - public void givenDir_whenUsingJAVAIO_thenListAllFiles() throws IOException { + public void givenDir_whenUsingJAVAIO_thenListAllFiles() { assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingJavaIO(DIRECTORY)); } + @Test + public void givenDir_whenUsingFilesList_thenListAllFiles() throws IOException { + assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingFilesList(DIRECTORY)); + } + @Test public void givenDir_whenWalkingTree_thenListAllFiles() throws IOException { assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingFileWalk(DIRECTORY,DEPTH)); From ad461edca2298ebe3e7d93b14480958404b157b5 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 21:46:25 +0100 Subject: [PATCH 412/590] JAVA-2824 Fix tests in Java 9 and above modules --- .../java9/process/OutputStreamExample.java | 3 +-- .../process/ProcessUnderstandingUnitTest.java | 19 ++++++++++++++++++- .../screenshot/ScreenshotUnitTest.java | 5 +++-- .../baeldung/time/LocalDateTimeUnitTest.java | 9 --------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java index 37378f9d6c..fc6d907bfd 100644 --- a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java +++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java @@ -6,8 +6,7 @@ import java.util.logging.Logger; public class OutputStreamExample { public static void main(String[] args) { - Logger log = Logger.getLogger(OutputStreamExample.class.getName()); - log.log(Level.INFO, Integer.toString(sum(1,2))); + System.out.println(sum(1,2)); } public static int sum(int a, int b) { diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java index c8932efb4f..69b65852cc 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java @@ -5,10 +5,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.lang.String; -import java.util.Optional; import java.util.concurrent.TimeUnit; import java.lang.Integer; @@ -88,4 +88,21 @@ class ProcessUnderstandingUnitTest { .filter(ph -> (ph.pid() > 10000 && ph.pid() < 50000)) .count()) > 0); } + + @Test + public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException { + + Runtime.getRuntime() + .exec("javac -cp src src/main/java/com/baeldung/java9/process/OutputStreamExample.java" + .replace("/", File.separator)); + + Process process = Runtime.getRuntime() + .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample" + .replace("/", File.separator)); + + BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream())); + int value = Integer.parseInt(output.readLine()); + + assertEquals(3, value); + } } diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java index ac358b4e71..bf271ef2cc 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java @@ -9,11 +9,13 @@ import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.jupiter.api.Disabled; import static org.junit.Assert.assertTrue; +@Ignore public class ScreenshotUnitTest { @Test @@ -43,7 +45,6 @@ public class ScreenshotUnitTest { // This methods needs a component as a parameter and can only be run from an application with a GUI @Test - @Disabled public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { Rectangle componentRect = component.getBounds(); BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java index 1611a3002f..52dc9ba1c6 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java @@ -18,15 +18,6 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic; @PrepareForTest({ LocalDateTime.class }) public class LocalDateTimeUnitTest { - @Test - public void givenLocalDateTimeMock_whenNow_thenGetFixedLocalDateTime() { - Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC")); - String dateTimeExpected = "2014-12-22T10:15:30"; - LocalDateTime now = LocalDateTime.now(clock); - - assertThat(now).isEqualTo(dateTimeExpected); - } - @Test public void givenFixedClock_whenNow_thenGetFixedLocalDateTime() { Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC")); From de5f9940dd5d4226b16b10afae3d16a21ba1e670 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:26:14 +0100 Subject: [PATCH 413/590] JAVA-3531 Move spring-mvc-xml module --- pom.xml | 2 - .../src/main/resources/messages.properties | 2 - spring-web-modules/pom.xml | 1 + .../spring-mvc-xml}/.gitignore | 0 .../spring-mvc-xml}/README.md | 0 .../spring-mvc-xml}/pom.xml | 0 .../java/com/baeldung/jsp/ExampleOne.java | 0 .../java/com/baeldung/jsp/ExampleThree.java | 0 .../com/baeldung/spring/ClientWebConfig.java | 0 .../baeldung/spring/ClientWebConfigJava.java | 0 .../ConstraintViolationExceptionHandler.java | 0 .../spring/controller/ErrorController.java | 0 .../controller/GeoIPTestController.java | 0 .../spring/controller/GreetingController.java | 0 .../spring/controller/HelloController.java | 0 .../controller/HelloGuestController.java | 0 .../controller/HelloWorldController.java | 0 .../spring/controller/ImageController.java | 122 +++++++++--------- .../spring/controller/PersonController.java | 0 ...stAndPathVariableValidationController.java | 0 .../spring/controller/WelcomeController.java | 0 .../java/com/baeldung/spring/form/GeoIP.java | 0 .../java/com/baeldung/spring/form/Person.java | 0 .../RawDBDemoGeoIPLocationService.java | 0 .../spring/validator/PersonValidator.java | 42 +++--- .../contentManagementWebMvcConfig.xml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/messages.properties | 2 + .../src/main/resources/webMvcConfig.xml | 0 .../src/main/webapp/GeoIpTest.jsp | 0 .../WEB-INF/crash/commands/message.groovy | 0 .../WEB-INF/crash/commands/message2.java | 0 .../webapp/WEB-INF/crash/crash.properties | 0 .../webapp/WEB-INF/crash/telnet.properties | 0 .../webapp/WEB-INF/images/image-example.jpg | Bin .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/error.jsp | 0 .../main/webapp/WEB-INF/view/errorPage.jsp | 0 .../src/main/webapp/WEB-INF/view/greeting.jsp | 0 .../src/main/webapp/WEB-INF/view/hello.jsp | 0 .../main/webapp/WEB-INF/view/helloworld.jsp | 0 .../webapp/WEB-INF/view/image-download.jsp | 0 .../main/webapp/WEB-INF/view/personForm.jsp | 0 .../main/webapp/WEB-INF/view/personView.jsp | 0 .../src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/view/welcome.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../spring-mvc-xml}/src/main/webapp/index.jsp | 0 .../src/main/webapp/jsp/ExampleThree.jsp | 0 .../src/main/webapp/jsp/ExampleTwo.jsp | 0 .../src/main/webapp/jsp/index.jsp | 0 .../src/main/webapp/spring-handler-index.jsp | 0 .../baeldung/geoip/GeoIpIntegrationTest.java | 0 ...leValidationControllerIntegrationTest.java | 0 .../java/org/baeldung/SpringContextTest.java | 2 +- 55 files changed, 86 insertions(+), 87 deletions(-) delete mode 100644 spring-mvc-xml/src/main/resources/messages.properties rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/.gitignore (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/README.md (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/pom.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/jsp/ExampleOne.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/jsp/ExampleThree.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/ClientWebConfig.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/ClientWebConfigJava.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ErrorController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/GreetingController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloGuestController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloWorldController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ImageController.java (97%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/PersonController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/WelcomeController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/form/GeoIP.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/form/Person.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/validator/PersonValidator.java (96%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/contentManagementWebMvcConfig.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/logback.xml (100%) create mode 100644 spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/webMvcConfig.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/GeoIpTest.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/commands/message.groovy (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/commands/message2.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/crash.properties (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/telnet.properties (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/images/image-example.jpg (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/error.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/errorPage.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/greeting.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/hello.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/helloworld.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/image-download.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/personForm.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/personView.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/welcome.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/ExampleThree.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/ExampleTwo.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/spring-handler-index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/org/baeldung/SpringContextTest.java (96%) diff --git a/pom.xml b/pom.xml index 67fa58293b..352d61660d 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-xml spring-protobuf spring-quartz @@ -1130,7 +1129,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-xml spring-protobuf spring-quartz diff --git a/spring-mvc-xml/src/main/resources/messages.properties b/spring-mvc-xml/src/main/resources/messages.properties deleted file mode 100644 index 2a3cccf76c..0000000000 --- a/spring-mvc-xml/src/main/resources/messages.properties +++ /dev/null @@ -1,2 +0,0 @@ -required.name = Name is required! -NotEmpty.person.password = Password is required! \ No newline at end of file diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c28ffbeab8..d9e7e8012d 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-mvc-views spring-mvc-webflow + spring-mvc-xml spring-rest-angular spring-rest-http spring-resttemplate-2 diff --git a/spring-mvc-xml/.gitignore b/spring-web-modules/spring-mvc-xml/.gitignore similarity index 100% rename from spring-mvc-xml/.gitignore rename to spring-web-modules/spring-mvc-xml/.gitignore diff --git a/spring-mvc-xml/README.md b/spring-web-modules/spring-mvc-xml/README.md similarity index 100% rename from spring-mvc-xml/README.md rename to spring-web-modules/spring-mvc-xml/README.md diff --git a/spring-mvc-xml/pom.xml b/spring-web-modules/spring-mvc-xml/pom.xml similarity index 100% rename from spring-mvc-xml/pom.xml rename to spring-web-modules/spring-mvc-xml/pom.xml diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java similarity index 97% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java index fc46c07e06..c02e76d4c0 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java +++ b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java @@ -1,61 +1,61 @@ -package com.baeldung.spring.controller; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.*; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.context.support.ServletContextResource; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; - -@Controller -public class ImageController { - - @Autowired - private ServletContext servletContext; - - @RequestMapping(value = "/image-view", method = RequestMethod.GET) - public String imageView() throws IOException { - return "image-download"; - } - - @RequestMapping(value = "/image-manual-response", method = RequestMethod.GET) - public void getImageAsByteArray(HttpServletResponse response) throws IOException { - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - response.setContentType(MediaType.IMAGE_JPEG_VALUE); - IOUtils.copy(in, response.getOutputStream()); - } - - @RequestMapping(value = "/image-byte-array", method = RequestMethod.GET) - @ResponseBody - public byte[] getImageAsByteArray() throws IOException { - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - return IOUtils.toByteArray(in); - } - - @RequestMapping(value = "/image-response-entity", method = RequestMethod.GET) - public ResponseEntity getImageAsResponseEntity() throws IOException { - ResponseEntity responseEntity; - final HttpHeaders headers = new HttpHeaders(); - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - byte[] media = IOUtils.toByteArray(in); - headers.setCacheControl(CacheControl.noCache().getHeaderValue()); - responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK); - return responseEntity; - } - - @RequestMapping(value = "/image-resource", method = RequestMethod.GET) - @ResponseBody - public ResponseEntity getImageAsResource() { - final HttpHeaders headers = new HttpHeaders(); - Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg"); - return new ResponseEntity<>(resource, headers, HttpStatus.OK); - } -} +package com.baeldung.spring.controller; + +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.*; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.support.ServletContextResource; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; + +@Controller +public class ImageController { + + @Autowired + private ServletContext servletContext; + + @RequestMapping(value = "/image-view", method = RequestMethod.GET) + public String imageView() throws IOException { + return "image-download"; + } + + @RequestMapping(value = "/image-manual-response", method = RequestMethod.GET) + public void getImageAsByteArray(HttpServletResponse response) throws IOException { + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + response.setContentType(MediaType.IMAGE_JPEG_VALUE); + IOUtils.copy(in, response.getOutputStream()); + } + + @RequestMapping(value = "/image-byte-array", method = RequestMethod.GET) + @ResponseBody + public byte[] getImageAsByteArray() throws IOException { + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + return IOUtils.toByteArray(in); + } + + @RequestMapping(value = "/image-response-entity", method = RequestMethod.GET) + public ResponseEntity getImageAsResponseEntity() throws IOException { + ResponseEntity responseEntity; + final HttpHeaders headers = new HttpHeaders(); + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + byte[] media = IOUtils.toByteArray(in); + headers.setCacheControl(CacheControl.noCache().getHeaderValue()); + responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK); + return responseEntity; + } + + @RequestMapping(value = "/image-resource", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getImageAsResource() { + final HttpHeaders headers = new HttpHeaders(); + Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg"); + return new ResponseEntity<>(resource, headers, HttpStatus.OK); + } +} diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java similarity index 96% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java index f7625bacd9..cda756cdfc 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java +++ b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java @@ -1,22 +1,22 @@ -package com.baeldung.spring.validator; - -import com.baeldung.spring.form.Person; -import org.springframework.stereotype.Component; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -@Component -public class PersonValidator implements Validator { - - @Override - public boolean supports(final Class calzz) { - return Person.class.isAssignableFrom(calzz); - } - - @Override - public void validate(final Object obj, final Errors errors) { - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name"); - } +package com.baeldung.spring.validator; + +import com.baeldung.spring.form.Person; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +@Component +public class PersonValidator implements Validator { + + @Override + public boolean supports(final Class calzz) { + return Person.class.isAssignableFrom(calzz); + } + + @Override + public void validate(final Object obj, final Errors errors) { + + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name"); + } } \ No newline at end of file diff --git a/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml diff --git a/spring-mvc-xml/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/logback.xml diff --git a/spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties b/spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties new file mode 100644 index 0000000000..8d886c8449 --- /dev/null +++ b/spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties @@ -0,0 +1,2 @@ +required.name = Name is required! +NotEmpty.person.password = Password is required! \ No newline at end of file diff --git a/spring-mvc-xml/src/main/resources/webMvcConfig.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/webMvcConfig.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/webMvcConfig.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/webMvcConfig.xml diff --git a/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/GeoIpTest.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-xml/src/main/webapp/index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/index.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/index.jsp diff --git a/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/spring-handler-index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp diff --git a/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java similarity index 100% rename from spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java diff --git a/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java similarity index 100% rename from spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java diff --git a/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java similarity index 96% rename from spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java index 62e34859ee..27dcb83bd4 100644 --- a/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package org.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 8f843980820d537980a124367424386efb169b8f Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:37:42 +0100 Subject: [PATCH 414/590] JAVA-3531 Move spring-mvc-xml module (correct package for test) --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-web-modules/spring-mvc-xml/src/test/java/{org => com}/baeldung/SpringContextTest.java (96%) diff --git a/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java similarity index 96% rename from spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java index 27dcb83bd4..62e34859ee 100644 --- a/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 08435be1909f31bef139b724ba0790dde736df55 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:57:22 +0100 Subject: [PATCH 415/590] JAVA-3536 Move spring-rest-shell module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-shell}/README.md | 0 .../spring-rest-shell}/pom.xml | 2 +- .../src/main/java/com/baeldung/Application.java | 0 .../src/main/java/com/baeldung/acticle/Article.java | 0 .../src/main/java/com/baeldung/acticle/ArticleRepository.java | 0 .../spring-rest-shell}/src/main/resources/logback.xml | 0 8 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/README.md (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/pom.xml (96%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/Application.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/acticle/Article.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/acticle/ArticleRepository.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/resources/logback.xml (100%) diff --git a/pom.xml b/pom.xml index 67fa58293b..44a87ecd3c 100644 --- a/pom.xml +++ b/pom.xml @@ -673,7 +673,6 @@ spring-remoting spring-rest-http-2 spring-rest-query-language - spring-rest-shell spring-rest-simple spring-resttemplate spring-rest-testing @@ -1138,7 +1137,6 @@ spring-reactor spring-remoting spring-rest-query-language - spring-rest-shell spring-rest-simple spring-resttemplate spring-rest-testing diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c28ffbeab8..9fb40a1ed3 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -24,6 +24,7 @@ spring-mvc-webflow spring-rest-angular spring-rest-http + spring-rest-shell spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-shell/README.md b/spring-web-modules/spring-rest-shell/README.md similarity index 100% rename from spring-rest-shell/README.md rename to spring-web-modules/spring-rest-shell/README.md diff --git a/spring-rest-shell/pom.xml b/spring-web-modules/spring-rest-shell/pom.xml similarity index 96% rename from spring-rest-shell/pom.xml rename to spring-web-modules/spring-rest-shell/pom.xml index 1148a5c093..f5792fd6ca 100644 --- a/spring-rest-shell/pom.xml +++ b/spring-web-modules/spring-rest-shell/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-shell/src/main/java/com/baeldung/Application.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/Application.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/Application.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/Application.java diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java diff --git a/spring-rest-shell/src/main/resources/logback.xml b/spring-web-modules/spring-rest-shell/src/main/resources/logback.xml similarity index 100% rename from spring-rest-shell/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-shell/src/main/resources/logback.xml From 90562c22a4c8a37db5f0c0189559c424eb8f9285 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 31 Dec 2020 10:46:33 +0100 Subject: [PATCH 416/590] JAVA-4130: Fix README.md for Using JaVers for Data Model Auditing in Spring Data --- spring-boot-modules/spring-boot-data/README.md | 1 + .../src/main/java/com/baeldung/javers/README.md | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md diff --git a/spring-boot-modules/spring-boot-data/README.md b/spring-boot-modules/spring-boot-data/README.md index da22b62128..f72864e6d9 100644 --- a/spring-boot-modules/spring-boot-data/README.md +++ b/spring-boot-modules/spring-boot-data/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring Boot with Spring Data - [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) - [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent) - [Guide To Running Logic on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) +- [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit) diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md deleted file mode 100644 index 4f8dd4abff..0000000000 --- a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles - -- [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit) From 47ada8bdcad728c5e86450916af1e3bf72584c4c Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:19:30 +0100 Subject: [PATCH 417/590] JAVA-3498 Fix integration test in spring-cloud-zuul --- ...=> GreetingControllerIntegrationTest.java} | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) rename spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/{GreetingControllerManualTest.java => GreetingControllerIntegrationTest.java} (72%) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java similarity index 72% rename from spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java rename to spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index 4d3cede534..62e57992cb 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -5,14 +5,17 @@ import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateL import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_REMAINING; import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_REMAINING_QUOTA; import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_RESET; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static java.lang.Integer.parseInt; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import java.util.concurrent.TimeUnit; + +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +29,7 @@ import org.springframework.test.context.junit4.SpringRunner; @AutoConfigureTestDatabase @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class GreetingControllerManualTest { +public class GreetingControllerIntegrationTest { private static final String SIMPLE_GREETING = "/greeting/simple"; private static final String ADVANCED_GREETING = "/greeting/advanced"; @@ -44,11 +47,15 @@ public class GreetingControllerManualTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - assertEquals(limit, "5"); - assertEquals(remaining, "4"); - assertEquals(reset, "60000"); + Assert.assertEquals("5", limit); + Assert.assertEquals(remaining, "4", remaining); + Assert.assertNotNull(reset); + Assert.assertThat( + parseInt(reset), + is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000))) + ); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); } @Test @@ -57,7 +64,7 @@ public class GreetingControllerManualTest { HttpHeaders headers = response.getHeaders(); String key = "rate-limit-application_serviceAdvanced_127.0.0.1"; assertHeaders(headers, key, false, false); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); for (int i = 0; i < 2; i++) { response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); @@ -68,18 +75,18 @@ public class GreetingControllerManualTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - assertEquals(limit, "1"); - assertEquals(remaining, "0"); - assertNotEquals(reset, "2000"); + Assert.assertEquals(limit, "1"); + Assert.assertEquals(remaining, "0"); + Assert.assertNotEquals(reset, "2000"); - assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); + Assert.assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); TimeUnit.SECONDS.sleep(2); response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); headers = response.getHeaders(); assertHeaders(headers, key, false, false); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); } private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) { @@ -91,22 +98,22 @@ public class GreetingControllerManualTest { if (nullable) { if (quotaHeaders) { - assertNull(quota); - assertNull(remainingQuota); + Assert.assertNull(quota); + Assert.assertNull(remainingQuota); } else { - assertNull(limit); - assertNull(remaining); + Assert.assertNull(limit); + Assert.assertNull(remaining); } - assertNull(reset); + Assert.assertNull(reset); } else { if (quotaHeaders) { - assertNotNull(quota); - assertNotNull(remainingQuota); + Assert.assertNotNull(quota); + Assert.assertNotNull(remainingQuota); } else { - assertNotNull(limit); - assertNotNull(remaining); + Assert.assertNotNull(limit); + Assert.assertNotNull(remaining); } - assertNotNull(reset); + Assert.assertNotNull(reset); } } } From bef161cc5df86f6cbd6e08dc9f43a6211196204c Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:22:01 +0100 Subject: [PATCH 418/590] JAVA-3498 Fix integration test in spring-cloud-zuul (fix imports) --- .../GreetingControllerIntegrationTest.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index 62e57992cb..a234bc8972 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -10,6 +10,9 @@ import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; @@ -47,15 +50,15 @@ public class GreetingControllerIntegrationTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - Assert.assertEquals("5", limit); - Assert.assertEquals(remaining, "4", remaining); - Assert.assertNotNull(reset); - Assert.assertThat( + assertEquals("5", limit); + assertEquals(remaining, "4", remaining); + assertNotNull(reset); + assertThat( parseInt(reset), is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000))) ); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); } @Test @@ -64,7 +67,7 @@ public class GreetingControllerIntegrationTest { HttpHeaders headers = response.getHeaders(); String key = "rate-limit-application_serviceAdvanced_127.0.0.1"; assertHeaders(headers, key, false, false); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); for (int i = 0; i < 2; i++) { response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); @@ -75,18 +78,18 @@ public class GreetingControllerIntegrationTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - Assert.assertEquals(limit, "1"); - Assert.assertEquals(remaining, "0"); + assertEquals(limit, "1"); + assertEquals(remaining, "0"); Assert.assertNotEquals(reset, "2000"); - Assert.assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); + assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); TimeUnit.SECONDS.sleep(2); response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); headers = response.getHeaders(); assertHeaders(headers, key, false, false); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); } private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) { @@ -107,13 +110,13 @@ public class GreetingControllerIntegrationTest { Assert.assertNull(reset); } else { if (quotaHeaders) { - Assert.assertNotNull(quota); - Assert.assertNotNull(remainingQuota); + assertNotNull(quota); + assertNotNull(remainingQuota); } else { - Assert.assertNotNull(limit); - Assert.assertNotNull(remaining); + assertNotNull(limit); + assertNotNull(remaining); } - Assert.assertNotNull(reset); + assertNotNull(reset); } } } From cb7c9406eed01e9f44d2dd2573443841e2ef7208 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:24:17 +0100 Subject: [PATCH 419/590] JAVA-3498 Fix integration test in spring-cloud-zuul (fix imports - 2) --- .../GreetingControllerIntegrationTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index a234bc8972..7fdc723305 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -11,14 +11,15 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import java.util.concurrent.TimeUnit; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -80,7 +81,7 @@ public class GreetingControllerIntegrationTest { assertEquals(limit, "1"); assertEquals(remaining, "0"); - Assert.assertNotEquals(reset, "2000"); + assertNotEquals(reset, "2000"); assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); @@ -101,13 +102,13 @@ public class GreetingControllerIntegrationTest { if (nullable) { if (quotaHeaders) { - Assert.assertNull(quota); - Assert.assertNull(remainingQuota); + assertNull(quota); + assertNull(remainingQuota); } else { - Assert.assertNull(limit); - Assert.assertNull(remaining); + assertNull(limit); + assertNull(remaining); } - Assert.assertNull(reset); + assertNull(reset); } else { if (quotaHeaders) { assertNotNull(quota); From 926f273a2d94ff36005f9ba82af6c9c64b9e94eb Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 2 Jan 2021 12:08:15 +0100 Subject: [PATCH 420/590] Feature/bael 4749 java 11 features (#10308) * BAEL-4749: Added examples for Java 11 * BAEL-4749: Refactor test examples * BAEL-4749: Refactor test examples 2 * BAEL-4749: Fix PR comments * BAEL-4749: Update nestmates examples * BAEL-4749: Use method reference in Predicate.not example * BAEL-4749: Use String::isBlank in Predicate.not example * BAEL-4749: Two space indents when continuing a line * BAEL-4749: Two space indents when continuing a line (2) --- core-java-modules/core-java-11-2/pom.xml | 25 ++++++++ .../java/com/baeldung/features/MainClass.java | 17 ++++++ .../features/HttpClientIntegrationTest.java | 54 ++++++++++++++++ .../features/JavaElevenFeaturesUnitTest.java | 61 +++++++++++++++++++ .../features/NestedClassesUnitTest.java | 37 +++++++++++ 5 files changed, 194 insertions(+) create mode 100644 core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml index e2b129ae00..b92963a5c8 100644 --- a/core-java-modules/core-java-11-2/pom.xml +++ b/core-java-modules/core-java-11-2/pom.xml @@ -28,6 +28,29 @@ ${assertj.version} test + + org.mock-server + mockserver-junit-jupiter + ${mockserver.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + @@ -48,7 +71,9 @@ 11 11 29.0-jre + 5.7.0 3.17.2 + 5.11.1 diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java new file mode 100644 index 0000000000..b00c56fcd7 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java @@ -0,0 +1,17 @@ +package com.baeldung.features; + +public class MainClass { + + private static boolean mainPrivateMethod() { + return true; + } + + public static class NestedClass { + + boolean nestedPublicMethod() { + return mainPrivateMethod(); + } + + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java new file mode 100644 index 0000000000..1d49f5dbd1 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java @@ -0,0 +1,54 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.model.HttpStatusCode; +import org.mockserver.socket.PortFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; + +class HttpClientIntegrationTest { + + private static ClientAndServer mockServer; + private static int port; + + @BeforeAll + static void startServer() { + port = PortFactory.findFreePort(); + mockServer = startClientAndServer(port); + mockServer.when(new org.mockserver.model.HttpRequest().withMethod("GET")) + .respond(new org.mockserver.model.HttpResponse() + .withStatusCode(HttpStatusCode.OK_200.code()) + .withBody("Hello from the server!")); + } + + @AfterAll + static void stopServer() { + mockServer.stop(); + } + + @Test + void givenSampleHttpRequest_whenRequestIsSent_thenServerResponseIsReceived() throws IOException, InterruptedException { + HttpClient httpClient = HttpClient.newBuilder() + .version(HttpClient.Version.HTTP_2) + .connectTimeout(Duration.ofSeconds(20)) + .build(); + HttpRequest httpRequest = HttpRequest.newBuilder() + .GET() + .uri(URI.create("http://localhost:" + port)) + .build(); + HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); + assertThat(httpResponse.body()).isEqualTo("Hello from the server!"); + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java new file mode 100644 index 0000000000..61ce9c7c13 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class JavaElevenFeaturesUnitTest { + + @Test + void givenMultilineString_whenExtractingNonBlankStrippedLines_thenLinesAreReturned() { + String multilineString = "Baeldung helps \n \n developers \n explore Java."; + List lines = multilineString.lines() + .filter(line -> !line.isBlank()) + .map(String::strip) + .collect(Collectors.toList()); + assertThat(lines).containsExactly("Baeldung helps", "developers", "explore Java."); + } + + @Test + void givenTemporaryFile_whenReadingStringContent_thenContentIsReturned(@TempDir Path tempDir) throws IOException { + Path filePath = Files.writeString(Files.createTempFile(tempDir, "demo", ".txt"), "Sample text"); + String fileContent = Files.readString(filePath); + assertThat(fileContent).isEqualTo("Sample text"); + } + + @Test + void givenSampleList_whenConvertingToArray_thenItemsRemainUnchanged() { + List sampleList = Arrays.asList("Java", "Kotlin"); + String[] sampleArray = sampleList.toArray(String[]::new); + assertThat(sampleArray).containsExactly("Java", "Kotlin"); + } + + @Test + void givenSampleList_whenConvertingToUppercaseString_thenUppercaseIsReturned() { + List sampleList = Arrays.asList("Java", "Kotlin"); + String resultString = sampleList.stream() + .map((@Nonnull var x) -> x.toUpperCase()) + .collect(Collectors.joining(", ")); + assertThat(resultString).isEqualTo("JAVA, KOTLIN"); + } + + @Test + void givenSampleList_whenExtractingNonBlankValues_thenOnlyNonBlanksAreReturned() { + List sampleList = Arrays.asList("Java", "\n \n", "Kotlin", " "); + List withoutBlanks = sampleList.stream() + .filter(Predicate.not(String::isBlank)) + .collect(Collectors.toList()); + assertThat(withoutBlanks).containsExactly("Java", "Kotlin"); + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java new file mode 100644 index 0000000000..902ad9c6f8 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class NestedClassesUnitTest { + + @Test + public void giveNestedClass_whenCallingMainClassPrivateMethod_thenNoExceptionIsThrown() { + MainClass.NestedClass nestedInstance = new MainClass.NestedClass(); + assertThat(nestedInstance.nestedPublicMethod()).isTrue(); + } + + @Test + public void giveNestedClass_whenCheckingNestmate_thenNestedClassIsReturned() { + assertThat(MainClass.class.isNestmateOf(MainClass.NestedClass.class)).isTrue(); + } + + @Test + public void giveNestedClass_whenCheckingNestHost_thenMainClassIsReturned() { + assertThat(MainClass.NestedClass.class.getNestHost()).isEqualTo(MainClass.class); + } + + @Test + public void giveNestedClass_whenCheckingNestMembers_thenNestMembersAreReturned() { + Set nestedMembers = Arrays.stream(MainClass.NestedClass.class.getNestMembers()) + .map(Class::getName) + .collect(Collectors.toSet()); + assertThat(nestedMembers).contains(MainClass.class.getName(), MainClass.NestedClass.class.getName()); + } + +} From f210b5ae2967688b38879b0165adf59c44cee49e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 3 Jan 2021 00:11:41 +0530 Subject: [PATCH 421/590] JAVA-4166: Fix test in spring-5-reactive --- .../com/baeldung/functional/FunctionalWebApplication.java | 7 ++++--- .../FunctionalWebApplicationIntegrationTest.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java index 1f40798ada..b89f74ad92 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java @@ -3,7 +3,7 @@ package com.baeldung.functional; import static org.springframework.web.reactive.function.BodyInserters.fromObject; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RequestPredicates.path; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import static org.springframework.web.reactive.function.server.RouterFunctions.route; import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; import static org.springframework.web.reactive.function.server.ServerResponse.ok; @@ -18,6 +18,7 @@ import org.apache.catalina.startup.Tomcat; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.server.WebServer; import org.springframework.core.io.ClassPathResource; +import org.springframework.http.MediaType; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; import org.springframework.web.reactive.function.server.RouterFunction; @@ -37,14 +38,14 @@ public class FunctionalWebApplication { private RouterFunction routingFunction() { FormHandler formHandler = new FormHandler(); - RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) + RouterFunction restfulRouter = route(GET("/actor"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/actor"), serverRequest -> serverRequest.bodyToMono(Actor.class) .doOnNext(actors::add) .then(ok().build())); return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) .andRoute(POST("/upload"), formHandler::handleUpload) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) - .andNest(path("/actor"), restfulRouter) + .andNest(accept(MediaType.APPLICATION_JSON), restfulRouter) .filter((request, next) -> { System.out.println("Before handler invocation: " + request.path()); return next.handle(request); diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java index 38496d3500..5c0b4f69d0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java @@ -103,7 +103,6 @@ public class FunctionalWebApplicationIntegrationTest { .isEqualTo(String.valueOf(resource.contentLength())); } - @Ignore("We get 404 after Spring Boot 2.4 upgrade. We need to solve it in a new task.") @Test public void givenActors_whenAddActor_thenAdded() throws Exception { client.get() From 71bbdb7fede51f7b275eac1b4fe6c13a6aea8901 Mon Sep 17 00:00:00 2001 From: Tapan Avasthi Date: Sat, 2 Jan 2021 04:03:44 +0530 Subject: [PATCH 422/590] Use shouldNotFilter to exclude URLs for a Filter Jira ticket: http://jira.baeldung.com/browse/BAEL-4703 The existing article uses an out-dated way is used to excluded filtering for certain urls, instead shouldNotFilter should be used. --- .../filter/HeaderValidatorFilter.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java index 2af90badae..d6c1777326 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java @@ -11,20 +11,23 @@ import java.io.IOException; @Order(1) public class HeaderValidatorFilter extends OncePerRequestFilter { - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException { - String path = request.getRequestURI(); - if ("/health".equals(path)) { - filterChain.doFilter(request, response); - return; - } - String countryCode = request.getHeader("X-Country-Code"); - if (!"US".equals(countryCode)) { - response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale"); - return; - } - - filterChain.doFilter(request, response); - } -} \ No newline at end of file + @Override + protected void doFilterInternal(HttpServletRequest request, + HttpServletResponse response, + FilterChain filterChain) + throws ServletException, + IOException { + String countryCode = request.getHeader("X-Country-Code"); + if (!"US".equals(countryCode)) { + response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale"); + return; + } + filterChain.doFilter(request, response); + } + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { + String path = request.getRequestURI(); + return "/health".equals(path); + } +} From 1a2bd7348762bf5b1b505d8c78fd3fb41665e4bf Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Thu, 31 Dec 2020 23:20:27 +0100 Subject: [PATCH 423/590] [BAEL-2547] jackson deserialization class-casting exception --- .../baeldung/jackson/tocollection/Book.java | 70 ++++++++++ .../tocollection/JsonToCollectionUtil.java | 24 ++++ .../resources/to-java-collection/books.json | 13 ++ .../resources/to-java-collection/books.xml | 17 +++ .../DeserializeToJavaCollectionUnitTest.java | 130 ++++++++++++++++++ .../JsonToCollectionUtilUnitTest.java | 51 +++++++ 6 files changed, 305 insertions(+) create mode 100644 jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java create mode 100644 jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java create mode 100644 jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json create mode 100644 jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml create mode 100644 jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java create mode 100644 jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java diff --git a/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java new file mode 100644 index 0000000000..e9cb1343e9 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java @@ -0,0 +1,70 @@ +package com.baeldung.jackson.tocollection; + + +import java.util.Objects; + +public class Book { + private Integer bookId; + private String title; + private String author; + + public Book() {} + + public Book(Integer bookId, String title, String author) { + this.bookId = bookId; + this.title = title; + this.author = author; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Book)) { + return false; + } + + Book book = (Book) o; + + if (!Objects.equals(bookId, book.bookId)) { + return false; + } + if (!Objects.equals(title, book.title)) { + return false; + } + return Objects.equals(author, book.author); + } + + @Override + public int hashCode() { + int result = bookId != null ? bookId.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + result = 31 * result + (author != null ? author.hashCode() : 0); + return result; + } + + public Integer getBookId() { + return bookId; + } + + public void setBookId(Integer bookId) { + this.bookId = bookId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} diff --git a/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java new file mode 100644 index 0000000000..83e2de2c3b --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java @@ -0,0 +1,24 @@ +package com.baeldung.jackson.tocollection; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class JsonToCollectionUtil { + + private JsonToCollectionUtil(){} + + public static List jsonArrayToList(String json, Class elementClass) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, elementClass); + return objectMapper.readValue(json, listType); + } + + public static List jsonArrayToList2(String json, Class elementClass) throws IOException { + return new ObjectMapper().readValue(json, new TypeReference>() {}); + } +} diff --git a/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json new file mode 100644 index 0000000000..6daf426736 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json @@ -0,0 +1,13 @@ +[ { + "bookId" : 1, + "title" : "A Song of Ice and Fire", + "author" : "George R. R. Martin" +}, { + "bookId" : 2, + "title" : "The Hitchhiker's Guide to the Galaxy", + "author" : "Douglas Adams" +}, { + "bookId" : 3, + "title" : "Hackers And Painters", + "author" : "Paul Graham" +} ] diff --git a/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml new file mode 100644 index 0000000000..b2f951315b --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml @@ -0,0 +1,17 @@ + + + 1 + A Song of Ice and Fire + George R. R. Martin + + + 2 + The Hitchhiker's Guide to the Galaxy + Douglas Adams + + + 3 + Hackers And Painters + Paul Graham + + diff --git a/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java new file mode 100644 index 0000000000..8ddcc2d69a --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java @@ -0,0 +1,130 @@ +package com.baeldung.jackson.tocollection; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +public class DeserializeToJavaCollectionUnitTest { + private ObjectMapper objectMapper; + private XmlMapper xmlMapper; + private List expectedBookList; + + + @BeforeEach + void setup() { + objectMapper = new ObjectMapper(); + xmlMapper = new XmlMapper(); + expectedBookList = Lists.newArrayList( + new Book(1, "A Song of Ice and Fire", "George R. R. Martin"), + new Book(2, "The Hitchhiker's Guide to the Galaxy", "Douglas Adams"), + new Book(3, "Hackers And Painters", "Paul Graham")); + } + + private String readFile(String path) { + try (Scanner scanner = new Scanner(getClass().getResourceAsStream(path), "UTF-8")) { + return scanner.useDelimiter("\\A").next(); + } + } + + /*==================== + * JSON tests + *==================== + */ + @Test + void givenJsonString_whenDeserializingToList_thenThrowingClassCastException() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = objectMapper.readValue(jsonString, ArrayList.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + + @Test + void givenJsonString_whenDeserializingWithTypeReference_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = objectMapper.readValue(jsonString, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithJavaType_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class); + List bookList = objectMapper.readValue(jsonString, listType); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithConvertValueAndTypeReference_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + JsonNode jsonNode = objectMapper.readTree(jsonString); + List bookList = objectMapper.convertValue(jsonNode, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithConvertValueAndJavaType_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + JsonNode jsonNode = objectMapper.readTree(jsonString); + List bookList = objectMapper.convertValue(jsonNode, objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class)); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + /*==================== + * XML tests + *==================== + */ + @Test + void givenXml_whenDeserializingToList_thenThrowingClassCastException() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List bookList = xmlMapper.readValue(xml, ArrayList.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + + @Test + void givenXml_whenDeserializingWithTypeReference_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List bookList = xmlMapper.readValue(xml, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenXml_whenDeserializingWithConvertValueAndTypeReference_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List node = xmlMapper.readValue(xml, List.class); + List bookList = xmlMapper.convertValue(node, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenXml_whenDeserializingWithConvertValueAndJavaType_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List node = xmlMapper.readValue(xml, List.class); + List bookList = xmlMapper.convertValue(node, objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class)); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } +} diff --git a/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java new file mode 100644 index 0000000000..a08e48e069 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.jackson.tocollection; + +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +class JsonToCollectionUtilUnitTest { + + private List expectedBookList; + + + @BeforeEach + void setup() { + expectedBookList = Lists.newArrayList( + new Book(1, "A Song of Ice and Fire", "George R. R. Martin"), + new Book(2, "The Hitchhiker's Guide to the Galaxy", "Douglas Adams"), + new Book(3, "Hackers And Painters", "Paul Graham")); + } + + private String readFile(String path) { + try (Scanner scanner = new Scanner(getClass().getResourceAsStream(path), "UTF-8")) { + return scanner.useDelimiter("\\A").next(); + } + } + + @Test + void givenJsonString_whenCalljsonArrayToList_thenGetExpectedList() throws IOException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = JsonToCollectionUtil.jsonArrayToList(jsonString, Book.class); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenCalljsonArrayToList2_thenGetException() throws IOException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = JsonToCollectionUtil.jsonArrayToList2(jsonString, Book.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + +} From 5d9cb02da9070e9742a172877d0220d841a559f8 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 3 Jan 2021 16:36:16 -0300 Subject: [PATCH 424/590] fixed error updating deprecated isEmpty method --- .../properties/reloading/configs/ReloadablePropertySource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java index 5d4e170226..e63dc1eb54 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java @@ -15,7 +15,7 @@ public class ReloadablePropertySource extends PropertySource { } public ReloadablePropertySource(String name, String path) { - super(StringUtils.hasText(name) ? path : name); + super(!StringUtils.hasText(name) ? path : name); try { this.propertiesConfiguration = new PropertiesConfiguration(path); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); From bbdcf57afb63dda1b6e020ba22c5d1a780ef1c92 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Tue, 29 Dec 2020 11:02:52 +0200 Subject: [PATCH 425/590] BAEL-4472- Binary Semaphore vs a ReentrantLock - new module added --- .../core-java-concurrency-advanced-4/pom.xml | 47 +++++++++++++++ ...inarySemaphoreVsReentrantLockUnitTest.java | 58 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 3 files changed, 106 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/pom.xml create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-4/pom.xml b/core-java-modules/core-java-concurrency-advanced-4/pom.xml new file mode 100644 index 0000000000..eb9ed3adc1 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + core-java-concurrency-advanced-4 + 0.1.0-SNAPSHOT + core-java-concurrency-advanced-4 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + + + core-java-concurrency-advanced-4 + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + src/main/resources + true + + + + + + 1.8 + 1.8 + + + diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java new file mode 100644 index 0000000000..f456e82f39 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.binarysemaphorereentrantlock; + +import static org.junit.Assert.assertEquals; +import java.util.concurrent.Semaphore; +import java.util.concurrent.locks.ReentrantLock; + +import org.junit.Test; + +public class BinarySemaphoreVsReentrantLockUnitTest { + + @Test + public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { + Semaphore binarySemaphore = new Semaphore(1); + try { + binarySemaphore.acquire(); + assertEquals(0, binarySemaphore.availablePermits()); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + binarySemaphore.release(); + assertEquals(1, binarySemaphore.availablePermits()); + } + } + + @Test + public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + + @Test + public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + reentrantLock.lock(); + assertEquals(2, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 0a9e818156..00ed22c3bd 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -47,6 +47,7 @@ core-java-concurrency-advanced core-java-concurrency-advanced-2 core-java-concurrency-advanced-3 + core-java-concurrency-advanced-4 core-java-concurrency-basic core-java-concurrency-basic-2 core-java-concurrency-collections From 1b4e5782ec11316b254c8faec298dc66d433dfdc Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 4 Jan 2021 09:05:55 +0530 Subject: [PATCH 426/590] BAEL-4624: Review comments --- .../com/baeldung/spring/transaction/CourseDao.java | 11 ----------- .../baeldung/spring/transaction/CourseService.java | 10 +++++++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java index 489784bb40..adf138ba67 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java @@ -1,8 +1,5 @@ package com.baeldung.spring.transaction; -import java.sql.SQLException; - -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Repository; import com.baeldung.spring.hibernate.AbstractHibernateDao; @@ -13,12 +10,4 @@ public class CourseDao extends AbstractHibernateDao { super(); setClazz(Course.class); } - - public Course createWithRuntimeException(final Course entity) { - throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); - } - - public Course createWithCheckedException(final Course entity) throws SQLException { - throw new SQLException("Throwing exception for demoing Rollback!!!"); - } } diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 21f947a925..400c7d4843 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -3,6 +3,7 @@ package com.baeldung.spring.transaction; import java.sql.SQLException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; @@ -15,17 +16,20 @@ public class CourseService { @Transactional public void createCourseDeclarativeWithRuntimeException(Course course) { - courseDao.createWithRuntimeException(course); + courseDao.create(course); + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); } @Transactional(rollbackFor = { SQLException.class }) public void createCourseDeclarativeWithCheckedException(Course course) throws SQLException { - courseDao.createWithCheckedException(course); + courseDao.create(course); + throw new SQLException("Throwing exception for demoing Rollback!!!"); } public void createCourseDefaultRatingProgramatic(Course course) { try { - courseDao.createWithRuntimeException(course); + courseDao.create(course); + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } From 68d3abae10124c5d5d2b103252be20d54d209cdb Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 10:50:19 +0100 Subject: [PATCH 427/590] JAVA-3537: Move spring-rest-simple into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-simple}/README.md | 0 .../spring-rest-simple}/pom.xml | 2 +- .../src/main/java/com/baeldung/Application.java | 0 .../java/com/baeldung/apachefileupload/UploadController.java | 0 .../src/main/java/com/baeldung/config/MvcConfig.java | 0 .../com/baeldung/config/converter/KryoHttpMessageConverter.java | 0 .../src/main/java/com/baeldung/repository/BookRepository.java | 0 .../java/com/baeldung/web/controller/ApiExceptionHandler.java | 0 .../main/java/com/baeldung/web/controller/BookController.java | 0 .../main/java/com/baeldung/web/controller/FooController.java | 0 .../src/main/java/com/baeldung/web/dto/Bazz.java | 0 .../src/main/java/com/baeldung/web/dto/Book.java | 0 .../src/main/java/com/baeldung/web/dto/Foo.java | 0 .../src/main/java/com/baeldung/web/dto/FooProtos.java | 0 .../src/main/java/com/baeldung/web/error/ApiErrorResponse.java | 0 .../main/java/com/baeldung/web/error/BookNotFoundException.java | 0 .../src/main/java/com/baeldung/web/util/LinkUtil.java | 0 .../src/main/resources/application.properties | 0 .../spring-rest-simple}/src/main/resources/logback.xml | 0 .../spring-rest-simple}/src/main/webapp/WEB-INF/company.html | 0 .../src/main/webapp/WEB-INF/spring-views.xml | 0 .../src/main/webapp/WEB-INF/spring-web-config.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../java/com/baeldung/repository/BookRepositoryUnitTest.java | 0 .../baeldung/web/controller/BookControllerIntegrationTest.java | 0 .../java/com/baeldung/web/controller/mediatypes/TestConfig.java | 0 .../test/java/com/baeldung/web/test/RequestMappingLiveTest.java | 0 .../java/com/baeldung/web/test/RestTemplateBasicLiveTest.java | 0 .../baeldung/web/test/SpringHttpMessageConvertersLiveTest.java | 0 .../com/baeldung/web/test/TestRestTemplateBasicLiveTest.java | 0 .../src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java | 0 .../spring-rest-simple}/src/test/resources/.gitignore | 0 34 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/README.md (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/pom.xml (99%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/Application.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/apachefileupload/UploadController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/config/MvcConfig.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/repository/BookRepository.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/BookController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Bazz.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Book.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Foo.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/FooProtos.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/error/ApiErrorResponse.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/error/BookNotFoundException.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/util/LinkUtil.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/resources/application.properties (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/resources/logback.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/company.html (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/spring-views.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/spring-web-config.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/resources/.gitignore (100%) diff --git a/pom.xml b/pom.xml index 16de220d8c..208a0f5d87 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-reactor spring-remoting - spring-rest-simple spring-resttemplate spring-rest-testing spring-roo @@ -1119,7 +1118,6 @@ spring-reactor spring-remoting - spring-rest-simple spring-resttemplate spring-rest-testing spring-roo diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index d2d8b5d816..6252a6360f 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -32,6 +32,7 @@ spring-rest-http-2 spring-rest-query-language spring-rest-shell + spring-rest-simple spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-simple/README.md b/spring-web-modules/spring-rest-simple/README.md similarity index 100% rename from spring-rest-simple/README.md rename to spring-web-modules/spring-rest-simple/README.md diff --git a/spring-rest-simple/pom.xml b/spring-web-modules/spring-rest-simple/pom.xml similarity index 99% rename from spring-rest-simple/pom.xml rename to spring-web-modules/spring-rest-simple/pom.xml index 291053c87f..37a0b99de2 100644 --- a/spring-rest-simple/pom.xml +++ b/spring-web-modules/spring-rest-simple/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-simple/src/main/java/com/baeldung/Application.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/Application.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/Application.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/Application.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java diff --git a/spring-rest-simple/src/main/resources/application.properties b/spring-web-modules/spring-rest-simple/src/main/resources/application.properties similarity index 100% rename from spring-rest-simple/src/main/resources/application.properties rename to spring-web-modules/spring-rest-simple/src/main/resources/application.properties diff --git a/spring-rest-simple/src/main/resources/logback.xml b/spring-web-modules/spring-rest-simple/src/main/resources/logback.xml similarity index 100% rename from spring-rest-simple/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-simple/src/main/resources/logback.xml diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/company.html b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/company.html similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/company.html rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/company.html diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml diff --git a/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java diff --git a/spring-rest-simple/src/test/resources/.gitignore b/spring-web-modules/spring-rest-simple/src/test/resources/.gitignore similarity index 100% rename from spring-rest-simple/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-simple/src/test/resources/.gitignore From f49df277d4e40d46034cd4a047fdaaf39f853556 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 12:29:07 +0100 Subject: [PATCH 428/590] JAVA-3586: Upgrade commons-lang3 to 3.11 in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 16de220d8c..41274250cd 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ 2.21.0 2.5 2.6 - 3.5 + 3.11 1.4 3.0.0 3.1.0 From 3cb1b8536f89fc90ff9bd9dd38f59185c67b979b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 12:50:24 +0100 Subject: [PATCH 429/590] JAVA-3586: Use commons-lang3.version property --- core-java-modules/core-java-15/pom.xml | 3 +-- core-java-modules/core-java-9/pom.xml | 2 +- core-java-modules/core-java-collections-3/pom.xml | 2 +- java-numbers-3/pom.xml | 3 +-- java-numbers-4/pom.xml | 3 +-- jhipster/jhipster-microservice/car-app/pom.xml | 3 +-- jhipster/jhipster-microservice/dealer-app/pom.xml | 3 +-- jhipster/jhipster-microservice/gateway-app/pom.xml | 3 +-- jhipster/jhipster-monolithic/pom.xml | 3 +-- maven-modules/versions-maven-plugin/pom.xml | 3 +-- persistence-modules/hibernate-annotations/pom.xml | 3 +-- quarkus/pom.xml | 2 +- 12 files changed, 12 insertions(+), 21 deletions(-) diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index df8aeafca9..3b0d324d10 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -20,7 +20,7 @@ org.apache.commons commons-lang3 - ${apache-commons-lang3.version} + ${commons-lang3.version} org.assertj @@ -68,7 +68,6 @@ 15 - 3.11 3.17.2 3.8.1 3.0.0-M3 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index d7894934b1..05dc8ba5eb 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -47,7 +47,7 @@ org.apache.commons commons-lang3 - 3.11 + ${commons-lang3.version} commons-io diff --git a/core-java-modules/core-java-collections-3/pom.xml b/core-java-modules/core-java-collections-3/pom.xml index a9a05f5092..602fcf60f4 100644 --- a/core-java-modules/core-java-collections-3/pom.xml +++ b/core-java-modules/core-java-collections-3/pom.xml @@ -35,7 +35,7 @@ org.apache.commons commons-lang3 - 3.10 + ${commons-lang3.version} diff --git a/java-numbers-3/pom.xml b/java-numbers-3/pom.xml index 495618885a..62225a898f 100644 --- a/java-numbers-3/pom.xml +++ b/java-numbers-3/pom.xml @@ -27,7 +27,7 @@ org.apache.commons commons-lang3 - ${commons.version} + ${commons-lang3.version} test @@ -51,7 +51,6 @@ 2.6.0 0.10.2 - 3.9 3.6.1 diff --git a/java-numbers-4/pom.xml b/java-numbers-4/pom.xml index e1722fb039..f4b0e23bd7 100644 --- a/java-numbers-4/pom.xml +++ b/java-numbers-4/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-lang3 - ${commons.version} + ${commons-lang3.version} test @@ -45,7 +45,6 @@ 0.10.2 - 3.9 3.6.1 diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml index c53ea8358e..603d53299c 100644 --- a/jhipster/jhipster-microservice/car-app/pom.xml +++ b/jhipster/jhipster-microservice/car-app/pom.xml @@ -22,7 +22,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.2 5.2.8.Final @@ -267,7 +266,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml index a0bcc73e31..0e492d3d13 100644 --- a/jhipster/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster/jhipster-microservice/dealer-app/pom.xml @@ -21,7 +21,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.2 5.2.8.Final @@ -266,7 +265,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml index c6dcbb3f3e..c5e7364f57 100644 --- a/jhipster/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster/jhipster-microservice/gateway-app/pom.xml @@ -23,7 +23,6 @@ 3.6.0 1.10 2.5 - 3.5 0.4.13 1.3 1.2 @@ -299,7 +298,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index 04f790faf5..103f48424f 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -171,7 +171,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj @@ -888,7 +888,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.3 2.2.1 diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 3a9134ff40..3c6f2eeb3e 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} @@ -74,7 +74,6 @@ 2.3 2.7 1.9.1 - 3.0 4.0 diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 5367921f31..368eee2115 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -30,7 +30,7 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} @@ -67,7 +67,6 @@ 2.1.7.RELEASE 5.4.7.Final 1.4.200 - 3.8.1 0.9 diff --git a/quarkus/pom.xml b/quarkus/pom.xml index 7fdf1557fb..9c14afca3c 100644 --- a/quarkus/pom.xml +++ b/quarkus/pom.xml @@ -48,7 +48,7 @@ org.apache.commons commons-lang3 - 3.9 + ${commons-lang3.version} org.projectlombok From 5f78600cf7df8efd88c4f0e64c33d2d8437ed43b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 13:33:47 +0100 Subject: [PATCH 430/590] JAVA-3586: Fix versions-maven-plugin pom.xml --- maven-modules/versions-maven-plugin/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 3c6f2eeb3e..ff49811430 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.apache.commons commons-lang3 - ${commons-lang3.version} + ${commons.lang3.version} @@ -75,6 +75,7 @@ 2.7 1.9.1 4.0 + 3.11 \ No newline at end of file From 7dc8fdba7eaab562793c96c3c52888669b824d04 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 16:27:21 +0100 Subject: [PATCH 431/590] JAVA-3538: Move spring-rest-testing into spring-web-modules --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-rest-testing}/.gitignore | 0 .../spring-rest-testing}/README.md | 0 .../spring-rest-testing}/pom.xml | 2 +- .../ExceptionTestingApplication.java | 48 +++---- .../controller/ExceptionController.java | 62 ++++----- .../exception/BadArgumentsException.java | 26 ++-- .../exception/InternalException.java | 26 ++-- .../exception/ResourceNotFoundException.java | 26 ++-- .../com/baeldung/persistence/IOperations.java | 0 .../com/baeldung/persistence/dao/IFooDao.java | 0 .../com/baeldung/persistence/model/Foo.java | 0 .../com/baeldung/persistence/model/User.java | 0 .../persistence/service/IFooService.java | 0 .../service/common/AbstractService.java | 0 .../persistence/service/impl/FooService.java | 0 .../java/com/baeldung/spring/Application.java | 0 .../baeldung/spring/PersistenceConfig.java | 0 .../java/com/baeldung/spring/WebConfig.java | 0 .../web/controller/FooController.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/RootController.java | 0 .../MyResourceNotFoundException.java | 0 .../web/metric/ActuatorMetricService.java | 0 .../metric/CustomActuatorMetricService.java | 0 .../web/metric/IActuatorMetricService.java | 0 .../metric/ICustomActuatorMetricService.java | 0 .../baeldung/web/metric/IMetricService.java | 0 .../com/baeldung/web/metric/MetricFilter.java | 0 .../baeldung/web/metric/MetricService.java | 0 .../baeldung/web/util/RestPreconditions.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/graph.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/Consts.java | 0 .../SpringContextIntegrationTest.java | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../ExceptionControllerUnitTest.java | 130 +++++++++--------- .../persistence/PersistenceTestSuite.java | 0 ...ractServicePersistenceIntegrationTest.java | 0 .../FooServicePersistenceIntegrationTest.java | 0 .../test/java/com/baeldung/util/IDUtil.java | 0 .../src/test/resources/.gitignore | 0 .../spring-rest-testing}/src/testFile | 0 51 files changed, 161 insertions(+), 162 deletions(-) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/README.md (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/pom.xml (99%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/IOperations.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/dao/IFooDao.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/Foo.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/IFooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/common/AbstractService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/impl/FooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/WebConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/HomeController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/RootController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricFilter.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/util/RestPreconditions.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/application.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/logback.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-h2.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-mysql.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/graph.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/Consts.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/util/IDUtil.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/resources/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/testFile (100%) diff --git a/pom.xml b/pom.xml index 208a0f5d87..d27d7350b3 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling @@ -1119,7 +1118,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 6252a6360f..640c7c3660 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -33,6 +33,7 @@ spring-rest-query-language spring-rest-shell spring-rest-simple + spring-rest-testing spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-testing/.gitignore b/spring-web-modules/spring-rest-testing/.gitignore similarity index 100% rename from spring-rest-testing/.gitignore rename to spring-web-modules/spring-rest-testing/.gitignore diff --git a/spring-rest-testing/README.md b/spring-web-modules/spring-rest-testing/README.md similarity index 100% rename from spring-rest-testing/README.md rename to spring-web-modules/spring-rest-testing/README.md diff --git a/spring-rest-testing/pom.xml b/spring-web-modules/spring-rest-testing/pom.xml similarity index 99% rename from spring-rest-testing/pom.xml rename to spring-web-modules/spring-rest-testing/pom.xml index 0e947260f4..fea8d25e4d 100644 --- a/spring-rest-testing/pom.xml +++ b/spring-web-modules/spring-rest-testing/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java index facc300dfa..b6e62b7295 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java @@ -1,25 +1,25 @@ -package com.baeldung.exceptiontesting; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * Main Application Class - uses Spring Boot. Just run this as a normal Java - * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) - * - */ -@EnableScheduling -@EnableAutoConfiguration -@ComponentScan("com.baeldung.exceptiontesting") -@SpringBootApplication -public class ExceptionTestingApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(ExceptionTestingApplication.class, args); - } - +package com.baeldung.exceptiontesting; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * Main Application Class - uses Spring Boot. Just run this as a normal Java + * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) + * + */ +@EnableScheduling +@EnableAutoConfiguration +@ComponentScan("com.baeldung.exceptiontesting") +@SpringBootApplication +public class ExceptionTestingApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(ExceptionTestingApplication.class, args); + } + } \ No newline at end of file diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java index 0f458b5f10..6d98337e40 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java @@ -1,31 +1,31 @@ -package com.baeldung.exceptiontesting.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -@RestController -public class ExceptionController { - - @GetMapping("/exception/{exception_id}") - public void getSpecificException(@PathVariable("exception_id") String pException) { - if("not_found".equals(pException)) { - throw new ResourceNotFoundException("resource not found"); - } - else if("bad_arguments".equals(pException)) { - throw new BadArgumentsException("bad arguments"); - } - else { - throw new InternalException("internal error"); - } - } - - @GetMapping("/exception/throw") - public void getException() throws Exception { - throw new Exception("error"); - } -} +package com.baeldung.exceptiontesting.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +@RestController +public class ExceptionController { + + @GetMapping("/exception/{exception_id}") + public void getSpecificException(@PathVariable("exception_id") String pException) { + if("not_found".equals(pException)) { + throw new ResourceNotFoundException("resource not found"); + } + else if("bad_arguments".equals(pException)) { + throw new BadArgumentsException("bad arguments"); + } + else { + throw new InternalException("internal error"); + } + } + + @GetMapping("/exception/throw") + public void getException() throws Exception { + throw new Exception("error"); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java index 1eb1e6a3c9..1f0e1c1ddb 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadArgumentsException extends RuntimeException { - - public BadArgumentsException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadArgumentsException extends RuntimeException { + + public BadArgumentsException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java index 8e9f0f60f3..854d6a57f0 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) -public class InternalException extends RuntimeException { - - public InternalException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) +public class InternalException extends RuntimeException { + + public InternalException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java index 469d5af96f..6d6e6ef712 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.NOT_FOUND) -public class ResourceNotFoundException extends RuntimeException { - - public ResourceNotFoundException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.NOT_FOUND) +public class ResourceNotFoundException extends RuntimeException { + + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java diff --git a/spring-rest-testing/src/main/resources/application.properties b/spring-web-modules/spring-rest-testing/src/main/resources/application.properties similarity index 100% rename from spring-rest-testing/src/main/resources/application.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/application.properties diff --git a/spring-rest-testing/src/main/resources/logback.xml b/spring-web-modules/spring-rest-testing/src/main/resources/logback.xml similarity index 100% rename from spring-rest-testing/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/logback.xml diff --git a/spring-rest-testing/src/main/resources/persistence-h2.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-h2.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties diff --git a/spring-rest-testing/src/main/resources/persistence-mysql.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-mysql.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties diff --git a/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml b/spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-testing/src/test/java/com/baeldung/Consts.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/Consts.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java similarity index 97% rename from spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java index d624efcdd0..8e1eaad977 100644 --- a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java +++ b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java @@ -1,65 +1,65 @@ -package com.baeldung.exceptiontesting.controller; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -import com.baeldung.exceptiontesting.controller.ExceptionController; -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@RunWith(SpringRunner.class) -@WebMvcTest(ExceptionController.class) -public class ExceptionControllerUnitTest{ - - @Autowired - private MockMvc mvc; - - @Test - public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { - String exceptionParam = "not_found"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) - .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); - } - - @Test - public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { - String exceptionParam = "bad_arguments"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) - .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); - } - - @Test - public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { - String exceptionParam = "dummy"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) - .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); - } - - @Test(expected = Exception.class) - public void whenGetException_thenInternalServerError() throws Exception { - mvc.perform(get("/exception/throw") - .contentType(MediaType.APPLICATION_JSON)); - } -} +package com.baeldung.exceptiontesting.controller; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.exceptiontesting.controller.ExceptionController; +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringRunner.class) +@WebMvcTest(ExceptionController.class) +public class ExceptionControllerUnitTest{ + + @Autowired + private MockMvc mvc; + + @Test + public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { + String exceptionParam = "not_found"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) + .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); + } + + @Test + public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { + String exceptionParam = "bad_arguments"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) + .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); + } + + @Test + public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { + String exceptionParam = "dummy"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) + .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); + } + + @Test(expected = Exception.class) + public void whenGetException_thenInternalServerError() throws Exception { + mvc.perform(get("/exception/throw") + .contentType(MediaType.APPLICATION_JSON)); + } +} diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java diff --git a/spring-rest-testing/src/test/resources/.gitignore b/spring-web-modules/spring-rest-testing/src/test/resources/.gitignore similarity index 100% rename from spring-rest-testing/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-testing/src/test/resources/.gitignore diff --git a/spring-rest-testing/src/testFile b/spring-web-modules/spring-rest-testing/src/testFile similarity index 100% rename from spring-rest-testing/src/testFile rename to spring-web-modules/spring-rest-testing/src/testFile From 6daa38007c206871ad2d1af496ab390a8322e84c Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Tue, 5 Jan 2021 01:32:23 +0800 Subject: [PATCH 432/590] [BAEL-4601] How to convert a Hibernate proxy to a real entity object * Adds Domain Models * Adds Integration Tests --- .../hibernateunproxy/CreditCardPayment.java | 20 +++++ .../jpa/hibernateunproxy/Payment.java | 47 ++++++++++++ .../jpa/hibernateunproxy/PaymentReceipt.java | 53 +++++++++++++ .../jpa/hibernateunproxy/WebUser.java | 42 +++++++++++ .../main/resources/META-INF/persistence.xml | 20 +++++ .../HibernateProxyIntegrationTest.java | 75 +++++++++++++++++++ 6 files changed, 257 insertions(+) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java new file mode 100644 index 0000000000..6eb41f7ccc --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java @@ -0,0 +1,20 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import java.math.BigDecimal; + +@Entity +public class CreditCardPayment extends Payment { + + private String cardNumber; + + CreditCardPayment(BigDecimal amount, WebUser webUser, String cardNumber) { + this.amount = amount; + this.webUser = webUser; + this.cardNumber = cardNumber; + } + + protected CreditCardPayment() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java new file mode 100644 index 0000000000..9e70da5f65 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java @@ -0,0 +1,47 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; +import java.math.BigDecimal; +import java.util.Objects; + +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Payment { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + protected WebUser webUser; + + protected BigDecimal amount; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Payment payment = (Payment) o; + + return Objects.equals(id, payment.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Payment() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java new file mode 100644 index 0000000000..530839eef4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java @@ -0,0 +1,53 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import java.util.Objects; +import java.util.UUID; + +@Entity +public class PaymentReceipt { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + private Payment payment; + + private String transactionNumber; + + PaymentReceipt(Payment payment) { + this.payment = payment; + this.transactionNumber = UUID.randomUUID().toString(); + } + + public Payment getPayment() { + return payment; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + PaymentReceipt that = (PaymentReceipt) o; + + return Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected PaymentReceipt() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java new file mode 100644 index 0000000000..d3f82bacd4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java @@ -0,0 +1,42 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Objects; + +@Entity +public class WebUser { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + WebUser(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + WebUser webUser = (WebUser) o; + + return Objects.equals(id, webUser.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected WebUser() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index f428fea07b..19ecae8491 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -77,4 +77,24 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.hibernateunproxy.Payment + com.baeldung.jpa.hibernateunproxy.CreditCardPayment + com.baeldung.jpa.hibernateunproxy.PaymentReceipt + com.baeldung.jpa.hibernateunproxy.WebUser + true + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java new file mode 100644 index 0000000000..a831639f5d --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.jpa.hibernateunproxy; + +import org.hibernate.Hibernate; +import org.hibernate.proxy.HibernateProxy; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class HibernateProxyIntegrationTest { + + private static EntityManager entityManager; + + @BeforeAll + public static void setup() { + EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-hibernate-unproxy"); + entityManager = factory.createEntityManager(); + populateH2DB(); + } + + @Test + public void givenPaymentReceipt_whenAccessingPayment_thenVerifyType() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + Assert.assertEquals(true, paymentReceipt.getPayment() instanceof HibernateProxy); + } + + @Test + public void givenWebUserProxy_whenCreatingPayment_thenExecuteSingleStatement() { + entityManager.getTransaction().begin(); + + WebUser webUser = entityManager.getReference(WebUser.class, 1L); + Payment payment = new CreditCardPayment(new BigDecimal(100), webUser, "CN-1234"); + entityManager.persist(payment); + + entityManager.getTransaction().commit(); + Assert.assertEquals(true, webUser instanceof HibernateProxy); + } + + @Test + public void givenPaymentReceipt_whenCastingPaymentToConcreteClass_thenThrowClassCastException() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + assertThrows(ClassCastException.class, () -> { + CreditCardPayment creditCardPayment = (CreditCardPayment) paymentReceipt.getPayment(); + }); + } + + @Test + public void givenPaymentReceipt_whenPaymentIsUnproxied_thenReturnRealEntityObject() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + Assert.assertEquals(true, Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); + } + + private static void populateH2DB() { + entityManager.getTransaction().begin(); + + WebUser webUser = new WebUser("name"); + entityManager.persist(webUser); + + Payment payment = new CreditCardPayment(new BigDecimal(100), webUser, "CN-1234"); + entityManager.persist(payment); + + PaymentReceipt receipt = new PaymentReceipt(payment); + entityManager.persist(receipt); + + entityManager.getTransaction().commit(); + entityManager.clear(); + } + +} From d8c26b6adb3e9a0a147276832a2b7523b4f7ca34 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 23:01:41 +0100 Subject: [PATCH 433/590] JAVA-3586: Get rid of the overriden commons-lang3.version property --- blade/pom.xml | 1 - .../core-java-arrays-operations-advanced/pom.xml | 2 -- core-java-modules/core-java-arrays-operations-basic/pom.xml | 4 ---- core-java-modules/core-java-arrays-sorting/pom.xml | 4 ---- core-java-modules/core-java-collections-list/pom.xml | 1 - core-java-modules/core-java-lang-2/pom.xml | 1 - core-java-modules/core-java-string-algorithms-2/pom.xml | 1 - core-java-modules/core-java-string-algorithms-3/pom.xml | 1 - core-java-modules/core-java-string-algorithms/pom.xml | 1 - core-java-modules/core-java-string-operations-2/pom.xml | 1 - core-java-modules/core-java-string-operations/pom.xml | 1 - json-2/pom.xml | 1 - libraries-apache-commons/pom.xml | 1 - maven-modules/versions-maven-plugin/original/pom.xml | 1 - persistence-modules/hibernate-annotations/pom.xml | 1 - persistence-modules/hibernate-mapping/pom.xml | 1 - spring-web-modules/spring-mvc-java/pom.xml | 1 - xml/pom.xml | 1 - 18 files changed, 25 deletions(-) diff --git a/blade/pom.xml b/blade/pom.xml index 178d1afb52..458ec40051 100644 --- a/blade/pom.xml +++ b/blade/pom.xml @@ -154,7 +154,6 @@ 2.0.14.RELEASE 4.2.1 - 3.8.1 1.18.4 4.5.6 4.5.6 diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml index d73fdcee28..c7ea09c616 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -29,8 +29,6 @@ - 3.9 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-basic/pom.xml b/core-java-modules/core-java-arrays-operations-basic/pom.xml index 64856d9b39..dcee6547a0 100644 --- a/core-java-modules/core-java-arrays-operations-basic/pom.xml +++ b/core-java-modules/core-java-arrays-operations-basic/pom.xml @@ -68,11 +68,7 @@ 3.2.0 - - 3.9 - 1.19 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-sorting/pom.xml b/core-java-modules/core-java-arrays-sorting/pom.xml index 9b307870a1..9b900c3de6 100644 --- a/core-java-modules/core-java-arrays-sorting/pom.xml +++ b/core-java-modules/core-java-arrays-sorting/pom.xml @@ -76,12 +76,8 @@ 3.2.0 - - 3.9 28.2-jre - 1.19 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml index 509f58ea61..76ca66fe70 100644 --- a/core-java-modules/core-java-collections-list/pom.xml +++ b/core-java-modules/core-java-collections-list/pom.xml @@ -36,7 +36,6 @@ 4.1 - 3.8.1 3.11.1 diff --git a/core-java-modules/core-java-lang-2/pom.xml b/core-java-modules/core-java-lang-2/pom.xml index 5f2d4ec901..d395e8efb1 100644 --- a/core-java-modules/core-java-lang-2/pom.xml +++ b/core-java-modules/core-java-lang-2/pom.xml @@ -69,7 +69,6 @@ 1.19 3.12.2 1.9.4 - 3.10 29.0-jre diff --git a/core-java-modules/core-java-string-algorithms-2/pom.xml b/core-java-modules/core-java-string-algorithms-2/pom.xml index a635cd8022..2a84cebb4c 100644 --- a/core-java-modules/core-java-string-algorithms-2/pom.xml +++ b/core-java-modules/core-java-string-algorithms-2/pom.xml @@ -61,7 +61,6 @@ - 3.8.1 3.6.1 1.2 diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index 2725ba84c6..610956588e 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -59,7 +59,6 @@ - 3.8.1 3.6.1 28.1-jre diff --git a/core-java-modules/core-java-string-algorithms/pom.xml b/core-java-modules/core-java-string-algorithms/pom.xml index 85879d74e2..6ba9ae7bb3 100644 --- a/core-java-modules/core-java-string-algorithms/pom.xml +++ b/core-java-modules/core-java-string-algorithms/pom.xml @@ -65,7 +65,6 @@ - 3.8.1 27.0.1-jre 0.4.0 3.6.1 diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index db32bf97a1..5865d9a776 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -112,7 +112,6 @@ 3.6.1 2.0.0.Final - 3.8.1 28.2-jre 6.0.2.Final 3.0.0 diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index c5791e929e..9632988392 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -60,7 +60,6 @@ - 3.9 3.6.1 1.10 diff --git a/json-2/pom.xml b/json-2/pom.xml index 0bdede3b1a..e27d1c83f6 100644 --- a/json-2/pom.xml +++ b/json-2/pom.xml @@ -114,7 +114,6 @@ 0.9.23 3.11.1 1.9.2 - 3.9 diff --git a/libraries-apache-commons/pom.xml b/libraries-apache-commons/pom.xml index 74adddabcf..08dddac880 100644 --- a/libraries-apache-commons/pom.xml +++ b/libraries-apache-commons/pom.xml @@ -65,7 +65,6 @@ - 3.6 1.1 1.9.3 1.2 diff --git a/maven-modules/versions-maven-plugin/original/pom.xml b/maven-modules/versions-maven-plugin/original/pom.xml index f705dae5c5..c36a5913c2 100644 --- a/maven-modules/versions-maven-plugin/original/pom.xml +++ b/maven-modules/versions-maven-plugin/original/pom.xml @@ -74,7 +74,6 @@ 1.15 2.3 4.0 - 3.0 1.9.1 2.7 diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 368eee2115..230de2e17e 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -62,7 +62,6 @@ 5.4.7.Final 1.4.200 - 3.8.1 true 2.1.7.RELEASE 5.4.7.Final diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 4eabc5d298..155eefa526 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -71,7 +71,6 @@ 3.0.1-b11 1.0.3 1.3 - 3.9 2.6 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 179ac0fb54..ec302eed57 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -234,7 +234,6 @@ 19.0 - 3.5 1.3.2 2.5 1.4 diff --git a/xml/pom.xml b/xml/pom.xml index 8b2df41af6..cbad5b37f0 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -379,7 +379,6 @@ 2.3.29 0.9.6 - 3.5 2.4 1.8 From f361ccc834363018a7d5f924e21c88b3ab0a0105 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 5 Jan 2021 14:10:30 +0100 Subject: [PATCH 434/590] JAVA-3540: Move spring-resttemplate into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-resttemplate}/.gitignore | 0 .../spring-resttemplate}/README.md | 0 .../spring-resttemplate}/pom.xml | 2 +- .../baeldung/responseheaders/ResponseHeadersApplication.java | 0 .../controllers/FilterResponseHeaderController.java | 0 .../responseheaders/controllers/ResponseHeaderController.java | 0 .../responseheaders/filter/AddResponseHeaderFilter.java | 0 .../resttemplate/RestTemplateConfigurationApplication.java | 0 .../configuration/CustomClientHttpRequestInterceptor.java | 0 .../configuration/CustomRestTemplateCustomizer.java | 0 .../com/baeldung/resttemplate/configuration/FooController.java | 0 .../baeldung/resttemplate/configuration/HelloController.java | 0 .../com/baeldung/resttemplate/configuration/SpringConfig.java | 0 .../com/baeldung/resttemplate/lists/EmployeeApplication.java | 0 .../com/baeldung/resttemplate/lists/client/EmployeeClient.java | 0 .../resttemplate/lists/controller/EmployeeResource.java | 0 .../main/java/com/baeldung/resttemplate/lists/dto/Employee.java | 0 .../java/com/baeldung/resttemplate/lists/dto/EmployeeList.java | 0 .../baeldung/resttemplate/lists/service/EmployeeService.java | 0 .../src/main/java/com/baeldung/resttemplate/web/dto/Foo.java | 0 .../baeldung/resttemplate/web/exception/NotFoundException.java | 0 .../web/handler/RestTemplateResponseErrorHandler.java | 0 .../src/main/java/com/baeldung/resttemplate/web/model/Bar.java | 0 .../main/java/com/baeldung/resttemplate/web/model/Employee.java | 0 .../baeldung/resttemplate/web/service/BarConsumerService.java | 0 .../com/baeldung/resttemplate/web/service/EmployeeService.java | 0 .../java/com/baeldung/sampleapp/config/MainApplication.java | 0 .../java/com/baeldung/sampleapp/config/RestClientConfig.java | 0 .../src/main/java/com/baeldung/sampleapp/config/WebConfig.java | 0 .../interceptors/RestTemplateHeaderModifierInterceptor.java | 0 .../baeldung/sampleapp/repository/HeavyResourceRepository.java | 0 .../sampleapp/web/controller/BarMappingExamplesController.java | 0 .../baeldung/sampleapp/web/controller/CompanyController.java | 0 .../sampleapp/web/controller/DeferredResultController.java | 0 .../sampleapp/web/controller/HeavyResourceController.java | 0 .../com/baeldung/sampleapp/web/controller/ItemController.java | 0 .../com/baeldung/sampleapp/web/controller/MyFooController.java | 0 .../com/baeldung/sampleapp/web/controller/PactController.java | 0 .../baeldung/sampleapp/web/controller/SimplePostController.java | 0 .../sampleapp/web/controller/redirect/RedirectController.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Company.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Foo.java | 0 .../main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java | 0 .../baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java | 0 .../sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Item.java | 0 .../main/java/com/baeldung/sampleapp/web/dto/ItemManager.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Views.java | 0 .../sampleapp/web/exception/ResourceNotFoundException.java | 0 .../src/main/java/com/baeldung/transfer/LoginForm.java | 0 .../java/com/baeldung/web/upload/app/UploadApplication.java | 0 .../baeldung/web/upload/client/MultipartFileUploadClient.java | 0 .../com/baeldung/web/upload/controller/FileServerResource.java | 0 .../src/main/resources/application.properties | 0 .../spring-resttemplate}/src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../src/test/java/com/baeldung/SpringTestConfig.java | 0 .../src/test/java/com/baeldung/client/Consts.java | 0 .../java/com/baeldung/client/TestRestTemplateBasicLiveTest.java | 0 .../src/test/java/com/baeldung/pact/PactProviderLiveTest.java | 0 .../baeldung/resttemplate/LargeFileDownloadIntegrationTest.java | 0 .../com/baeldung/resttemplate/RestTemplateBasicLiveTest.java | 0 .../java/com/baeldung/resttemplate/RestTemplateLiveTest.java | 0 .../controller/redirect/RedirectControllerIntegrationTest.java | 0 .../RestTemplateResponseErrorHandlerIntegrationTest.java | 0 .../service/EmployeeServiceMockRestServiceServerUnitTest.java | 0 .../java/com/baeldung/web/service/EmployeeServiceUnitTest.java | 0 .../spring-resttemplate}/src/test/resources/.gitignore | 0 .../spring-resttemplate}/src/test/resources/logback-test.xml | 0 72 files changed, 2 insertions(+), 3 deletions(-) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/.gitignore (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/README.md (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/pom.xml (99%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/FooController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/model/Bar.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/model/Employee.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/MainApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/WebConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Company.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Item.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Views.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/transfer/LoginForm.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/app/UploadApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/resources/application.properties (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/resources/logback.xml (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/SpringTestConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/client/Consts.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/pact/PactProviderLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/resources/.gitignore (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/resources/logback-test.xml (100%) diff --git a/pom.xml b/pom.xml index d27d7350b3..464134b572 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-reactor spring-remoting - spring-resttemplate spring-roo spring-scheduling @@ -1117,7 +1116,6 @@ spring-reactor spring-remoting - spring-resttemplate spring-roo spring-scheduling diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 640c7c3660..e00ae3e899 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -34,6 +34,7 @@ spring-rest-shell spring-rest-simple spring-rest-testing + spring-resttemplate spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-resttemplate/.gitignore b/spring-web-modules/spring-resttemplate/.gitignore similarity index 100% rename from spring-resttemplate/.gitignore rename to spring-web-modules/spring-resttemplate/.gitignore diff --git a/spring-resttemplate/README.md b/spring-web-modules/spring-resttemplate/README.md similarity index 100% rename from spring-resttemplate/README.md rename to spring-web-modules/spring-resttemplate/README.md diff --git a/spring-resttemplate/pom.xml b/spring-web-modules/spring-resttemplate/pom.xml similarity index 99% rename from spring-resttemplate/pom.xml rename to spring-web-modules/spring-resttemplate/pom.xml index 05660f5210..c0f266fd62 100644 --- a/spring-resttemplate/pom.xml +++ b/spring-web-modules/spring-resttemplate/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java diff --git a/spring-resttemplate/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate/src/main/resources/application.properties similarity index 100% rename from spring-resttemplate/src/main/resources/application.properties rename to spring-web-modules/spring-resttemplate/src/main/resources/application.properties diff --git a/spring-resttemplate/src/main/resources/logback.xml b/spring-web-modules/spring-resttemplate/src/main/resources/logback.xml similarity index 100% rename from spring-resttemplate/src/main/resources/logback.xml rename to spring-web-modules/spring-resttemplate/src/main/resources/logback.xml diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/client/Consts.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java diff --git a/spring-resttemplate/src/test/resources/.gitignore b/spring-web-modules/spring-resttemplate/src/test/resources/.gitignore similarity index 100% rename from spring-resttemplate/src/test/resources/.gitignore rename to spring-web-modules/spring-resttemplate/src/test/resources/.gitignore diff --git a/spring-resttemplate/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate/src/test/resources/logback-test.xml similarity index 100% rename from spring-resttemplate/src/test/resources/logback-test.xml rename to spring-web-modules/spring-resttemplate/src/test/resources/logback-test.xml From 3bf9bf40948c308eeaaed1e9dc5943d37bfe98c8 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 5 Jan 2021 20:17:31 +0530 Subject: [PATCH 435/590] Added no roll back example --- .../java/com/baeldung/spring/transaction/CourseService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 400c7d4843..05e3f32cee 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -35,4 +35,10 @@ public class CourseService { } } + @Transactional(noRollbackFor = { SQLException.class }) + public void createCourseDeclarativeWithNoRollBack(Course course) throws SQLException { + courseDao.create(course); + throw new SQLException("Throwing exception for demoing Rollback!!!"); + } + } From af51e73604d96e45b75d2b076d9d0f14a1f125e8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 5 Jan 2021 23:00:14 +0530 Subject: [PATCH 436/590] JAVA-4011: Moved 1 article from spring-5-security to spring-boot-security --- .../src/main/java/com/baeldung/securityprofile/Application.java | 0 .../java/com/baeldung/securityprofile/ApplicationNoSecurity.java | 0 .../java/com/baeldung/securityprofile/ApplicationSecurity.java | 0 .../java/com/baeldung/securityprofile/EmployeeController.java | 0 .../securityprofile/EmployeeControllerNoSecurityUnitTest.java | 0 .../com/baeldung/securityprofile/EmployeeControllerUnitTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/Application.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/EmployeeController.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java (100%) diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/Application.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/Application.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java diff --git a/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java similarity index 100% rename from spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java rename to spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java diff --git a/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java similarity index 100% rename from spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java rename to spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java From 5fcec971af06230b6fd077f417b0ae30e4a901d8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 5 Jan 2021 23:01:01 +0530 Subject: [PATCH 437/590] JAVA-4011: README changes --- spring-boot-modules/spring-boot-security/README.md | 2 ++ spring-security-modules/spring-5-security/README.md | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-security/README.md b/spring-boot-modules/spring-boot-security/README.md index 7229ba0f4a..2c9d37eac0 100644 --- a/spring-boot-modules/spring-boot-security/README.md +++ b/spring-boot-modules/spring-boot-security/README.md @@ -8,6 +8,8 @@ This module contains articles about Spring Boot Security - [Spring Security for Spring Boot Integration Tests](https://www.baeldung.com/spring-security-integration-tests) - [Introduction to Spring Security Taglibs](https://www.baeldung.com/spring-security-taglibs) - [Guide to @CurrentSecurityContext in Spring Security](https://www.baeldung.com/spring-currentsecuritycontext) +- [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) + ### Spring Boot Security Auto-Configuration diff --git a/spring-security-modules/spring-5-security/README.md b/spring-security-modules/spring-5-security/README.md index 6847d4bf5c..1917d347fb 100644 --- a/spring-security-modules/spring-5-security/README.md +++ b/spring-security-modules/spring-5-security/README.md @@ -9,6 +9,5 @@ This module contains articles about Spring Security 5 - [New Password Storage In Spring Security 5](https://www.baeldung.com/spring-security-5-password-storage) - [Default Password Encoder in Spring Security 5](https://www.baeldung.com/spring-security-5-default-password-encoder) - [Guide to the AuthenticationManagerResolver in Spring Security](https://www.baeldung.com/spring-security-authenticationmanagerresolver) -- [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) - [Manual Logout With Spring Security](https://www.baeldung.com/spring-security-manual-logout) - [How to Disable Spring Security Logout Redirects](https://www.baeldung.com/spring-security-disable-logout-redirects) From bfa1d207dfc8d7271a4e48e070e4d6714e2f8d9b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:03:21 +0800 Subject: [PATCH 438/590] Update README.md --- core-java-modules/core-java-char/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md index 71f8e943aa..fd79da15ab 100644 --- a/core-java-modules/core-java-char/README.md +++ b/core-java-modules/core-java-char/README.md @@ -3,4 +3,4 @@ This module contains articles about Java Character Class ### Relevant Articles: -- Character#isAlphabetic vs Character#isLetter +- [Character#isAlphabetic vs Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic) From 6ba3be6c81535b1e8976beae5a98dfac3de9da12 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:21:03 +0800 Subject: [PATCH 439/590] Update README.md --- spring-boot-modules/spring-boot-artifacts-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-artifacts-2/README.md b/spring-boot-modules/spring-boot-artifacts-2/README.md index 80e3d95d14..35f9cfab32 100644 --- a/spring-boot-modules/spring-boot-artifacts-2/README.md +++ b/spring-boot-modules/spring-boot-artifacts-2/README.md @@ -4,4 +4,4 @@ This module contains articles about configuring the Spring Boot build process 2. ### Relevant Articles: -TBD \ No newline at end of file +- [Difference Between spring-boot:repackage and Maven package](https://www.baeldung.com/spring-boot-repackage-vs-mvn-package) From cc6a351836ee0f29467b45348f4e9aaa521a4076 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:23:20 +0800 Subject: [PATCH 440/590] Update README.md --- core-java-modules/core-java-11-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-11-2/README.md b/core-java-modules/core-java-11-2/README.md index 834f310fce..c87936b07d 100644 --- a/core-java-modules/core-java-11-2/README.md +++ b/core-java-modules/core-java-11-2/README.md @@ -6,3 +6,4 @@ This module contains articles about Java 11 core features - [Guide to Java 8 Optional](https://www.baeldung.com/java-optional) - [Guide to Java Reflection](http://www.baeldung.com/java-reflection) - [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors) +- [New Features in Java 11](https://www.baeldung.com/java-11-new-features) From eedd1fd70bfab9a73417c099afc0d7f5d4db4cef Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:25:50 +0800 Subject: [PATCH 441/590] Update README.md --- core-java-modules/core-java-12/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-12/README.md b/core-java-modules/core-java-12/README.md index 6c603e4dea..c28df26c6f 100644 --- a/core-java-modules/core-java-12/README.md +++ b/core-java-modules/core-java-12/README.md @@ -2,3 +2,4 @@ - [String API Updates in Java 12](https://www.baeldung.com/java12-string-api) +- [Java 12 New Features](https://www.baeldung.com/java-12-new-features) From 108522e190261b1795fd55b9beb3c94b81af84fd Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 6 Jan 2021 11:16:55 +0100 Subject: [PATCH 442/590] JAVA-3541: Move spring-5-mvc into spring-web-modules --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-5-mvc}/.gitignore | 0 .../spring-5-mvc}/README.md | 0 .../spring-5-mvc}/pom.xml | 3 +- .../src/main/java/com/baeldung/Constants.java | 0 .../java/com/baeldung/Spring5Application.java | 0 .../com/baeldung/html/HtmlApplication.java | 0 .../com/baeldung/html/HtmlController.java | 0 .../java/com/baeldung/idc/Application.java | 0 .../src/main/java/com/baeldung/idc/Book.java | 0 .../java/com/baeldung/idc/BookController.java | 0 .../java/com/baeldung/idc/BookOperations.java | 0 .../java/com/baeldung/idc/BookRepository.java | 0 .../src/main/java/com/baeldung/model/Foo.java | 0 .../baeldung/persistence/DataSetupBean.java | 0 .../baeldung/persistence/FooRepository.java | 0 .../java/com/baeldung/web/FooController.java | 130 +++++++++--------- .../web/ResponseBodyEmitterController.java | 0 .../baeldung/web/SseEmitterController.java | 0 .../web/StreamingResponseBodyController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/jsp/index.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/LiveTest.java | 0 .../Spring5ApplicationIntegrationTest.java | 0 .../com/baeldung/html/HtmlControllerTest.java | 0 28 files changed, 67 insertions(+), 69 deletions(-) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/.gitignore (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/README.md (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/pom.xml (97%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/Constants.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/Spring5Application.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/html/HtmlApplication.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/html/HtmlController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/Application.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/Book.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookOperations.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookRepository.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/model/Foo.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/persistence/DataSetupBean.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/persistence/FooRepository.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/FooController.java (97%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/SseEmitterController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/StreamingResponseBodyController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/resources/application.properties (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/resources/logback.xml (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/webapp/WEB-INF/jsp/index.jsp (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/LiveTest.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/html/HtmlControllerTest.java (100%) diff --git a/pom.xml b/pom.xml index 464134b572..3eca22c173 100644 --- a/pom.xml +++ b/pom.xml @@ -601,7 +601,6 @@ spring-5 spring-5-data-reactive - spring-5-mvc spring-5-reactive spring-5-reactive-2 spring-5-reactive-client @@ -1055,7 +1054,6 @@ spring-5 spring-5-data-reactive - spring-5-mvc spring-5-reactive spring-5-reactive-2 spring-5-reactive-client diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index e00ae3e899..cc2ffcf762 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -14,6 +14,7 @@ + spring-5-mvc spring-mvc-basics spring-mvc-basics-2 spring-mvc-basics-3 diff --git a/spring-5-mvc/.gitignore b/spring-web-modules/spring-5-mvc/.gitignore similarity index 100% rename from spring-5-mvc/.gitignore rename to spring-web-modules/spring-5-mvc/.gitignore diff --git a/spring-5-mvc/README.md b/spring-web-modules/spring-5-mvc/README.md similarity index 100% rename from spring-5-mvc/README.md rename to spring-web-modules/spring-5-mvc/README.md diff --git a/spring-5-mvc/pom.xml b/spring-web-modules/spring-5-mvc/pom.xml similarity index 97% rename from spring-5-mvc/pom.xml rename to spring-web-modules/spring-5-mvc/pom.xml index 39fcd22824..ddcce8207b 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-web-modules/spring-5-mvc/pom.xml @@ -12,8 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 - + ../../parent-boot-2 diff --git a/spring-5-mvc/src/main/java/com/baeldung/Constants.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Constants.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/Constants.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Constants.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/Application.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/Book.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/model/Foo.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java similarity index 97% rename from spring-5-mvc/src/main/java/com/baeldung/web/FooController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java index 137864cddd..8d8e03bbaf 100644 --- a/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java @@ -1,66 +1,66 @@ -package com.baeldung.web; - -import java.util.List; - -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; - -import com.baeldung.model.Foo; -import com.baeldung.persistence.FooRepository; - -@RestController -public class FooController { - - @Autowired - private FooRepository repo; - - // API - read - - @GetMapping("/foos/{id}") - @Validated - public Foo findById(@PathVariable @Min(0) final long id) { - return repo.findById(id).orElse(null); - } - - @GetMapping("/foos") - public List findAll() { - return repo.findAll(); - } - - @GetMapping( value="/foos", params = { "page", "size" }) - @Validated - public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { - return repo.findAll(PageRequest.of(page, size)).getContent(); - } - - // API - write - - @PutMapping("/foos/{id}") - @ResponseStatus(HttpStatus.OK) - public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { - return foo; - } - - @PostMapping("/foos") - @ResponseStatus(HttpStatus.CREATED) - public void create( @RequestBody final Foo foo) { - if (null == foo || null == foo.getName()) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required"); - } - repo.save(foo); - } +package com.baeldung.web; + +import java.util.List; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.HttpStatus; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +import com.baeldung.model.Foo; +import com.baeldung.persistence.FooRepository; + +@RestController +public class FooController { + + @Autowired + private FooRepository repo; + + // API - read + + @GetMapping("/foos/{id}") + @Validated + public Foo findById(@PathVariable @Min(0) final long id) { + return repo.findById(id).orElse(null); + } + + @GetMapping("/foos") + public List findAll() { + return repo.findAll(); + } + + @GetMapping( value="/foos", params = { "page", "size" }) + @Validated + public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { + return repo.findAll(PageRequest.of(page, size)).getContent(); + } + + // API - write + + @PutMapping("/foos/{id}") + @ResponseStatus(HttpStatus.OK) + public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { + return foo; + } + + @PostMapping("/foos") + @ResponseStatus(HttpStatus.CREATED) + public void create( @RequestBody final Foo foo) { + if (null == foo || null == foo.getName()) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required"); + } + repo.save(foo); + } } \ No newline at end of file diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java diff --git a/spring-5-mvc/src/main/resources/application.properties b/spring-web-modules/spring-5-mvc/src/main/resources/application.properties similarity index 100% rename from spring-5-mvc/src/main/resources/application.properties rename to spring-web-modules/spring-5-mvc/src/main/resources/application.properties diff --git a/spring-5-mvc/src/main/resources/logback.xml b/spring-web-modules/spring-5-mvc/src/main/resources/logback.xml similarity index 100% rename from spring-5-mvc/src/main/resources/logback.xml rename to spring-web-modules/spring-5-mvc/src/main/resources/logback.xml diff --git a/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp rename to spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/spring-5-mvc/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-5-mvc/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/web.xml diff --git a/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/LiveTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java diff --git a/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java diff --git a/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java From 83664977f035d37e14f4a075330fa2fb71d66216 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 6 Jan 2021 11:48:27 -0300 Subject: [PATCH 443/590] Updated deprecated ConfigFileApplicationContextInitializer usage, now using ConfigDataApplicationContextInitializer --- .../properties/yamllist/YamlComplexListsUnitTest.java | 4 ++-- .../baeldung/properties/yamllist/YamlSimpleListUnitTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java index 6dc5d61d09..ce9ec38551 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java @@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.baeldung.properties.yamllist.pojo.ApplicationProps; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ApplicationProps.class) class YamlComplexListsUnitTest { diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java index 475a73c7d7..5315c7b9bc 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java @@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.baeldung.properties.yamllist.pojo.ApplicationProps; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ApplicationProps.class) class YamlSimpleListUnitTest { From 1112f95497583488dbdf9f13f9feb38a401be2ad Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 6 Jan 2021 11:49:12 -0300 Subject: [PATCH 444/590] updated deprecated Assert. method usage. This is not related to this 2.4.0 boot update --- .../value/defaults/ValuesWithDefaultsApp.java | 14 +++++++------- .../properties/lists/ListsPropertiesUnitTest.java | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java index 72fa0e03c0..2a2b535be7 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java +++ b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java @@ -51,21 +51,21 @@ public class ValuesWithDefaultsApp { @PostConstruct public void afterInitialize() { // strings - Assert.isTrue(stringWithDefaultValue.equals("my default value")); - Assert.isTrue(stringWithBlankDefaultValue.equals("")); + Assert.isTrue(stringWithDefaultValue.equals("my default value"), "unexpected value for stringWithDefaultValue"); + Assert.isTrue(stringWithBlankDefaultValue.equals(""), "unexpected value for stringWithBlankDefaultValue"); // other primitives - Assert.isTrue(booleanWithDefaultValue); - Assert.isTrue(intWithDefaultValue == 42); + Assert.isTrue(booleanWithDefaultValue, "unexpected value for booleanWithDefaultValue"); + Assert.isTrue(intWithDefaultValue == 42, "unexpected value for intWithDefaultValue"); // arrays List stringListValues = Arrays.asList("one", "two", "three"); - Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues)); + Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults"); List intListValues = Arrays.asList(1, 2, 3); - Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues)); + Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults"); // SpEL - Assert.isTrue(spelWithDefaultValue.equals("my default system property value")); + Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java index 60ba4cc108..1abb643d75 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SpringListPropertiesApplication.class) @@ -47,7 +48,7 @@ public class ListsPropertiesUnitTest { @Test public void whenContextIsInitialized_thenInjectedArrayContainsExpectedValues() { - assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); + assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); } @Test @@ -82,7 +83,7 @@ public class ListsPropertiesUnitTest { String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); - assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); + assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStrings); } } From 567e9109038dcdd0bc2536c3d4f24c7622d74120 Mon Sep 17 00:00:00 2001 From: MeenaGawande <45625809+MeenaGawande@users.noreply.github.com> Date: Wed, 6 Jan 2021 23:36:07 +0530 Subject: [PATCH 445/590] [BAEL-4720] Java File.separator vs File.pathSeparator (#10330) * [BAEL-4720] Java File.separator vs File.pathSeparator Removed src code and modified junit tests * [BAEL-4720] Java File.separator vs File.pathSeparator Code formatting: Removed extra spaces in the code * [BAEL-4720] Java File.separator vs File.pathSeparator Added more junit tests * [BAEL-4720] Java File.separator vs File.pathSeparator Added new module core-java-io4 and moved the code from core-java-io3 module. Co-authored-by: MeenaGawande --- core-java-modules/core-java-io-4/.gitignore | 2 + core-java-modules/core-java-io-4/README.md | 8 +++ core-java-modules/core-java-io-4/pom.xml | 52 +++++++++++++++ .../FilePathSeparatorUnitTest.java | 63 +++++++++++++++++++ .../fileseparator/FileSeparatorUnitTest.java | 63 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 6 files changed, 189 insertions(+) create mode 100644 core-java-modules/core-java-io-4/.gitignore create mode 100644 core-java-modules/core-java-io-4/README.md create mode 100644 core-java-modules/core-java-io-4/pom.xml create mode 100644 core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java create mode 100644 core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java diff --git a/core-java-modules/core-java-io-4/.gitignore b/core-java-modules/core-java-io-4/.gitignore new file mode 100644 index 0000000000..0c0cd871c5 --- /dev/null +++ b/core-java-modules/core-java-io-4/.gitignore @@ -0,0 +1,2 @@ +test-link* +0.* \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md new file mode 100644 index 0000000000..7cc38bb9fe --- /dev/null +++ b/core-java-modules/core-java-io-4/README.md @@ -0,0 +1,8 @@ +## Core Java IO + +This module contains articles about core Java input and output (IO) + +### Relevant Articles: + +- [Java File Separator vs File Path Separator] +- [[<-- Prev]](/core-java-modules/core-java-io-3) diff --git a/core-java-modules/core-java-io-4/pom.xml b/core-java-modules/core-java-io-4/pom.xml new file mode 100644 index 0000000000..ee31b35ba9 --- /dev/null +++ b/core-java-modules/core-java-io-4/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + core-java-io-4 + 0.1.0-SNAPSHOT + core-java-io-4 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + + commons-io + commons-io + ${commons-io.version} + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + + + + 3.6.1 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java new file mode 100644 index 0000000000..959aae8aff --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.fileseparator; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.util.StringJoiner; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; + +public class FilePathSeparatorUnitTest { + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenCheckPathSeparator_thenResultIsAsExpectedOnWindows() throws IOException { + assertEquals(";", File.pathSeparator); + assertEquals(';', File.pathSeparatorChar); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenCheckPathSeparator_thenResultIsAsExpected() throws IOException { + assertEquals(":", File.pathSeparator); + assertEquals(':', File.pathSeparatorChar); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildPathUsingString_thenResultIsAsExpectedOnWindows() throws IOException { + String[] pathNames = { "path1", "path2", "path3" }; + String path = String.join(File.pathSeparator, pathNames); + assertEquals("path1;path2;path3",path); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildPathUsingString_thenResultIsAsExpected() throws IOException { + String[] pathNames = { "path1", "path2", "path3" }; + String path = String.join(File.pathSeparator, pathNames); + assertEquals("path1:path2:path3", path); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenbuildPathUsingStringJoiner_thenResultIsAsExpectedOnWindows() throws IOException { + assertEquals("path1;path2", buildPathUsingStringJoiner("path1", "path2")); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenbuildPathUsingStringJoiner_thenResultIsAsExpected() throws IOException { + assertEquals("path1:path2", buildPathUsingStringJoiner("path1", "path2")); + } + + private String buildPathUsingStringJoiner(String path1, String path2) { + StringJoiner joiner = new StringJoiner(File.pathSeparator); + joiner.add(path1); + joiner.add(path2); + return joiner.toString(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java new file mode 100644 index 0000000000..f908dcc9bb --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.fileseparator; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; + +public class FileSeparatorUnitTest { + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenCheckFileSeparator_thenCorrectOnWindows() { + assertEquals("\\", File.separator); + assertEquals('\\', File.separatorChar); + + String fileSeparator = FileSystems.getDefault().getSeparator(); + assertEquals("\\",fileSeparator); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenCheckFileSeparator_thenCorrect() { + assertEquals("/", File.separator); + assertEquals('/', File.separatorChar); + + String fileSeparator = FileSystems.getDefault().getSeparator(); + assertEquals("/",fileSeparator); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildFilePathUsingPathsClass_thenCorrectOnWindows() { + Path path = Paths.get("dir1", "dir2"); + assertEquals("dir1\\dir2", path.toString()); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildFilePathUsingPathsClass_thenCorrect() { + Path path = Paths.get("dir1", "dir2"); + assertEquals("dir1/dir2", path.toString()); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpectedOnWindows() { + File file = new File("file1", "file2"); + assertEquals("file1\\file2", file.toString()); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpected() { + File file = new File("file1", "file2"); + assertEquals("file1/file2", file.toString()); + } +} \ No newline at end of file diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 0a9e818156..711d1e03b9 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -67,6 +67,7 @@ core-java-io core-java-io-2 core-java-io-3 + core-java-io-4 core-java-io-apis core-java-io-conversions core-java-io-conversions-2 From e136bfb7dfea608c1dac957170c6bad5f77924d1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 7 Jan 2021 11:06:50 +0530 Subject: [PATCH 446/590] JAVA-4214: Fix issue with geodb repo --- persistence-modules/hibernate-annotations/pom.xml | 14 -------------- persistence-modules/hibernate-queries/pom.xml | 14 -------------- persistence-modules/hibernate5/pom.xml | 14 -------------- 3 files changed, 42 deletions(-) diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 230de2e17e..d3b786d6c8 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -44,21 +44,8 @@ hibernate-spatial ${hibernate-core.version} - - org.opengeo - geodb - ${geodb.version} - - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 5.4.7.Final 1.4.200 @@ -66,7 +53,6 @@ 2.1.7.RELEASE 5.4.7.Final 1.4.200 - 0.9 diff --git a/persistence-modules/hibernate-queries/pom.xml b/persistence-modules/hibernate-queries/pom.xml index 06f7f42088..4374c833c2 100644 --- a/persistence-modules/hibernate-queries/pom.xml +++ b/persistence-modules/hibernate-queries/pom.xml @@ -35,11 +35,6 @@ hibernate-spatial ${hibernate.version} - - org.opengeo - geodb - ${geodb.version} - mysql mysql-connector-java @@ -62,19 +57,10 @@ - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 6.0.6 2.2.3 3.8.0 - 0.9 1.21 diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index 7f04abc09f..3feffc98fd 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -35,11 +35,6 @@ hibernate-spatial ${hibernate.version} - - org.opengeo - geodb - ${geodb.version} - mysql mysql-connector-java @@ -68,21 +63,12 @@ - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 5.4.12.Final 6.0.6 2.2.3 3.8.0 1.21 - 0.9 From 28d61c77efda4b80321c233a4d0bcb2b352fe585 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 7 Jan 2021 16:30:52 +0200 Subject: [PATCH 447/590] move main class to graphql package --- spring-boot-modules/spring-boot-libraries/pom.xml | 2 +- .../java/com/baeldung/{demo => graphql}/DemoApplication.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/{demo => graphql}/DemoApplication.java (96%) diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index cec035cf93..c96a881573 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -239,7 +239,7 @@ - com.baeldung.intro.App + com.baeldung.graphql.DemoApplication 8.5.11 2.4.1.Final 1.9.0 diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java similarity index 96% rename from spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java index e30ee6104d..1fd93af3b7 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.demo; +package com.baeldung.graphql; import com.baeldung.graphql.GraphqlConfiguration; import org.springframework.boot.SpringApplication; From 75aa478d80aa0f249351ac0dec0731773059604a Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 20:26:18 +0100 Subject: [PATCH 448/590] JAVA-3585: Upgrade commons-io in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 09cba54b87..e4a2632bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -1375,7 +1375,7 @@ 1.19 1.6.0 2.21.0 - 2.5 + 2.8.0 2.6 3.11 1.4 From ba5343cab27965460f29ec889fa1a03a30d2cb78 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 20:42:57 +0100 Subject: [PATCH 449/590] JAVA-3585: Use common commons-io.version property in all child modules --- aws-lambda/lambda/pom.xml | 1 - core-java-modules/core-java-9/pom.xml | 2 +- jhipster/jhipster-microservice/car-app/pom.xml | 1 - jhipster/jhipster-microservice/dealer-app/pom.xml | 1 - jhipster/jhipster-microservice/gateway-app/pom.xml | 1 - jhipster/jhipster-monolithic/pom.xml | 1 - libraries-6/pom.xml | 3 +-- libraries-data/pom.xml | 3 +-- parent-java/pom.xml | 3 +-- persistence-modules/hibernate-mapping/pom.xml | 1 - spring-boot-modules/pom.xml | 1 - spring-boot-modules/spring-boot-mvc-3/pom.xml | 4 ---- spring-core/pom.xml | 3 +-- spring-di/pom.xml | 3 +-- spring-web-modules/spring-mvc-java/pom.xml | 1 - xml/pom.xml | 1 - 16 files changed, 6 insertions(+), 24 deletions(-) diff --git a/aws-lambda/lambda/pom.xml b/aws-lambda/lambda/pom.xml index 2d903aabc5..1f446e04c0 100644 --- a/aws-lambda/lambda/pom.xml +++ b/aws-lambda/lambda/pom.xml @@ -89,7 +89,6 @@ 1.1.1 - 2.5 1.3.0 1.2.0 2.8.2 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index 05dc8ba5eb..001faf88cb 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -52,7 +52,7 @@ commons-io commons-io - 2.7 + ${commons-io.version} diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml index 603d53299c..477192438f 100644 --- a/jhipster/jhipster-microservice/car-app/pom.xml +++ b/jhipster/jhipster-microservice/car-app/pom.xml @@ -21,7 +21,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.2 5.2.8.Final diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml index 0e492d3d13..59df7d3b69 100644 --- a/jhipster/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster/jhipster-microservice/dealer-app/pom.xml @@ -20,7 +20,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.2 5.2.8.Final diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml index c5e7364f57..a50c2bbdd1 100644 --- a/jhipster/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster/jhipster-microservice/gateway-app/pom.xml @@ -22,7 +22,6 @@ 2.0.0 3.6.0 1.10 - 2.5 0.4.13 1.3 1.2 diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index 103f48424f..97f2b85b2f 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -887,7 +887,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.3 2.2.1 diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index 0f129c27c9..caaebbb922 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -94,7 +94,7 @@ commons-io commons-io - ${commonsio.version} + ${commons-io.version} test @@ -157,7 +157,6 @@ 1.15 3.6 3.6.2 - 2.6 RELEASE 3.0 1.8.1 diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 95d771ce4e..5adb490e96 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -80,7 +80,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} provided @@ -165,7 +165,6 @@ 2.3 1.2 - 2.1 3.0.1 1.2.2 1.0.0 diff --git a/parent-java/pom.xml b/parent-java/pom.xml index d251adcdd3..9170f45bbe 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -27,7 +27,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} org.openjdk.jmh @@ -43,7 +43,6 @@ 29.0-jre - 2.6 1.19 2.3.7 2.2 diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 155eefa526..ebc854a621 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -71,7 +71,6 @@ 3.0.1-b11 1.0.3 1.3 - 2.6 diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index c562d522e2..ee088c357a 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -116,6 +116,5 @@ 5.6.2 - 2.6 diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml index 1290b0432f..5a5d4c3cd8 100644 --- a/spring-boot-modules/spring-boot-mvc-3/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -37,8 +37,4 @@ - - 2.7 - - diff --git a/spring-core/pom.xml b/spring-core/pom.xml index eb25bcd517..7d83fc198c 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -65,7 +65,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} @@ -86,7 +86,6 @@ 1.4.4.RELEASE 1 20.0 - 2.5 1.5.2.RELEASE 1.10.19 3.12.2 diff --git a/spring-di/pom.xml b/spring-di/pom.xml index 48cdf60673..df0b685ae2 100644 --- a/spring-di/pom.xml +++ b/spring-di/pom.xml @@ -83,7 +83,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} org.aspectj @@ -159,7 +159,6 @@ 1.4.4.RELEASE 1 20.0 - 2.5 1.5.2.RELEASE 1.10.19 3.12.2 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index ec302eed57..474bbb2a06 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -235,7 +235,6 @@ 19.0 1.3.2 - 2.5 1.4 2.2.0 diff --git a/xml/pom.xml b/xml/pom.xml index cbad5b37f0..837f918b46 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -364,7 +364,6 @@ 1.2.0 2.0.6 1.6.2 - 2.5 4.1 1.2.4.5 2.3.1 From d25080b689972a08a53d82891af20e98cec45d5e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 23:14:19 +0100 Subject: [PATCH 450/590] JAVA-4217: Update batch dependencies --- spring-batch-2/pom.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-batch-2/pom.xml b/spring-batch-2/pom.xml index 54df6d43e8..183ad610f3 100644 --- a/spring-batch-2/pom.xml +++ b/spring-batch-2/pom.xml @@ -20,7 +20,6 @@ org.springframework.boot spring-boot-starter-batch - 2.3.6.RELEASE org.hsqldb @@ -31,7 +30,6 @@ org.springframework.boot spring-boot-starter-test - ${spring.boot.batch.version} test @@ -43,14 +41,13 @@ org.springframework.batch spring-batch-test - ${spring.batch.test.version} + ${spring.batch.version} test - 2.3.6.RELEASE - 4.2.4.RELEASE + 4.3.0 2.5.1 From 51189b8d4058b637fd9ce1091fe4ea8b120e6158 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 8 Jan 2021 18:22:46 +0530 Subject: [PATCH 451/590] JAVA-4216: Fix issue in jnosql-artemis project --- persistence-modules/jnosql/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/jnosql/pom.xml b/persistence-modules/jnosql/pom.xml index fb7ac72b05..81c62ee562 100644 --- a/persistence-modules/jnosql/pom.xml +++ b/persistence-modules/jnosql/pom.xml @@ -21,7 +21,7 @@ - 0.0.5 + 0.0.6 From 989216338f7b2ee7b00a5672dd60cfa11a4b64cd Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 8 Jan 2021 19:56:04 +0100 Subject: [PATCH 452/590] JAVA-3588: Upgrade commons-fileupload in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4a2632bf4..2d1850bb79 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ 2.3.1 1.2 2.11.1 - 1.3 + 1.4 1.2.0 5.2.0 0.3.1 From d450e4a2f81748ada5b89fd8cc5a8a976d35d095 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 8 Jan 2021 20:01:27 +0100 Subject: [PATCH 453/590] JAVA-3588: Use common commons-fileupload.version property in all child modules --- javax-servlets/pom.xml | 1 - spring-security-modules/spring-security-web-rest/pom.xml | 2 -- spring-web-modules/spring-mvc-basics-2/pom.xml | 1 - spring-web-modules/spring-mvc-forms-jsp/pom.xml | 3 +-- spring-web-modules/spring-mvc-java/pom.xml | 2 -- spring-web-modules/spring-rest-simple/pom.xml | 1 - 6 files changed, 1 insertion(+), 9 deletions(-) diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index 5fc9fef24a..700b823a6e 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -59,7 +59,6 @@ 4.5.3 2.8.2 3.9.1 - 1.3.3 4.0.1 diff --git a/spring-security-modules/spring-security-web-rest/pom.xml b/spring-security-modules/spring-security-web-rest/pom.xml index d2468152da..2330243aa6 100644 --- a/spring-security-modules/spring-security-web-rest/pom.xml +++ b/spring-security-modules/spring-security-web-rest/pom.xml @@ -168,7 +168,6 @@ ${springfox-swagger.version} - commons-fileupload commons-fileupload @@ -271,7 +270,6 @@ 26.0-jre - 1.3.2 2.9.0 diff --git a/spring-web-modules/spring-mvc-basics-2/pom.xml b/spring-web-modules/spring-mvc-basics-2/pom.xml index e16b54b2c8..0b4515994b 100644 --- a/spring-web-modules/spring-mvc-basics-2/pom.xml +++ b/spring-web-modules/spring-mvc-basics-2/pom.xml @@ -168,7 +168,6 @@ 4.0.0 6.0.10.Final enter-location-of-server - 1.3.2 3.0.11.RELEASE 2.4.12 2.3.27-incubating diff --git a/spring-web-modules/spring-mvc-forms-jsp/pom.xml b/spring-web-modules/spring-mvc-forms-jsp/pom.xml index aba16236da..0ca23bd6cb 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/pom.xml +++ b/spring-web-modules/spring-mvc-forms-jsp/pom.xml @@ -54,7 +54,7 @@ commons-fileupload commons-fileupload - ${fileupload.version} + ${commons-fileupload.version} com.fasterxml.jackson.core @@ -98,7 +98,6 @@ 6.0.10.Final - 1.3.3 5.2.5.Final 6.0.6 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 474bbb2a06..1324511215 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -234,8 +234,6 @@ 19.0 - 1.3.2 - 1.4 2.2.0 diff --git a/spring-web-modules/spring-rest-simple/pom.xml b/spring-web-modules/spring-rest-simple/pom.xml index 37a0b99de2..b9d5100fbf 100644 --- a/spring-web-modules/spring-rest-simple/pom.xml +++ b/spring-web-modules/spring-rest-simple/pom.xml @@ -314,7 +314,6 @@ - 1.3.3 4.0.0 1.4 3.1.0 From 195f4aab7bf8dd5147d1d538cad41504056cf70d Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 8 Jan 2021 18:14:01 -0300 Subject: [PATCH 454/590] cleaned up boot version override in spring-boot-properties, since the parent-boot-2 module has been updated --- spring-boot-modules/spring-boot-properties/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index 0260a4a72e..40668f47fd 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -141,7 +141,6 @@ @ com.baeldung.yaml.MyApplication - 2.4.0 From d3c73637c287229ae619d020140fe433dc33f34a Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Sat, 9 Jan 2021 07:54:57 +1000 Subject: [PATCH 455/590] BAEL-4614 JVM property java.security.egd --- .../baeldung/egd/JavaSecurityEgdTester.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java new file mode 100644 index 0000000000..347d3b4cba --- /dev/null +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java @@ -0,0 +1,23 @@ +package com.baeldung.egd; + +import java.security.SecureRandom; + +/** + * JavaSecurityEgdTester - run this with JVM parameter java.security.egd, e.g.: + * java -Djava.security.egd=file:/dev/urandom -cp . com.baeldung.egd.JavaSecurityEgdTester + */ +public class JavaSecurityEgdTester { + public static final double NANOSECS = 1000000000.0; + public static final String JAVA_SECURITY_EGD = "java.security.egd"; + + public static void main(String[] args) { + SecureRandom secureRandom = new SecureRandom(); + long start = System.nanoTime(); + byte[] randomBytes = new byte[256]; + secureRandom.nextBytes(randomBytes); + double duration = (System.nanoTime() - start) / NANOSECS; + + String message = String.format("java.security.egd=%s took %.3f seconds and used the %s algorithm", System.getProperty(JAVA_SECURITY_EGD), duration, secureRandom.getAlgorithm()); + System.out.println(message); + } +} From dfe902f0a68ccb9071165130d06319c01cf3eb02 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 12:59:21 +0530 Subject: [PATCH 456/590] JAVA-3542: Moved spring-jooq inside persistence-modules --- {spring-jooq => persistence-modules/spring-jooq}/.gitignore | 0 {spring-jooq => persistence-modules/spring-jooq}/README.md | 0 {spring-jooq => persistence-modules/spring-jooq}/pom.xml | 2 +- .../spring-jooq}/src/main/resources/application.properties | 0 .../spring-jooq}/src/main/resources/intro_config.properties | 0 .../spring-jooq}/src/main/resources/intro_schema.sql | 0 .../spring-jooq}/src/main/resources/logback.xml | 0 .../com/baeldung/jooq/introduction/ExceptionTranslator.java | 0 .../jooq/introduction/PersistenceContextIntegrationTest.java | 0 .../com/baeldung/jooq/introduction/QueryIntegrationTest.java | 0 .../src/test/java/com/baeldung/jooq/springboot/Application.java | 0 .../java/com/baeldung/jooq/springboot/InitialConfiguration.java | 0 .../com/baeldung/jooq/springboot/SpringBootIntegrationTest.java | 0 .../spring-jooq}/src/test/resources/application.properties | 0 14 files changed, 1 insertion(+), 1 deletion(-) rename {spring-jooq => persistence-modules/spring-jooq}/.gitignore (100%) rename {spring-jooq => persistence-modules/spring-jooq}/README.md (100%) rename {spring-jooq => persistence-modules/spring-jooq}/pom.xml (99%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/application.properties (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/intro_config.properties (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/intro_schema.sql (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/logback.xml (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/Application.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/resources/application.properties (100%) diff --git a/spring-jooq/.gitignore b/persistence-modules/spring-jooq/.gitignore similarity index 100% rename from spring-jooq/.gitignore rename to persistence-modules/spring-jooq/.gitignore diff --git a/spring-jooq/README.md b/persistence-modules/spring-jooq/README.md similarity index 100% rename from spring-jooq/README.md rename to persistence-modules/spring-jooq/README.md diff --git a/spring-jooq/pom.xml b/persistence-modules/spring-jooq/pom.xml similarity index 99% rename from spring-jooq/pom.xml rename to persistence-modules/spring-jooq/pom.xml index 550d49b5b2..6b3d565175 100644 --- a/spring-jooq/pom.xml +++ b/persistence-modules/spring-jooq/pom.xml @@ -9,7 +9,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-jooq/src/main/resources/application.properties b/persistence-modules/spring-jooq/src/main/resources/application.properties similarity index 100% rename from spring-jooq/src/main/resources/application.properties rename to persistence-modules/spring-jooq/src/main/resources/application.properties diff --git a/spring-jooq/src/main/resources/intro_config.properties b/persistence-modules/spring-jooq/src/main/resources/intro_config.properties similarity index 100% rename from spring-jooq/src/main/resources/intro_config.properties rename to persistence-modules/spring-jooq/src/main/resources/intro_config.properties diff --git a/spring-jooq/src/main/resources/intro_schema.sql b/persistence-modules/spring-jooq/src/main/resources/intro_schema.sql similarity index 100% rename from spring-jooq/src/main/resources/intro_schema.sql rename to persistence-modules/spring-jooq/src/main/resources/intro_schema.sql diff --git a/spring-jooq/src/main/resources/logback.xml b/persistence-modules/spring-jooq/src/main/resources/logback.xml similarity index 100% rename from spring-jooq/src/main/resources/logback.xml rename to persistence-modules/spring-jooq/src/main/resources/logback.xml diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java diff --git a/spring-jooq/src/test/resources/application.properties b/persistence-modules/spring-jooq/src/test/resources/application.properties similarity index 100% rename from spring-jooq/src/test/resources/application.properties rename to persistence-modules/spring-jooq/src/test/resources/application.properties From 3dbc22182ff3220becfb321b351bea10ea3556c7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 13:00:07 +0530 Subject: [PATCH 457/590] JAVA-3542: Added module to new parent's pom --- persistence-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index c7905a178d..8789a8473b 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -86,6 +86,7 @@ spring-jpa spring-jpa-2 spring-jdbc + spring-jooq spring-persistence-simple From 1f70c884377d18195ae838aa8d8579ffefa4ac80 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 13:01:08 +0530 Subject: [PATCH 458/590] JAVA-3542: Removed module from main pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index e4a2632bf4..e923c3711c 100644 --- a/pom.xml +++ b/pom.xml @@ -650,7 +650,6 @@ spring-jersey spring-jinq spring-jms - spring-jooq spring-kafka spring-katharsis @@ -1101,7 +1100,6 @@ spring-jersey spring-jinq spring-jms - spring-jooq spring-kafka spring-katharsis From df31e606c3d8486dfb99a0be50491e74097b2810 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 9 Jan 2021 15:55:24 +0000 Subject: [PATCH 459/590] BAEL-4748 implement UserConsumerService with webClient and write UnitTests --- .../webclient/json/UserConsumerService.java | 16 ++++ .../json/UserConsumerServiceImpl.java | 90 +++++++++++++++++++ .../webclient/json/model/Address.java | 29 ++++++ .../baeldung/webclient/json/model/User.java | 30 +++++++ .../json/UserConsumerServiceImplUnitTest.java | 74 +++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java new file mode 100644 index 0000000000..9afc207ff2 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java @@ -0,0 +1,16 @@ +package com.baeldung.webclient.json; + +import java.util.List; + +public interface UserConsumerService { + + List processUserDataFromObjectArray(); + + List processUserDataFromUserArray(); + + List processUserDataFromUserList(); + + List processNestedUserDataFromUserArray(); + + List processNestedUserDataFromUserList(); +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java new file mode 100644 index 0000000000..30cd4a5617 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java @@ -0,0 +1,90 @@ +package com.baeldung.webclient.json; + +import com.baeldung.webclient.json.model.Address; +import com.baeldung.webclient.json.model.User; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class UserConsumerServiceImpl implements UserConsumerService { + + private final WebClient webClient; + private static final ObjectMapper mapper = new ObjectMapper(); + + public UserConsumerServiceImpl(WebClient webClient) { + this.webClient = webClient; + } + @Override + public List processUserDataFromObjectArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Object[].class).log(); + Object[] objects = response.block(); + return Arrays.stream(objects) + .map(object -> mapper.convertValue(object, User.class)) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserArray() { + Mono response = + webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(User[].class).log(); + + User[] userArray = response.block(); + return Arrays.stream(userArray) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + List userList = response.block(); + + return userList.stream() + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(User[].class).log(); + User[] userArray = response.block(); + + return Arrays.stream(userArray) + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + + List userList = response.block(); + return userList.stream() + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java new file mode 100644 index 0000000000..cc4323b72b --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java @@ -0,0 +1,29 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Address { + private final String addressLine1; + private final String addressLine2; + private final String town; + private final String postCode; + + @JsonCreator + public Address( + @JsonProperty("addressLine1") String addressLine1, + @JsonProperty("addressLine2") String addressLine2, + @JsonProperty("town") String town, + @JsonProperty("postCode") String postCode) { + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.town = town; + this.postCode = postCode; + } + public String getPostCode() { + return postCode; + } +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java new file mode 100644 index 0000000000..6ed359f9db --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java @@ -0,0 +1,30 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User { + private final int id; + private final String name; + private final List
    addressList; + + @JsonCreator + public User( + @JsonProperty("id") int id, + @JsonProperty("name") String name, + @JsonProperty("addressList") List
    addressList) { + this.id = id; + this.name = name; + this.addressList = addressList; + } + + public String getName() { + return name; + } + + public List
    getAddressList() { return addressList; } +} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java new file mode 100644 index 0000000000..151554efde --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.webclient.json; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +public class UserConsumerServiceImplUnitTest { + + private static String USER_JSON = "[{\"id\":1,\"name\":\"user1\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user1_address1_postCode\"}," + + "{\"addressLine1\":\"address2_addressLine1\",\"addressLine2\":\"address2_addressLine2\",\"town\":\"address2_town\",\"postCode\":\"user1_address2_postCode\"}]}," + + "{\"id\":2,\"name\":\"user2\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user2_address1_postCode\"}]}]"; + + private static String BASE_URL = "http://localhost:8080"; + + WebClient webClientMock = WebClient.builder() + .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) + .header("content-type", "application/json") + .body(USER_JSON) + .build())) + .build(); + + private final UserConsumerService tested = new UserConsumerServiceImpl(webClientMock); + + @Test + void when_processUserDataFromObjectArray_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromObjectArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processUserDataFromUserArray_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromUserArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processUserDataFromUserList_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromUserList(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processNestedUserDataFromUserArray_then_OK() { + List expected = Arrays.asList( + "user1_address1_postCode", + "user1_address2_postCode", + "user2_address1_postCode"); + + List actual = tested.processNestedUserDataFromUserArray(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); + } + + @Test + void when_processNestedUserDataFromUserList_then_OK() { + List expected = Arrays.asList( + "user1_address1_postCode", + "user1_address2_postCode", + "user2_address1_postCode"); + + List actual = tested.processNestedUserDataFromUserList(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); + } +} \ No newline at end of file From adfede63ba31352ca99e0631330a5e9856646096 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Sat, 9 Jan 2021 21:18:07 +0200 Subject: [PATCH 460/590] BAEL-4472 - old file removed --- ...inarySemaphoreVsReentrantLockUnitTest.java | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java deleted file mode 100644 index f456e82f39..0000000000 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.binarysemaphorereentrantlock; - -import static org.junit.Assert.assertEquals; -import java.util.concurrent.Semaphore; -import java.util.concurrent.locks.ReentrantLock; - -import org.junit.Test; - -public class BinarySemaphoreVsReentrantLockUnitTest { - - @Test - public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { - Semaphore binarySemaphore = new Semaphore(1); - try { - binarySemaphore.acquire(); - assertEquals(0, binarySemaphore.availablePermits()); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - binarySemaphore.release(); - assertEquals(1, binarySemaphore.availablePermits()); - } - } - - @Test - public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { - ReentrantLock reentrantLock = new ReentrantLock(); - try { - reentrantLock.lock(); - assertEquals(1, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - } finally { - reentrantLock.unlock(); - assertEquals(0, reentrantLock.getHoldCount()); - assertEquals(false, reentrantLock.isLocked()); - } - } - - @Test - public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { - ReentrantLock reentrantLock = new ReentrantLock(); - try { - reentrantLock.lock(); - reentrantLock.lock(); - assertEquals(2, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - } finally { - reentrantLock.unlock(); - assertEquals(1, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - - reentrantLock.unlock(); - assertEquals(0, reentrantLock.getHoldCount()); - assertEquals(false, reentrantLock.isLocked()); - } - } - -} From 5e26ff97d9e41166fdd59c6192278838e9785d80 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 9 Jan 2021 23:09:00 -0300 Subject: [PATCH 461/590] removed starter-test vintage engine exclusion, not needed since Boot 2.4.0 --- spring-boot-modules/spring-boot-properties-3/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml index 44e2ef52ac..809fd6e2d4 100644 --- a/spring-boot-modules/spring-boot-properties-3/pom.xml +++ b/spring-boot-modules/spring-boot-properties-3/pom.xml @@ -26,12 +26,6 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - org.springframework.boot From c0955b04f7c91c22d669bec3a212f58959f18def Mon Sep 17 00:00:00 2001 From: wolkenschieber Date: Sun, 10 Jan 2021 14:03:17 +0100 Subject: [PATCH 462/590] Update packages to match declaration --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-angular/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-ctx-fluent/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-jasypt/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-logging-log4j2/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-vue/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-angular/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-angular/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-jasypt/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-jasypt/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-logging-log4j2/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-vue/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-vue/src/test/java/com/baeldung/SpringContextTest.java From 4af05b2230e35453f39a6708b9f2bef5a17580a6 Mon Sep 17 00:00:00 2001 From: wolkenschieber Date: Sun, 10 Jan 2021 15:04:09 +0100 Subject: [PATCH 463/590] Update packages to match declaration --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/SpringContextTest.java From 7347c8fe16d7d26de2f01e24c9869450209341ba Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 9 Jan 2021 23:10:12 -0300 Subject: [PATCH 464/590] added example for multidocument properties files --- .../src/main/resources/application.properties | 6 ++++- ...documentPropertiesFileIntegrationTest.java | 22 +++++++++++++++++ ...documentPropertiesFileIntegrationTest.java | 24 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index eace1f0e46..bf89182d8a 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -8,4 +8,8 @@ spring.datasource.url=jdbc:h2:dev spring.datasource.username=SA spring.datasource.password=password app.name=MyApp -app.description=${app.name} is a Spring Boot application \ No newline at end of file +app.description=${app.name} is a Spring Boot application +bael.property=defaultValue +#--- +spring.config.activate.on-profile=prod +bael.property=prodValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..61c76aef84 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,22 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +public class DefaultMultidocumentPropertiesFileIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Test + public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("defaultValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..39bc2da3ba --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,24 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("prod") +public class ProdMultidocumentPropertiesFileIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("prodValue"); + } +} From 0de32373657be04f4d28ed50bc558a263fd0cb00 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 11 Jan 2021 14:23:27 -0300 Subject: [PATCH 465/590] improved and updated spring-boot-yaml-vs-properties article code --- ...ation-multidocument-integration.properties | 4 +++ .../src/main/resources/application.properties | 12 +++++++- .../src/main/resources/application.yml | 20 ++++++------- ...ultMultidocumentFilesIntegrationTest.java} | 6 +++- .../DevMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ ...tionMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ ...rodMultidocumentFilesIntegrationTest.java} | 8 ++++-- ...gingMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ 8 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties rename spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/{DefaultMultidocumentPropertiesFileIntegrationTest.java => DefaultMultidocumentFilesIntegrationTest.java} (77%) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java rename spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/{ProdMultidocumentPropertiesFileIntegrationTest.java => ProdMultidocumentFilesIntegrationTest.java} (76%) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties new file mode 100644 index 0000000000..c4eeba2589 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties @@ -0,0 +1,4 @@ +spring.datasource.password: 'password' +spring.datasource.url: jdbc:mysql://localhost:3306/db_integration +spring.datasource.username: user +bael.property=integrationValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index bf89182d8a..c2bb5deb45 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -9,7 +9,17 @@ spring.datasource.username=SA spring.datasource.password=password app.name=MyApp app.description=${app.name} is a Spring Boot application +logging.file.name=myapplication.log bael.property=defaultValue #--- -spring.config.activate.on-profile=prod +spring.config.activate.on-profile=multidocument-dev +spring.datasource.password=password +spring.datasource.url=jdbc:h2:dev +spring.datasource.username=SA +bael.property=devValue +#--- +spring.config.activate.on-profile=multidocument-prod +spring.datasource.password=password +spring.datasource.url=jdbc:h2:prod +spring.datasource.username=prodUser bael.property=prodValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index 00baeade9c..33aabb2459 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -1,17 +1,17 @@ -logging: - file: - name: myapplication.log -spring: - datasource: - password: 'password' - url: jdbc:h2:dev - username: SA +bael: + root-level-property: defaultRootLevelValue --- spring: + config: + activate: + on-profile: multidocument-staging datasource: password: 'password' - url: jdbc:mysql://localhost:3306/db_production - username: user + url: jdbc:h2:staging + username: SA +bael: + property: stagingValue +--- application: servers: - ip: '127.0.0.1' diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java similarity index 77% rename from spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java index 61c76aef84..af1f7f705f 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java @@ -10,13 +10,17 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import com.baeldung.boot.properties.DemoApplication; @SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) -public class DefaultMultidocumentPropertiesFileIntegrationTest { +public class DefaultMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; @Test public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("defaultValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..54188595c0 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-dev") +public class DevMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("devValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..f7968f51ad --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-integration") +public class IntegrationMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("integrationValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java similarity index 76% rename from spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java index 39bc2da3ba..9270995da0 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java @@ -11,14 +11,18 @@ import org.springframework.test.context.ActiveProfiles; import com.baeldung.boot.properties.DemoApplication; @SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) -@ActiveProfiles("prod") -public class ProdMultidocumentPropertiesFileIntegrationTest { +@ActiveProfiles("multidocument-prod") +public class ProdMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; @Test public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("prodValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..8040c93ee0 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-staging") +public class StagingMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("stagingValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} From 93e15677438aeebf523d40bdbb003e237261c764 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:12:12 +0530 Subject: [PATCH 466/590] JAVA-4013: Moved 1 article to spring-boot-data-2 --- spring-boot-modules/spring-boot-data-2/pom.xml | 9 +++++++++ .../hikari/ApplicationWithHikariConnectionPool.java | 0 .../java/com/baeldung/hikari/HikariIntegrationTest.java | 0 3 files changed, 9 insertions(+) rename {spring-5 => spring-boot-modules/spring-boot-data-2}/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java (100%) rename {spring-5 => spring-boot-modules/spring-boot-data-2}/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java (100%) diff --git a/spring-boot-modules/spring-boot-data-2/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml index 199a204500..fb0d5f2053 100644 --- a/spring-boot-modules/spring-boot-data-2/pom.xml +++ b/spring-boot-modules/spring-boot-data-2/pom.xml @@ -16,6 +16,15 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java similarity index 100% rename from spring-5/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java diff --git a/spring-5/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java similarity index 100% rename from spring-5/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java From 6052fd6bc85e12d1ddfe9d2b9e7054d307074858 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:14:11 +0530 Subject: [PATCH 467/590] JAVA-4013: Moved 2 articles to spring-testing-2 --- spring-5/pom.xml | 13 +------------ testing-modules/spring-testing-2/pom.xml | 17 +++++++++++++++++ .../Spring5JUnit4ConcurrentIntegrationTest.java | 2 +- .../com/baeldung/enabledif}/EnabledOnJava8.java | 2 +- ...Spring5EnabledAnnotationIntegrationTest.java | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) rename {spring-5/src/test/java/com/baeldung => testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent}/Spring5JUnit4ConcurrentIntegrationTest.java (98%) rename {spring-5/src/test/java/com/baeldung/jupiter => testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif}/EnabledOnJava8.java (93%) rename {spring-5/src/test/java/com/baeldung/jupiter => testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif}/Spring5EnabledAnnotationIntegrationTest.java (97%) diff --git a/spring-5/pom.xml b/spring-5/pom.xml index eadfb5e512..e368bcacba 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -133,18 +133,7 @@ - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - methods - true - - + diff --git a/testing-modules/spring-testing-2/pom.xml b/testing-modules/spring-testing-2/pom.xml index 807b84c676..4686a20202 100644 --- a/testing-modules/spring-testing-2/pom.xml +++ b/testing-modules/spring-testing-2/pom.xml @@ -54,8 +54,25 @@ + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + methods + true + + + + 1.12.2 + 2.21.0 \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java similarity index 98% rename from spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java index 7e494465b2..8a0947ba44 100644 --- a/spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.concurrent; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java similarity index 93% rename from spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java index c6d3b7ff10..01bdc176e0 100644 --- a/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java @@ -1,4 +1,4 @@ -package com.baeldung.jupiter; +package com.baeldung.enabledif; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java similarity index 97% rename from spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java index 35363e0ea3..b6ccb2204b 100644 --- a/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.jupiter; +package com.baeldung.enabledif; import static org.junit.jupiter.api.Assertions.assertTrue; From 013902b25364fe5044361f2b536b8af5c2b6557a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:14:50 +0530 Subject: [PATCH 468/590] JAVA-4013: README changes --- spring-5/README.md | 3 --- spring-boot-modules/spring-boot-data-2/README.md | 1 + testing-modules/spring-testing-2/README.md | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-5/README.md b/spring-5/README.md index cef0fedb4f..cce18bedf8 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -4,13 +4,10 @@ This module contains articles about Spring 5 ### Relevant Articles -- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) - [Spring 5 Functional Bean Registration](https://www.baeldung.com/spring-5-functional-beans) - [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](https://www.baeldung.com/spring-5-junit-config) -- [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) - [Introduction to Spring REST Docs](https://www.baeldung.com/spring-rest-docs) - [Spring ResponseStatusException](https://www.baeldung.com/spring-response-status-exception) - [Spring Assert Statements](https://www.baeldung.com/spring-assert) -- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) - [Difference between \ vs \](https://www.baeldung.com/spring-contextannotation-contextcomponentscan) - [Finding the Spring Version](https://www.baeldung.com/spring-find-version) diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md index d5020ce354..c21ce02a2e 100644 --- a/spring-boot-modules/spring-boot-data-2/README.md +++ b/spring-boot-modules/spring-boot-data-2/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper) +- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) diff --git a/testing-modules/spring-testing-2/README.md b/testing-modules/spring-testing-2/README.md index 702a02ff27..16b47adeac 100644 --- a/testing-modules/spring-testing-2/README.md +++ b/testing-modules/spring-testing-2/README.md @@ -1,3 +1,5 @@ ## Relevant Articles: - [Guide to @DynamicPropertySource in Spring](https://www.baeldung.com/spring-dynamicpropertysource) +- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) +- [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) From 1a0655a189734d2d9b50611acf2987d69a2e02f7 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 13 Jan 2021 10:26:38 -0300 Subject: [PATCH 469/590] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests These are potential issues, since the dependency is included in the root pom --- testing-modules/spring-testing/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index 9fe0fd8895..9e0c986bb2 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -39,6 +39,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + org.springframework spring-core From 1ed7c56596a3f29f55b79b85c1a88e7279a2f2bc Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 13 Jan 2021 11:28:41 -0300 Subject: [PATCH 470/590] changes related to spring-boot-modules/spring-boot-testing boot 2.4.0 upgrade --- spring-boot-modules/spring-boot-testing/pom.xml | 11 +++++++++++ .../BindingYMLPropertiesUnitTest.java | 4 ++-- .../execution/LoadSpringContextIntegrationTest.java | 4 ++-- .../src/test/resources/application.yml | 8 ++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index 5bf626f165..50a1ace2fa 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -51,6 +51,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java index 5543f5e9e8..99c128997e 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java @@ -7,13 +7,13 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ServerConfig.class) @ActiveProfiles("test") public class BindingYMLPropertiesUnitTest { diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java index 6698094550..483c67b7a2 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -19,7 +19,7 @@ import static org.mockito.Mockito.verify; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class }, - initializers = ConfigFileApplicationContextInitializer.class) + initializers = ConfigDataApplicationContextInitializer.class) public class LoadSpringContextIntegrationTest { @SpyBean TaskService taskService; diff --git a/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml b/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml index 1b46b0f1ff..056b5baffc 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml +++ b/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml @@ -1,5 +1,7 @@ spring: - profiles: test + config: + activate: + on-profile: test server: address: ip: 192.168.0.4 @@ -7,7 +9,9 @@ server: imgs: /etc/test/imgs --- spring: - profiles: dev + config: + activate: + on-profile: dev server: address: ip: 192.168.0.5 From 3af803eb73f0ea9b3e643c66f6cba20fc8d52dd2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:11:46 +0800 Subject: [PATCH 471/590] Update README.md --- core-java-modules/core-java-io-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md index 7cc38bb9fe..c837e2bffc 100644 --- a/core-java-modules/core-java-io-4/README.md +++ b/core-java-modules/core-java-io-4/README.md @@ -4,5 +4,5 @@ This module contains articles about core Java input and output (IO) ### Relevant Articles: -- [Java File Separator vs File Path Separator] +- [Java File Separator vs File Path Separator](https://www.baeldung.com/java-file-vs-file-path-separator) - [[<-- Prev]](/core-java-modules/core-java-io-3) From 974f0f34273b65f08a5f64fd08ebf68133d54383 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:13:45 +0800 Subject: [PATCH 472/590] Update README.md --- jackson-modules/jackson-conversions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson-modules/jackson-conversions-2/README.md b/jackson-modules/jackson-conversions-2/README.md index 71c5578525..9986fe75b5 100644 --- a/jackson-modules/jackson-conversions-2/README.md +++ b/jackson-modules/jackson-conversions-2/README.md @@ -9,4 +9,5 @@ This module contains articles about Jackson conversions. - [Converting JSON to CSV in Java](https://www.baeldung.com/java-converting-json-to-csv) - [How to Process YAML with Jackson](https://www.baeldung.com/jackson-yaml) - [Jackson Streaming API](https://www.baeldung.com/jackson-streaming-api) +- [Jackson: java.util.LinkedHashMap cannot be cast to X](https://www.baeldung.com/jackson-linkedhashmap-cannot-be-cast) - More articles: [[<-- prev]](../jackson-conversions) From 5d14cdd74619575db8617f54ec0dc682ea2961a4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:15:43 +0800 Subject: [PATCH 473/590] Create README.md --- core-java-modules/core-java-concurrency-advanced-4/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/README.md diff --git a/core-java-modules/core-java-concurrency-advanced-4/README.md b/core-java-modules/core-java-concurrency-advanced-4/README.md new file mode 100644 index 0000000000..98f2894515 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Binary Semaphore vs Reentrant Lock](https://www.baeldung.com/java-binary-semaphore-vs-reentrant-lock) From eddab4c557548bce7c83bcdacf8800eb0f6c7e64 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Thu, 14 Jan 2021 01:36:35 +0800 Subject: [PATCH 474/590] [BAEL-4601] Revision: Simplifies assertions --- .../jpa/hibernateunproxy/HibernateProxyIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java index a831639f5d..717745bb13 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java @@ -27,7 +27,7 @@ public class HibernateProxyIntegrationTest { @Test public void givenPaymentReceipt_whenAccessingPayment_thenVerifyType() { PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); - Assert.assertEquals(true, paymentReceipt.getPayment() instanceof HibernateProxy); + Assert.assertTrue(paymentReceipt.getPayment() instanceof HibernateProxy); } @Test @@ -39,7 +39,7 @@ public class HibernateProxyIntegrationTest { entityManager.persist(payment); entityManager.getTransaction().commit(); - Assert.assertEquals(true, webUser instanceof HibernateProxy); + Assert.assertTrue(webUser instanceof HibernateProxy); } @Test @@ -53,7 +53,7 @@ public class HibernateProxyIntegrationTest { @Test public void givenPaymentReceipt_whenPaymentIsUnproxied_thenReturnRealEntityObject() { PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); - Assert.assertEquals(true, Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); + Assert.assertTrue(Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); } private static void populateH2DB() { From 0785727da410d21dcf1b67660d84210583a93dd9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 13:45:12 +0800 Subject: [PATCH 475/590] Create README.md --- guest/core-kotlin/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 guest/core-kotlin/README.md diff --git a/guest/core-kotlin/README.md b/guest/core-kotlin/README.md new file mode 100644 index 0000000000..c211773f27 --- /dev/null +++ b/guest/core-kotlin/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Kotlin vs Java](https://www.baeldung.com/kotlin/kotlin-vs-java) From 7e51af38d962b0f26f630bc0db1527778a7c4f87 Mon Sep 17 00:00:00 2001 From: CHANDRAKANT Kumar Date: Thu, 14 Jan 2021 15:18:33 +0530 Subject: [PATCH 476/590] Corrected the name of unit test to mark them as manual. --- ....java => MyCounterJCStressManualTest.java} | 8 ++- ...> MyCounterMultithreadedTCManualTest.java} | 12 ++-- .../concurrent/MyCounterSimpleManualTest.java | 63 +++++++++++++++++++ .../concurrent/MyCounterSimpleUnitTest.java | 60 ------------------ .../MyCounterTempusFugitManualTest.java | 41 ++++++++++++ .../MyCounterTempusFugitUnitTest.java | 37 ----------- .../MyCounterThreadWeaverManualTest.java | 48 ++++++++++++++ .../MyCounterThreadWeaverUnitTest.java | 44 ------------- 8 files changed, 167 insertions(+), 146 deletions(-) rename core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/{MyCounterJCStressUnitTest.java => MyCounterJCStressManualTest.java} (74%) rename core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/{MyCounterMultithreadedTCUnitTest.java => MyCounterMultithreadedTCManualTest.java} (59%) create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java similarity index 74% rename from core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java rename to core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java index 6c76505347..0e6b41d1e9 100644 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java @@ -10,11 +10,17 @@ import org.openjdk.jcstress.annotations.Outcome; import org.openjdk.jcstress.annotations.State; import org.openjdk.jcstress.infra.results.I_Result; +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ @JCStressTest @Outcome(id = "1", expect = ACCEPTABLE_INTERESTING, desc = "One update lost.") @Outcome(id = "2", expect = ACCEPTABLE, desc = "Both updates.") @State -public class MyCounterJCStressUnitTest { +public class MyCounterJCStressManualTest { private MyCounter counter; diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java similarity index 59% rename from core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java rename to core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java index 8a0bedf6c2..985e316635 100644 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java @@ -1,12 +1,17 @@ package com.baeldung.concurrent; -import org.junit.Ignore; import org.junit.Test; import edu.umd.cs.mtc.MultithreadedTestCase; import edu.umd.cs.mtc.TestFramework; -public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase { +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterMultithreadedTCManualTest extends MultithreadedTestCase { private MyCounter counter; @@ -29,9 +34,8 @@ public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase { assertEquals(2, counter.getCount()); } - @Ignore @Test public void testCounter() throws Throwable { - TestFramework.runManyTimes(new MyCounterMultithreadedTCUnitTest(), 1000); + TestFramework.runManyTimes(new MyCounterMultithreadedTCManualTest(), 1000); } } diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java new file mode 100644 index 0000000000..cba30da34b --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java @@ -0,0 +1,63 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.junit.Test; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterSimpleManualTest { + + @Test + public void testCounter() { + MyCounter counter = new MyCounter(); + for (int i = 0; i < 500; i++) + counter.increment(); + assertEquals(500, counter.getCount()); + } + + @Test + public void testCounterWithConcurrency() throws InterruptedException { + int numberOfThreads = 100; + ExecutorService service = Executors.newFixedThreadPool(10); + CountDownLatch latch = new CountDownLatch(numberOfThreads); + MyCounter counter = new MyCounter(); + for (int i = 0; i < numberOfThreads; i++) { + service.execute(() -> { + counter.increment(); + latch.countDown(); + }); + } + latch.await(); + assertEquals(numberOfThreads, counter.getCount()); + } + + @Test + public void testSummationWithConcurrencyAndWait() throws InterruptedException { + int numberOfThreads = 2; + ExecutorService service = Executors.newFixedThreadPool(10); + CountDownLatch latch = new CountDownLatch(numberOfThreads); + MyCounter counter = new MyCounter(); + for (int i = 0; i < numberOfThreads; i++) { + service.submit(() -> { + try { + counter.incrementWithWait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + latch.countDown(); + }); + } + latch.await(); + assertEquals(numberOfThreads, counter.getCount()); + } + +} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java deleted file mode 100644 index 9a405e7e24..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.junit.Ignore; -import org.junit.Test; - -public class MyCounterSimpleUnitTest { - - @Test - public void testCounter() { - MyCounter counter = new MyCounter(); - for (int i = 0; i < 500; i++) - counter.increment(); - assertEquals(500, counter.getCount()); - } - - @Ignore - @Test - public void testCounterWithConcurrency() throws InterruptedException { - int numberOfThreads = 100; - ExecutorService service = Executors.newFixedThreadPool(10); - CountDownLatch latch = new CountDownLatch(numberOfThreads); - MyCounter counter = new MyCounter(); - for (int i = 0; i < numberOfThreads; i++) { - service.execute(() -> { - counter.increment(); - latch.countDown(); - }); - } - latch.await(); - assertEquals(numberOfThreads, counter.getCount()); - } - - @Ignore - @Test - public void testSummationWithConcurrencyAndWait() throws InterruptedException { - int numberOfThreads = 2; - ExecutorService service = Executors.newFixedThreadPool(10); - CountDownLatch latch = new CountDownLatch(numberOfThreads); - MyCounter counter = new MyCounter(); - for (int i = 0; i < numberOfThreads; i++) { - service.submit(() -> { - try { - counter.incrementWithWait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - latch.countDown(); - }); - } - latch.await(); - assertEquals(numberOfThreads, counter.getCount()); - } - -} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java new file mode 100644 index 0000000000..a4ac643f7e --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java @@ -0,0 +1,41 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import org.junit.AfterClass; +import org.junit.Rule; +import org.junit.Test; + +import com.google.code.tempusfugit.concurrency.ConcurrentRule; +import com.google.code.tempusfugit.concurrency.RepeatingRule; +import com.google.code.tempusfugit.concurrency.annotations.Concurrent; +import com.google.code.tempusfugit.concurrency.annotations.Repeating; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterTempusFugitManualTest { + + @Rule + public ConcurrentRule concurrently = new ConcurrentRule(); + @Rule + public RepeatingRule rule = new RepeatingRule(); + + private static MyCounter counter = new MyCounter(); + + @Test + @Concurrent(count = 2) + @Repeating(repetition = 10) + public void runsMultipleTimes() { + counter.increment(); + } + + @AfterClass + public static void annotatedTestRunsMultipleTimes() throws InterruptedException { + assertEquals(counter.getCount(), 20); + } + +} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java deleted file mode 100644 index 36a2031e78..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - -import com.google.code.tempusfugit.concurrency.ConcurrentRule; -import com.google.code.tempusfugit.concurrency.RepeatingRule; -import com.google.code.tempusfugit.concurrency.annotations.Concurrent; -import com.google.code.tempusfugit.concurrency.annotations.Repeating; - -public class MyCounterTempusFugitUnitTest { - - @Rule - public ConcurrentRule concurrently = new ConcurrentRule(); - @Rule - public RepeatingRule rule = new RepeatingRule(); - - private static MyCounter counter = new MyCounter(); - - @Ignore - @Test - @Concurrent(count = 2) - @Repeating(repetition = 10) - public void runsMultipleTimes() { - counter.increment(); - } - - @AfterClass - public static void annotatedTestRunsMultipleTimes() throws InterruptedException { - assertEquals(counter.getCount(), 20); - } - -} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java new file mode 100644 index 0000000000..2acfc4ee71 --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java @@ -0,0 +1,48 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.google.testing.threadtester.AnnotatedTestRunner; +import com.google.testing.threadtester.ThreadedAfter; +import com.google.testing.threadtester.ThreadedBefore; +import com.google.testing.threadtester.ThreadedMain; +import com.google.testing.threadtester.ThreadedSecondary; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterThreadWeaverManualTest { + + private MyCounter counter; + + @ThreadedBefore + public void before() { + counter = new MyCounter(); + } + + @ThreadedMain + public void mainThread() { + counter.increment(); + } + + @ThreadedSecondary + public void secondThread() { + counter.increment(); + } + + @ThreadedAfter + public void after() { + assertEquals(2, counter.getCount()); + } + + @Test + public void testCounter() { + new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java deleted file mode 100644 index e65a963584..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import org.junit.Ignore; -import org.junit.Test; - -import com.google.testing.threadtester.AnnotatedTestRunner; -import com.google.testing.threadtester.ThreadedAfter; -import com.google.testing.threadtester.ThreadedBefore; -import com.google.testing.threadtester.ThreadedMain; -import com.google.testing.threadtester.ThreadedSecondary; - -public class MyCounterThreadWeaverUnitTest { - - private MyCounter counter; - - @ThreadedBefore - public void before() { - counter = new MyCounter(); - } - - @ThreadedMain - public void mainThread() { - counter.increment(); - } - - @ThreadedSecondary - public void secondThread() { - counter.increment(); - } - - @ThreadedAfter - public void after() { - assertEquals(2, counter.getCount()); - } - - @Ignore - @Test - public void testCounter() { - new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class); - } - -} \ No newline at end of file From 1c5185b54940c2089fc7a558f2bb614e3d256217 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 14 Jan 2021 11:43:32 -0300 Subject: [PATCH 477/590] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests --- spring-boot-modules/spring-boot-environment/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index d34bbd18c0..e3a8186cbf 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -33,6 +33,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + org.springframework.boot From 52db422b6c303b1b9018a85d842981ff427eece4 Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Fri, 15 Jan 2021 04:34:00 +0530 Subject: [PATCH 478/590] BAEL-4695 - Evaluating a Math Expression in Java (#10345) * Added code for checking if a class is abstract or not. * Renamed test name as per review comments. * BAEL-4695 - Added code to evaluate math expressions. * BAEL-4695 - Added test case for math function. * BAEL-4695 Added consistent examples and entry in parent pom. * BAEL-4695 - Added more examples --- .../core-java-lang-math-3/pom.xml | 35 +++++++ .../EvalauteMathExpressionsUnitTest.java | 91 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 3 files changed, 127 insertions(+) create mode 100644 core-java-modules/core-java-lang-math-3/pom.xml create mode 100644 core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java diff --git a/core-java-modules/core-java-lang-math-3/pom.xml b/core-java-modules/core-java-lang-math-3/pom.xml new file mode 100644 index 0000000000..27c2372ab6 --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + core-java-lang-math-3 + 0.0.1-SNAPSHOT + core-java-lang-math-3 + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + net.objecthunter + exp4j + 0.4.8 + + + + com.fathzer + javaluator + 3.0.3 + + + + + + + + + diff --git a/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java new file mode 100644 index 0000000000..a251e8d545 --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java @@ -0,0 +1,91 @@ +package com.baeldung.math.evaluate; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.fathzer.soft.javaluator.DoubleEvaluator; +import com.fathzer.soft.javaluator.StaticVariableSet; + +import net.objecthunter.exp4j.Expression; +import net.objecthunter.exp4j.ExpressionBuilder; + +public class EvalauteMathExpressionsUnitTest { + + @Test + public void givenSimpleExpression_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("3+2").build(); + double result = expression.evaluate(); + Assertions.assertEquals(5, result); + } + + @Test + public void givenTwoVariables_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("3x+2y").variables("x", "y") + .build() + .setVariable("x", 2) + .setVariable("y", 3); + double result = expression.evaluate(); + Assertions.assertEquals(12, result); + } + + @Test + public void givenMathFunctions_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("sin(x)*sin(x)+cos(x)*cos(x)").variables("x") + .build() + .setVariable("x", 0.5); + double result = expression.evaluate(); + Assertions.assertEquals(1, result); + } + + @Test + public void givenExpression_whenCallEvaluateMethod_thenSuccess() { + String expression = "3+2"; + DoubleEvaluator eval = new DoubleEvaluator(); + Double result = eval.evaluate(expression); + Assertions.assertEquals(5, result); + } + + @Test + public void givenVariables_whenCallEvaluateMethod_thenSuccess() { + String expression = "3*x+2*y"; + DoubleEvaluator eval = new DoubleEvaluator(); + StaticVariableSet variables = new StaticVariableSet(); + variables.set("x", 2.0); + variables.set("y", 3.0); + Double result = eval.evaluate(expression, variables); + Assertions.assertEquals(12, result); + } + + @Test + public void givenMathFunction_whenCallEvaluateMethod_thenSuccess() { + String expression = "sin(x)*sin(x)+cos(x)*cos(x)"; + DoubleEvaluator eval = new DoubleEvaluator(); + StaticVariableSet variables = new StaticVariableSet(); + variables.set("x", 0.5); + Double result = eval.evaluate(expression, variables); + Assertions.assertEquals(1, result); + } + + @Test + public void givenJavaScriptingApiAndSimpleExpression_whenCallEvalMethod_thenSuccess() throws ScriptException { + ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); + ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript"); + String expression = "3+2"; + Integer result = (Integer) scriptEngine.eval(expression); + Assertions.assertEquals(5, result); + } + + @Test + public void givenJavaScriptingApi_whenCallEvalMethod_thenSuccess() throws ScriptException { + ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); + ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript"); + String expression = "x=2; y=3; 3*x+2*y;"; + Double result = (Double) scriptEngine.eval(expression); + Assertions.assertEquals(12, result); + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 140d5efe3b..2d342c4216 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -84,6 +84,7 @@ core-java-lang-3 core-java-lang-math core-java-lang-math-2 + core-java-lang-math-3 core-java-lang-oop-constructors core-java-lang-oop-patterns core-java-lang-oop-generics From e54423ce83c48abda00ca295eb1d29ef6501a28e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:15:41 +0530 Subject: [PATCH 479/590] JAVA-4010: Added new module and moved 3 articles to it --- .../spring-resttemplate-3/.gitignore | 12 ++ .../spring-resttemplate-3/README.md | 11 ++ .../spring-resttemplate-3/pom.xml | 29 +++++ .../lists/EmployeeApplication.java | 16 +++ .../lists/client/EmployeeClient.java | 120 ++++++++++++++++++ .../lists/controller/EmployeeResource.java | 46 +++++++ .../resttemplate/lists/dto/Employee.java | 40 ++++++ .../resttemplate/lists/dto/EmployeeList.java | 29 +++++ .../lists/service/EmployeeService.java | 25 ++++ .../web/upload/app/UploadApplication.java | 17 +++ .../client/MultipartFileUploadClient.java | 61 +++++++++ .../upload/controller/FileServerResource.java | 43 +++++++ .../src/main/resources/application.properties | 2 + .../src/main/resources/logback.xml | 23 ++++ .../java/com/baeldung/SpringContextTest.java | 15 +++ .../LargeFileDownloadIntegrationTest.java | 105 +++++++++++++++ .../src/test/resources/.gitignore | 13 ++ .../src/test/resources/logback-test.xml | 23 ++++ 18 files changed, 630 insertions(+) create mode 100644 spring-web-modules/spring-resttemplate-3/.gitignore create mode 100644 spring-web-modules/spring-resttemplate-3/README.md create mode 100644 spring-web-modules/spring-resttemplate-3/pom.xml create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml diff --git a/spring-web-modules/spring-resttemplate-3/.gitignore b/spring-web-modules/spring-resttemplate-3/.gitignore new file mode 100644 index 0000000000..8f98975dc9 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/.gitignore @@ -0,0 +1,12 @@ +*.class + +#folders# +/target +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/README.md b/spring-web-modules/spring-resttemplate-3/README.md new file mode 100644 index 0000000000..6a00d226db --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/README.md @@ -0,0 +1,11 @@ +## Spring RestTemplate + +This module contains articles about Spring RestTemplate + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles: +- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload) +- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list) +- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/pom.xml b/spring-web-modules/spring-resttemplate-3/pom.xml new file mode 100644 index 0000000000..b1c26e002f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + spring-resttemplate-3 + 0.1-SNAPSHOT + spring-resttemplate-3 + war + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + + diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java new file mode 100644 index 0000000000..1967d4f2aa --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.resttemplate.lists; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Sample application used to demonstrate working with Lists and RestTemplate. + */ +@SpringBootApplication +public class EmployeeApplication +{ + public static void main(String[] args) + { + SpringApplication.run(EmployeeApplication.class, args); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java new file mode 100644 index 0000000000..49e375f9cc --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java @@ -0,0 +1,120 @@ +package com.baeldung.resttemplate.lists.client; + +import com.baeldung.resttemplate.lists.dto.Employee; +import com.baeldung.resttemplate.lists.dto.EmployeeList; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Arrays.asList; + +/** + * Application that shows how to use Lists with RestTemplate. + */ +public class EmployeeClient { + public static void main(String[] args) { + EmployeeClient employeeClient = new EmployeeClient(); + + System.out.println("Calling GET for entity using arrays"); + employeeClient.getForEntityEmployeesAsArray(); + + System.out.println("Calling GET using ParameterizedTypeReference"); + employeeClient.getAllEmployeesUsingParameterizedTypeReference(); + + System.out.println("Calling GET using wrapper class"); + employeeClient.getAllEmployeesUsingWrapperClass(); + + System.out.println("Calling POST using normal lists"); + employeeClient.createEmployeesUsingLists(); + + System.out.println("Calling POST using wrapper class"); + employeeClient.createEmployeesUsingWrapperClass(); + } + + public EmployeeClient() { + + } + + public Employee[] getForEntityEmployeesAsArray() { + + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity response = + restTemplate.getForEntity( + "http://localhost:8082/spring-rest/employees/", + Employee[].class); + + Employee[] employees = response.getBody(); + + assert employees != null; + asList(employees).forEach(System.out::println); + + return employees; + + } + + + public List getAllEmployeesUsingParameterizedTypeReference() { + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity> response = + restTemplate.exchange( + "http://localhost:8082/spring-rest/employees/", + HttpMethod.GET, + null, + new ParameterizedTypeReference>() { + }); + + List employees = response.getBody(); + + assert employees != null; + employees.forEach(System.out::println); + + return employees; + } + + public List getAllEmployeesUsingWrapperClass() { + RestTemplate restTemplate = new RestTemplate(); + + EmployeeList response = + restTemplate.getForObject( + "http://localhost:8082/spring-rest/employees/v2", + EmployeeList.class); + + List employees = response.getEmployees(); + + employees.forEach(System.out::println); + + return employees; + } + + public void createEmployeesUsingLists() { + RestTemplate restTemplate = new RestTemplate(); + + List newEmployees = new ArrayList<>(); + newEmployees.add(new Employee(3, "Intern")); + newEmployees.add(new Employee(4, "CEO")); + + restTemplate.postForObject( + "http://localhost:8082/spring-rest/employees/", + newEmployees, + ResponseEntity.class); + } + + public void createEmployeesUsingWrapperClass() { + RestTemplate restTemplate = new RestTemplate(); + + List newEmployees = new ArrayList<>(); + newEmployees.add(new Employee(3, "Intern")); + newEmployees.add(new Employee(4, "CEO")); + + restTemplate.postForObject( + "http://localhost:8082/spring-rest/employees/v2/", + new EmployeeList(newEmployees), + ResponseEntity.class); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java new file mode 100644 index 0000000000..8a4d510f63 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java @@ -0,0 +1,46 @@ +package com.baeldung.resttemplate.lists.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.resttemplate.lists.dto.Employee; +import com.baeldung.resttemplate.lists.dto.EmployeeList; +import com.baeldung.resttemplate.lists.service.EmployeeService; + +import java.util.List; + +@RestController +@RequestMapping("/employees") +public class EmployeeResource +{ + @Autowired + private EmployeeService employeeService; + + @RequestMapping(method = RequestMethod.GET, path = "/") + public List getEmployees() + { + return employeeService.getAllEmployees(); + } + + @RequestMapping(method = RequestMethod.GET, path = "/v2") + public EmployeeList getEmployeesUsingWrapperClass() + { + List employees = employeeService.getAllEmployees(); + return new EmployeeList(employees); + } + + @RequestMapping(method = RequestMethod.POST, path = "/") + public void addEmployees(@RequestBody List employees) + { + employeeService.addEmployees(employees); + } + + @RequestMapping(method = RequestMethod.POST, path = "/v2") + public void addEmployeesUsingWrapperClass(@RequestBody EmployeeList employeeWrapper) + { + employeeService.addEmployees(employeeWrapper.getEmployees()); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java new file mode 100644 index 0000000000..0754c13c5b --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java @@ -0,0 +1,40 @@ +package com.baeldung.resttemplate.lists.dto; + +public class Employee { + + public long id; + public String title; + + public Employee() + { + + } + + public Employee(long id, String title) + { + this.id = id; + this.title = title; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public String toString() + { + return "Employee #" + id + "[" + title + "]"; + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java new file mode 100644 index 0000000000..eeabbfe450 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java @@ -0,0 +1,29 @@ +package com.baeldung.resttemplate.lists.dto; + +import java.util.ArrayList; +import java.util.List; + +public class EmployeeList +{ + public List employees; + + public EmployeeList() + { + employees = new ArrayList<>(); + } + + public EmployeeList(List employees) + { + this.employees = employees; + } + + public void setEmployees(List employees) + { + this.employees = employees; + } + + public List getEmployees() + { + return employees; + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java new file mode 100644 index 0000000000..8a1773483a --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java @@ -0,0 +1,25 @@ +package com.baeldung.resttemplate.lists.service; + +import org.springframework.stereotype.Service; + +import com.baeldung.resttemplate.lists.dto.Employee; + +import java.util.ArrayList; +import java.util.List; + +@Service("EmployeeListService") +public class EmployeeService +{ + public List getAllEmployees() + { + List employees = new ArrayList<>(); + employees.add(new Employee(1, "Manager")); + employees.add(new Employee(2, "Java Developer")); + return employees; + } + + public void addEmployees(List employees) + { + employees.forEach(e -> System.out.println("Adding new employee " + e)); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java new file mode 100644 index 0000000000..f3b1c0dc6f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.web.upload.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; + +@EnableAutoConfiguration +@ComponentScan("com.baeldung.web.upload") +@SpringBootApplication +public class UploadApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(UploadApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java new file mode 100644 index 0000000000..547aec17a0 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java @@ -0,0 +1,61 @@ +package com.baeldung.web.upload.client; + +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class MultipartFileUploadClient { + + public static void main(String[] args) throws IOException { + uploadSingleFile(); + uploadMultipleFile(); + } + + private static void uploadSingleFile() throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("file", getTestFile()); + + + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + String serverUrl = "http://localhost:8082/spring-rest/fileserver/singlefileupload/"; + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); + System.out.println("Response code: " + response.getStatusCode()); + } + + private static void uploadMultipleFile() throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("files", getTestFile()); + body.add("files", getTestFile()); + body.add("files", getTestFile()); + + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + String serverUrl = "http://localhost:8082/spring-rest/fileserver/multiplefileupload/"; + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); + System.out.println("Response code: " + response.getStatusCode()); + } + + public static Resource getTestFile() throws IOException { + Path testFile = Files.createTempFile("test-file", ".txt"); + System.out.println("Creating and Uploading Test File: " + testFile); + Files.write(testFile, "Hello World !!, This is a test file.".getBytes()); + return new FileSystemResource(testFile.toFile()); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java new file mode 100644 index 0000000000..3863a8f20d --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java @@ -0,0 +1,43 @@ +package com.baeldung.web.upload.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +@RestController +@RequestMapping("/fileserver") +public class FileServerResource { + + @RequestMapping(path = "/singlefileupload/", method = RequestMethod.POST) + public ResponseEntity processFile(@RequestParam("file") MultipartFile file) throws IOException { + + byte[] bytes = file.getBytes(); + + System.out.println("File Name: " + file.getOriginalFilename()); + System.out.println("File Content Type: " + file.getContentType()); + System.out.println("File Content:\n" + new String(bytes)); + + return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); + } + + @RequestMapping(path = "/multiplefileupload/", method = RequestMethod.POST) + public ResponseEntity processFile(@RequestParam("files") List files) throws IOException { + + for (MultipartFile file : files) { + byte[] bytes = file.getBytes(); + + System.out.println("File Name: " + file.getOriginalFilename()); + System.out.println("File Content Type: " + file.getContentType()); + System.out.println("File Content:\n" + new String(bytes)); + } + + return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties new file mode 100644 index 0000000000..1a26e3ad99 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8082 +server.servlet.context-path=/spring-rest \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml b/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml new file mode 100644 index 0000000000..9f48d36486 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml @@ -0,0 +1,23 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..26972a0aca --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,15 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { com.baeldung.web.upload.app.UploadApplication.class, }) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java new file mode 100644 index 0000000000..d8fc58319f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java @@ -0,0 +1,105 @@ +package com.baeldung.largefile; + +import java.io.File; +import java.io.FileOutputStream; + +import org.assertj.core.api.Assertions; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.util.StreamUtils; +import org.springframework.web.client.RestTemplate; + +public class LargeFileDownloadIntegrationTest { + + static String FILE_URL = "http://ovh.net/files/1Mio.dat"; + + RestTemplate restTemplate; + + @Before + public void setUp() { + restTemplate = new RestTemplate(); + } + + @Test + public void givenResumableUrl_whenUrlCalledByHeadOption_thenExpectHeadersAvailable() { + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + Assertions + .assertThat(headers.get("Accept-Ranges")) + .contains("bytes"); + Assertions + .assertThat(headers.getContentLength()) + .isGreaterThan(0); + } + + @Test + public void givenResumableUrl_whenDownloadCompletely_thenExpectCorrectFileSize() { + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + long contentLength = headers.getContentLength(); + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, null, clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + Assertions + .assertThat(file.length()) + .isEqualTo(contentLength); + } + + @Test + public void givenResumableUrl_whenDownloadRange_thenExpectFileSizeEqualOrLessThanRange() { + int range = 10; + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + Assertions + .assertThat(file.length()) + .isLessThanOrEqualTo(range); + } + + @Test + public void givenResumableUrl_whenPauseDownloadAndResume_thenExpectCorrectFileSize() { + + int range = 10; + + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + long contentLength = headers.getContentLength(); + + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + + Assertions + .assertThat(file.length()) + .isLessThanOrEqualTo(range); + + restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=%d-%d", file.length(), contentLength)), clientHttpResponse -> { + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(file, true)); + return file; + }); + + Assertions + .assertThat(file.length()) + .isEqualTo(contentLength); + + } + +} diff --git a/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore b/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..9f48d36486 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml @@ -0,0 +1,23 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + \ No newline at end of file From 2931dcbeb495abfac95cfbb28eaa2f1a97d69a28 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:16:39 +0530 Subject: [PATCH 480/590] JAVA-4010: Moved 3 articles from this module --- .../spring-resttemplate/README.md | 3 - .../lists/EmployeeApplication.java | 16 --- .../lists/client/EmployeeClient.java | 120 ------------------ .../lists/controller/EmployeeResource.java | 46 ------- .../resttemplate/lists/dto/Employee.java | 40 ------ .../resttemplate/lists/dto/EmployeeList.java | 29 ----- .../lists/service/EmployeeService.java | 25 ---- .../web/upload/app/UploadApplication.java | 17 --- .../client/MultipartFileUploadClient.java | 61 --------- .../upload/controller/FileServerResource.java | 43 ------- .../java/com/baeldung/SpringContextTest.java | 6 +- .../LargeFileDownloadIntegrationTest.java | 109 ---------------- 12 files changed, 2 insertions(+), 513 deletions(-) delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java delete mode 100644 spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java diff --git a/spring-web-modules/spring-resttemplate/README.md b/spring-web-modules/spring-resttemplate/README.md index 952f35e90b..e8c240d86b 100644 --- a/spring-web-modules/spring-resttemplate/README.md +++ b/spring-web-modules/spring-resttemplate/README.md @@ -11,10 +11,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RestTemplate Error Handling](https://www.baeldung.com/spring-rest-template-error-handling) - [Configure a RestTemplate with RestTemplateBuilder](https://www.baeldung.com/spring-rest-template-builder) - [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) -- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) - [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor) -- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload) -- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list) - [HTTP PUT vs HTTP PATCH in a REST API](https://www.baeldung.com/http-put-patch-difference-spring) ### NOTE: diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java deleted file mode 100644 index 1967d4f2aa..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.resttemplate.lists; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Sample application used to demonstrate working with Lists and RestTemplate. - */ -@SpringBootApplication -public class EmployeeApplication -{ - public static void main(String[] args) - { - SpringApplication.run(EmployeeApplication.class, args); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java deleted file mode 100644 index 49e375f9cc..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.baeldung.resttemplate.lists.client; - -import com.baeldung.resttemplate.lists.dto.Employee; -import com.baeldung.resttemplate.lists.dto.EmployeeList; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import java.util.ArrayList; -import java.util.List; - -import static java.util.Arrays.asList; - -/** - * Application that shows how to use Lists with RestTemplate. - */ -public class EmployeeClient { - public static void main(String[] args) { - EmployeeClient employeeClient = new EmployeeClient(); - - System.out.println("Calling GET for entity using arrays"); - employeeClient.getForEntityEmployeesAsArray(); - - System.out.println("Calling GET using ParameterizedTypeReference"); - employeeClient.getAllEmployeesUsingParameterizedTypeReference(); - - System.out.println("Calling GET using wrapper class"); - employeeClient.getAllEmployeesUsingWrapperClass(); - - System.out.println("Calling POST using normal lists"); - employeeClient.createEmployeesUsingLists(); - - System.out.println("Calling POST using wrapper class"); - employeeClient.createEmployeesUsingWrapperClass(); - } - - public EmployeeClient() { - - } - - public Employee[] getForEntityEmployeesAsArray() { - - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity response = - restTemplate.getForEntity( - "http://localhost:8082/spring-rest/employees/", - Employee[].class); - - Employee[] employees = response.getBody(); - - assert employees != null; - asList(employees).forEach(System.out::println); - - return employees; - - } - - - public List getAllEmployeesUsingParameterizedTypeReference() { - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity> response = - restTemplate.exchange( - "http://localhost:8082/spring-rest/employees/", - HttpMethod.GET, - null, - new ParameterizedTypeReference>() { - }); - - List employees = response.getBody(); - - assert employees != null; - employees.forEach(System.out::println); - - return employees; - } - - public List getAllEmployeesUsingWrapperClass() { - RestTemplate restTemplate = new RestTemplate(); - - EmployeeList response = - restTemplate.getForObject( - "http://localhost:8082/spring-rest/employees/v2", - EmployeeList.class); - - List employees = response.getEmployees(); - - employees.forEach(System.out::println); - - return employees; - } - - public void createEmployeesUsingLists() { - RestTemplate restTemplate = new RestTemplate(); - - List newEmployees = new ArrayList<>(); - newEmployees.add(new Employee(3, "Intern")); - newEmployees.add(new Employee(4, "CEO")); - - restTemplate.postForObject( - "http://localhost:8082/spring-rest/employees/", - newEmployees, - ResponseEntity.class); - } - - public void createEmployeesUsingWrapperClass() { - RestTemplate restTemplate = new RestTemplate(); - - List newEmployees = new ArrayList<>(); - newEmployees.add(new Employee(3, "Intern")); - newEmployees.add(new Employee(4, "CEO")); - - restTemplate.postForObject( - "http://localhost:8082/spring-rest/employees/v2/", - new EmployeeList(newEmployees), - ResponseEntity.class); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java deleted file mode 100644 index 8a4d510f63..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.resttemplate.lists.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.resttemplate.lists.dto.Employee; -import com.baeldung.resttemplate.lists.dto.EmployeeList; -import com.baeldung.resttemplate.lists.service.EmployeeService; - -import java.util.List; - -@RestController -@RequestMapping("/employees") -public class EmployeeResource -{ - @Autowired - private EmployeeService employeeService; - - @RequestMapping(method = RequestMethod.GET, path = "/") - public List getEmployees() - { - return employeeService.getAllEmployees(); - } - - @RequestMapping(method = RequestMethod.GET, path = "/v2") - public EmployeeList getEmployeesUsingWrapperClass() - { - List employees = employeeService.getAllEmployees(); - return new EmployeeList(employees); - } - - @RequestMapping(method = RequestMethod.POST, path = "/") - public void addEmployees(@RequestBody List employees) - { - employeeService.addEmployees(employees); - } - - @RequestMapping(method = RequestMethod.POST, path = "/v2") - public void addEmployeesUsingWrapperClass(@RequestBody EmployeeList employeeWrapper) - { - employeeService.addEmployees(employeeWrapper.getEmployees()); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java deleted file mode 100644 index 0754c13c5b..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.resttemplate.lists.dto; - -public class Employee { - - public long id; - public String title; - - public Employee() - { - - } - - public Employee(long id, String title) - { - this.id = id; - this.title = title; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString() - { - return "Employee #" + id + "[" + title + "]"; - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java deleted file mode 100644 index eeabbfe450..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.resttemplate.lists.dto; - -import java.util.ArrayList; -import java.util.List; - -public class EmployeeList -{ - public List employees; - - public EmployeeList() - { - employees = new ArrayList<>(); - } - - public EmployeeList(List employees) - { - this.employees = employees; - } - - public void setEmployees(List employees) - { - this.employees = employees; - } - - public List getEmployees() - { - return employees; - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java deleted file mode 100644 index 8a1773483a..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.resttemplate.lists.service; - -import org.springframework.stereotype.Service; - -import com.baeldung.resttemplate.lists.dto.Employee; - -import java.util.ArrayList; -import java.util.List; - -@Service("EmployeeListService") -public class EmployeeService -{ - public List getAllEmployees() - { - List employees = new ArrayList<>(); - employees.add(new Employee(1, "Manager")); - employees.add(new Employee(2, "Java Developer")); - return employees; - } - - public void addEmployees(List employees) - { - employees.forEach(e -> System.out.println("Adding new employee " + e)); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java deleted file mode 100644 index f3b1c0dc6f..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.web.upload.app; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ComponentScan; - -@EnableAutoConfiguration -@ComponentScan("com.baeldung.web.upload") -@SpringBootApplication -public class UploadApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(UploadApplication.class, args); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java deleted file mode 100644 index 547aec17a0..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.web.upload.client; - -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class MultipartFileUploadClient { - - public static void main(String[] args) throws IOException { - uploadSingleFile(); - uploadMultipleFile(); - } - - private static void uploadSingleFile() throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - - MultiValueMap body = new LinkedMultiValueMap<>(); - body.add("file", getTestFile()); - - - HttpEntity> requestEntity = new HttpEntity<>(body, headers); - String serverUrl = "http://localhost:8082/spring-rest/fileserver/singlefileupload/"; - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); - System.out.println("Response code: " + response.getStatusCode()); - } - - private static void uploadMultipleFile() throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - - MultiValueMap body = new LinkedMultiValueMap<>(); - body.add("files", getTestFile()); - body.add("files", getTestFile()); - body.add("files", getTestFile()); - - HttpEntity> requestEntity = new HttpEntity<>(body, headers); - String serverUrl = "http://localhost:8082/spring-rest/fileserver/multiplefileupload/"; - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); - System.out.println("Response code: " + response.getStatusCode()); - } - - public static Resource getTestFile() throws IOException { - Path testFile = Files.createTempFile("test-file", ".txt"); - System.out.println("Creating and Uploading Test File: " + testFile); - Files.write(testFile, "Hello World !!, This is a test file.".getBytes()); - return new FileSystemResource(testFile.toFile()); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java deleted file mode 100644 index 3863a8f20d..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.web.upload.controller; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.List; - -@RestController -@RequestMapping("/fileserver") -public class FileServerResource { - - @RequestMapping(path = "/singlefileupload/", method = RequestMethod.POST) - public ResponseEntity processFile(@RequestParam("file") MultipartFile file) throws IOException { - - byte[] bytes = file.getBytes(); - - System.out.println("File Name: " + file.getOriginalFilename()); - System.out.println("File Content Type: " + file.getContentType()); - System.out.println("File Content:\n" + new String(bytes)); - - return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); - } - - @RequestMapping(path = "/multiplefileupload/", method = RequestMethod.POST) - public ResponseEntity processFile(@RequestParam("files") List files) throws IOException { - - for (MultipartFile file : files) { - byte[] bytes = file.getBytes(); - - System.out.println("File Name: " + file.getOriginalFilename()); - System.out.println("File Content Type: " + file.getContentType()); - System.out.println("File Content:\n" + new String(bytes)); - } - - return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java index 43901cf37f..dc176f5322 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java @@ -8,12 +8,10 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.responseheaders.ResponseHeadersApplication; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { ResponseHeadersApplication.class, - com.baeldung.web.upload.app.UploadApplication.class, - }) +@SpringBootTest(classes = { ResponseHeadersApplication.class }) public class SpringContextTest { @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { + public void whenSpringContextIsBootstrapped_thenNoExceptions() { } } diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java deleted file mode 100644 index eb5d01d06f..0000000000 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.resttemplate; - -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.util.StreamUtils; -import org.springframework.web.client.RestTemplate; - -import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.List; - -public class LargeFileDownloadIntegrationTest { - - static String FILE_URL = "http://ovh.net/files/1Mio.dat"; - - RestTemplate restTemplate; - - @Before - public void setUp() { - restTemplate = new RestTemplate(); - } - - @Test - public void givenResumableUrl_whenUrlCalledByHeadOption_thenExpectHeadersAvailable() { - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - Assertions - .assertThat(headers.get("Accept-Ranges")) - .contains("bytes"); - Assertions - .assertThat(headers.getContentLength()) - .isGreaterThan(0); - } - - @Test - public void givenResumableUrl_whenDownloadCompletely_thenExpectCorrectFileSize() { - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - long contentLength = headers.getContentLength(); - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, null, clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - Assertions - .assertThat(file.length()) - .isEqualTo(contentLength); - } - - @Test - public void givenResumableUrl_whenDownloadRange_thenExpectFileSizeEqualOrLessThanRange() { - int range = 10; - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - Assertions - .assertThat(file.length()) - .isLessThanOrEqualTo(range); - } - - @Test - public void givenResumableUrl_whenPauseDownloadAndResume_thenExpectCorrectFileSize() { - - int range = 10; - - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - long contentLength = headers.getContentLength(); - - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - - Assertions - .assertThat(file.length()) - .isLessThanOrEqualTo(range); - - restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=%d-%d", file.length(), contentLength)), clientHttpResponse -> { - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(file, true)); - return file; - }); - - Assertions - .assertThat(file.length()) - .isEqualTo(contentLength); - - } - -} From a0e7e3bf8005102b12167382e92988c93802b115 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:17:03 +0530 Subject: [PATCH 481/590] JAVA-4010: Added new module to parent pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index cc2ffcf762..37ee84da25 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -37,6 +37,7 @@ spring-rest-testing spring-resttemplate spring-resttemplate-2 + spring-resttemplate-3 spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 From 6b462cd6c69679fedd58fe58e15df788a7e9faa2 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 15 Jan 2021 16:00:03 -0300 Subject: [PATCH 482/590] Improved spring-properties-file-outside-jar with new 2.4.0 feature --- .../additional.properties | 1 + .../spring-boot-environment/pom.xml | 21 +++++++++++++----- .../src/main/resources/application.properties | 5 +++-- ...ertyImportExternalFileIntegrationTest.java | 22 +++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 spring-boot-modules/spring-boot-environment/additional.properties create mode 100644 spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-environment/additional.properties b/spring-boot-modules/spring-boot-environment/additional.properties new file mode 100644 index 0000000000..676536efa5 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/additional.properties @@ -0,0 +1 @@ +bael.property1=value1 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index e3a8186cbf..a3aab63a2d 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -88,7 +89,6 @@ org.springframework.cloud spring-cloud-context - ${springcloud.version} @@ -99,6 +99,18 @@ + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud-version} + pom + import + + + + ${project.artifactId} @@ -153,9 +165,8 @@ 2.2 18.0 3.1.7 - 2.0.2.RELEASE 4.5.8 - 2.3.3.RELEASE + 2020.0.0 diff --git a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties index 27b7915cff..3d6f37230c 100644 --- a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties @@ -2,6 +2,7 @@ management.endpoints.web.exposure.include=* management.metrics.enable.root=true management.metrics.enable.jvm=true management.endpoint.restart.enabled=true -spring.datasource.jmx-enabled=false +spring.datasource.tomcat.jmx-enabled=false spring.main.allow-bean-definition-overriding=true -management.endpoint.shutdown.enabled=true \ No newline at end of file +management.endpoint.shutdown.enabled=true +spring.config.import=file:./additional.properties,optional:file:/Users/home/config/jdbc.properties \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java new file mode 100644 index 0000000000..04f5445639 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java @@ -0,0 +1,22 @@ +package com.baeldung.properties; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ApplicationPropertyImportExternalFileIntegrationTest { + + @Value("${bael.property1}") + String baelProperty; + + @Test + public void whenExternalisedPropertiesLoadedUsinApplicationProperties_thenReadValues() throws IOException { + assertEquals(baelProperty, "value1"); + } + +} From dce6c4fe126268493f334b278bd282856ab7bf05 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Fri, 15 Jan 2021 17:21:00 -0600 Subject: [PATCH 483/590] BAEL-4695: create and update README files (#10425) --- core-java-modules/core-java-lang-math-2/README.md | 2 +- core-java-modules/core-java-lang-math-3/README.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-lang-math-3/README.md 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 a98ff863ac..5e1dc5af0e 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -14,4 +14,4 @@ - [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 with Java](https://www.baeldung.com/java-largest-power-of-2-less-than-number) -- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math)[[Next -->]](/core-java-modules/core-java-lang-math-3) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md new file mode 100644 index 0000000000..9eee021f8f --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -0,0 +1,8 @@ +========= + +## Core Java 8 Cookbooks and Examples - Part 3 + +### Relevant articles: + +- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) From 77b00187def78bd518b51b2ba1603d49cdd76d08 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 16 Jan 2021 16:27:02 +0200 Subject: [PATCH 484/590] fix channel type, callback --- webrtc/src/main/resources/static/client.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webrtc/src/main/resources/static/client.js b/webrtc/src/main/resources/static/client.js index 059dc84bcb..9b3de9ef6d 100644 --- a/webrtc/src/main/resources/static/client.js +++ b/webrtc/src/main/resources/static/client.js @@ -38,11 +38,7 @@ var input = document.getElementById("messageInput"); function initialize() { var configuration = null; - peerConnection = new RTCPeerConnection(configuration, { - optional : [ { - RtpDataChannels : true - } ] - }); + peerConnection = new RTCPeerConnection(configuration); // Setup ice handling peerConnection.onicecandidate = function(event) { @@ -71,6 +67,11 @@ function initialize() { dataChannel.onclose = function() { console.log("data channel is closed"); }; + + peerConnection.ondatachannel = function (event) { + dataChannel = event.channel; + }; + } function createOffer() { From 72ca7fde484f8645078a0031e4bcf1a5db5587da Mon Sep 17 00:00:00 2001 From: Gilvan Ornelas Fernandes Filho Date: Sat, 16 Jan 2021 11:36:20 -0300 Subject: [PATCH 485/590] Fixing valid password condition --- .../pattern/cleanarchitecture/usercreation/CommonUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java index f7ba9dacc0..c4f105fad5 100644 --- a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java @@ -15,7 +15,7 @@ class CommonUser implements User { @Override public boolean passwordIsValid() { - return password == null || password.length() > 5; + return password != null && password.length() > 5; } @Override From 82b5316bc444fe0032563b7d0511a4e90fff65cb Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 16 Jan 2021 12:20:54 -0300 Subject: [PATCH 486/590] fixed properties files notation --- .../application-multidocument-integration.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties index c4eeba2589..f3bac4c614 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties @@ -1,4 +1,4 @@ -spring.datasource.password: 'password' -spring.datasource.url: jdbc:mysql://localhost:3306/db_integration -spring.datasource.username: user +spring.datasource.password=password +spring.datasource.url=jdbc:mysql://localhost:3306/db_integration +spring.datasource.username=user bael.property=integrationValue \ No newline at end of file From 100e3b652dd7bdfc7369799a292c089dde77a9fb Mon Sep 17 00:00:00 2001 From: Azhwani Date: Sun, 17 Jan 2021 02:08:18 +0100 Subject: [PATCH 487/590] first commit --- .../RestTemplateExceptionApplication.java | 13 +++++ .../controller/ProductApi.java | 50 +++++++++++++++++ .../model/Criterion.java | 28 ++++++++++ .../resttemplateexception/model/Product.java | 43 +++++++++++++++ .../RestTemplateExceptionLiveTest.java | 53 +++++++++++++++++++ 5 files changed, 187 insertions(+) create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/RestTemplateExceptionApplication.java create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Criterion.java create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Product.java create mode 100644 spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/RestTemplateExceptionApplication.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/RestTemplateExceptionApplication.java new file mode 100644 index 0000000000..84a337f5ee --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/RestTemplateExceptionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.resttemplateexception; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestTemplateExceptionApplication { + + public static void main(String[] args) { + SpringApplication.run(RestTemplateExceptionApplication.class, args); + } + +} diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java new file mode 100644 index 0000000000..66fbfa487d --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java @@ -0,0 +1,50 @@ +package com.baeldung.resttemplateexception.controller; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.resttemplateexception.model.Criterion; +import com.baeldung.resttemplateexception.model.Product; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RestController +@RequestMapping("/api") +public class ProductApi { + + private List productList = new ArrayList<>(Arrays.asList(new Product(1, "Acer Aspire 5", 437), new Product(2, "ASUS VivoBook", 650), new Product(3, "Lenovo Legion", 990))); + + @GetMapping("/get") + public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException { + + ObjectMapper objectMapper = new ObjectMapper(); + Criterion crt; + + crt = objectMapper.readValue(criterion, Criterion.class); + if (crt.getProp().equals("name")) + return findByName(crt.getValue()); + + // Search by other properties (id,price) + + return null; + } + + private Product findByName(String name) { + for (Product product : this.productList) { + if (product.getName().equals(name)) { + return product; + } + } + return null; + } + + // Other methods + +} diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Criterion.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Criterion.java new file mode 100644 index 0000000000..9a96ad4dc3 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Criterion.java @@ -0,0 +1,28 @@ +package com.baeldung.resttemplateexception.model; + +public class Criterion { + + private String prop; + private String value; + + public Criterion() { + + } + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Product.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Product.java new file mode 100644 index 0000000000..e4cc29279c --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/model/Product.java @@ -0,0 +1,43 @@ +package com.baeldung.resttemplateexception.model; + +public class Product { + + private int id; + private String name; + private double price; + + public Product() { + + } + + public Product(int id, String name, double price) { + this.id = id; + this.name = name; + this.price = price; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + +} diff --git a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java new file mode 100644 index 0000000000..f5938e1f0a --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java @@ -0,0 +1,53 @@ +package com.baeldung.resttemplateexception; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import com.baeldung.resttemplateexception.model.Product; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { RestTemplate.class, RestTemplateExceptionApplication.class }) +public class RestTemplateExceptionLiveTest { + + @Autowired + RestTemplate restTemplate; + + @Test(expected = IllegalArgumentException.class) + public void givenGetUrl_whenJsonIsPassed_thenThrowException() { + + String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; + Product product = restTemplate.getForObject(url, Product.class); + + } + + @Test + public void givenGetUrl_whenJsonIsPassed_thenGetProduct() { + + String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; + String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}"; + Product product = restTemplate.getForObject(url, Product.class, criterion); + + assertEquals(product.getPrice(), 650, 0); + + } + + @Test + public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() { + + String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}"; + String url = "http://localhost:8080/spring-rest/api/get"; + + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url).queryParam("criterion", criterion); + Product product = restTemplate.getForObject(builder.build().toUri(), Product.class); + + assertEquals(product.getId(), 1, 0); + + } +} From 8396dabf774f1b66bc8a74015b2b6385fc105af3 Mon Sep 17 00:00:00 2001 From: Azhwani Date: Sun, 17 Jan 2021 02:27:34 +0100 Subject: [PATCH 488/590] quick fix --- .../resttemplateexception/controller/ProductApi.java | 6 +----- .../RestTemplateExceptionLiveTest.java | 6 ------ 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java index 66fbfa487d..2c530cae2b 100644 --- a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java @@ -23,11 +23,8 @@ public class ProductApi { @GetMapping("/get") public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - Criterion crt; - - crt = objectMapper.readValue(criterion, Criterion.class); + Criterion crt = objectMapper.readValue(criterion, Criterion.class); if (crt.getProp().equals("name")) return findByName(crt.getValue()); @@ -46,5 +43,4 @@ public class ProductApi { } // Other methods - } diff --git a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java index f5938e1f0a..adfb8ffa4e 100644 --- a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java +++ b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java @@ -21,26 +21,21 @@ public class RestTemplateExceptionLiveTest { @Test(expected = IllegalArgumentException.class) public void givenGetUrl_whenJsonIsPassed_thenThrowException() { - String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; Product product = restTemplate.getForObject(url, Product.class); - } @Test public void givenGetUrl_whenJsonIsPassed_thenGetProduct() { - String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}"; Product product = restTemplate.getForObject(url, Product.class, criterion); assertEquals(product.getPrice(), 650, 0); - } @Test public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() { - String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}"; String url = "http://localhost:8080/spring-rest/api/get"; @@ -48,6 +43,5 @@ public class RestTemplateExceptionLiveTest { Product product = restTemplate.getForObject(builder.build().toUri(), Product.class); assertEquals(product.getId(), 1, 0); - } } From b9c81b0cedbcaa40ecb9978d3072a1f7939299ec Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sun, 17 Jan 2021 11:39:53 +0100 Subject: [PATCH 489/590] BAEL-4756 - Mockito MockSettings (#10423) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings Co-authored-by: Jonathan Cook --- .../mockito/mocksettings/AbstractCoffee.java | 15 +++++ .../mockito/mocksettings/SimpleService.java | 10 ++++ .../mocksettings/SpecialInterface.java | 5 ++ .../mocksettings/MockSettingsUnitTest.java | 56 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java new file mode 100644 index 0000000000..99fd686951 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java @@ -0,0 +1,15 @@ +package com.baeldung.mockito.mocksettings; + +public abstract class AbstractCoffee { + + protected String name; + + protected AbstractCoffee(String name) { + this.name = name; + } + + protected String getName() { + return name; + } + +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java new file mode 100644 index 0000000000..034517acbf --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java @@ -0,0 +1,10 @@ +package com.baeldung.mockito.mocksettings; + +public class SimpleService { + + public SimpleService(SpecialInterface special) { + Runnable runnable = (Runnable) special; + runnable.run(); + } + +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java new file mode 100644 index 0000000000..e5f88247d6 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java @@ -0,0 +1,5 @@ +package com.baeldung.mockito.mocksettings; + +public interface SpecialInterface { + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java new file mode 100644 index 0000000000..596baf1954 --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.mockito.mocksettings; + +import static org.mockito.Answers.RETURNS_SMART_NULLS; +import static org.junit.Assert.assertEquals; +import static org.mockito.Answers.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.exceptions.verification.SmartNullPointerException; +import org.mockito.junit.MockitoJUnitRunner; + +import com.baeldung.mockito.fluentapi.Pizza; +import com.baeldung.mockito.fluentapi.PizzaService; + +@RunWith(MockitoJUnitRunner.class) +public class MockSettingsUnitTest { + + @Test(expected = SmartNullPointerException.class) + public void whenServiceMockedWithSmartNulls_thenExceptionHasExtraInfo() { + PizzaService service = mock(PizzaService.class, withSettings().defaultAnswer(RETURNS_SMART_NULLS)); + Pizza pizza = service.orderHouseSpecial(); + pizza.getSize(); + } + + @Test + public void whenServiceMockedWithNameAndVerboseLogging_thenLogsMethodInvocations() { + PizzaService service = mock(PizzaService.class, withSettings().name("pizzaServiceMock") + .verboseLogging()); + + Pizza pizza = mock(Pizza.class); + when(service.orderHouseSpecial()).thenReturn(pizza); + + service.orderHouseSpecial(); + + verify(service).orderHouseSpecial(); + } + + @Test + public void whenServiceMockedWithExtraInterfaces_thenConstructorSuccess() { + SpecialInterface specialMock = mock(SpecialInterface.class, withSettings().extraInterfaces(Runnable.class)); + new SimpleService(specialMock); + } + + @Test + public void whenMockSetupWithConstructor_thenConstructorIsInvoked() { + AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("expresso") + .defaultAnswer(CALLS_REAL_METHODS)); + + assertEquals("Coffee name: ", "expresso", coffeeSpy.getName()); + } + +} From 1b127b9b00b1cb9bc25e606c2f74a107b3bb0d6b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 18 Jan 2021 12:55:30 -0300 Subject: [PATCH 490/590] removed Sprng Boot version override, upgraded cloud version and added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests --- spring-cloud/spring-cloud-config/client/pom.xml | 15 +++++++++++++-- spring-cloud/spring-cloud-config/pom.xml | 3 +-- spring-cloud/spring-cloud-config/server/pom.xml | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-config/client/pom.xml b/spring-cloud/spring-cloud-config/client/pom.xml index 805a50bfdb..2400520d2b 100644 --- a/spring-cloud/spring-cloud-config/client/pom.xml +++ b/spring-cloud/spring-cloud-config/client/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 client client @@ -26,6 +26,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + diff --git a/spring-cloud/spring-cloud-config/pom.xml b/spring-cloud/spring-cloud-config/pom.xml index 5db18a7245..bfe17044e0 100644 --- a/spring-cloud/spring-cloud-config/pom.xml +++ b/spring-cloud/spring-cloud-config/pom.xml @@ -33,8 +33,7 @@ - Hoxton.SR4 - 2.3.3.RELEASE + 2020.0.0 diff --git a/spring-cloud/spring-cloud-config/server/pom.xml b/spring-cloud/spring-cloud-config/server/pom.xml index e32a473cd6..f0f1e43612 100644 --- a/spring-cloud/spring-cloud-config/server/pom.xml +++ b/spring-cloud/spring-cloud-config/server/pom.xml @@ -1,11 +1,11 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 server server - + com.baeldung.spring.cloud spring-cloud-config @@ -30,6 +30,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + From b33fd1ee9c03cac4c3a5f919babc9728f2a38c2b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 18 Jan 2021 15:50:55 -0300 Subject: [PATCH 491/590] Added additional scenario to reflect scenario mentioned in spring-feature-flags (even though the article does not point to any module in the codebase) --- .../src/main/resources/application.properties | 4 ++++ .../src/main/resources/application.yml | 3 +++ .../IntegrationMultidocumentFilesIntegrationTest.java | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index c2bb5deb45..a079837942 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -11,6 +11,7 @@ app.name=MyApp app.description=${app.name} is a Spring Boot application logging.file.name=myapplication.log bael.property=defaultValue +bael.otherProperty=defaultOtherValue #--- spring.config.activate.on-profile=multidocument-dev spring.datasource.password=password @@ -18,6 +19,9 @@ spring.datasource.url=jdbc:h2:dev spring.datasource.username=SA bael.property=devValue #--- +spring.config.activate.on-profile=multidocument-integration-extension +bael.otherProperty=integrationExtensionOtherValue +#--- spring.config.activate.on-profile=multidocument-prod spring.datasource.password=password spring.datasource.url=jdbc:h2:prod diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index 33aabb2459..da398f5beb 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -2,6 +2,9 @@ bael: root-level-property: defaultRootLevelValue --- spring: + profiles: + group: + multidocument-integration: multidocument-integration-extension config: activate: on-profile: multidocument-staging diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java index f7968f51ad..e0727154d0 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java @@ -17,12 +17,16 @@ public class IntegrationMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + @Value("${bael.otherProperty}") + private String baelCustomOtherProperty; + @Value("${bael.root-level-property}") private String baelRootProperty; @Test public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("integrationValue"); + assertThat(baelCustomOtherProperty).isEqualTo("integrationExtensionOtherValue"); assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } From caadfb7a911bdba043de472d9c30843a57d0d781 Mon Sep 17 00:00:00 2001 From: Bruno Fontana Date: Tue, 19 Jan 2021 08:58:58 -0300 Subject: [PATCH 492/590] Adding clean-architecture to parent POM. Fixing UserResponseFormatter test name. --- ...seFormatterTests.java => UserResponseFormatterUnitTest.java} | 2 +- patterns/pom.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/{UserResponseFormatterTests.java => UserResponseFormatterUnitTest.java} (96%) diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java similarity index 96% rename from patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java rename to patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java index f8ebde5f10..e394cbbf94 100644 --- a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java @@ -9,7 +9,7 @@ import org.springframework.web.server.ResponseStatusException; import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseFormatter; import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseModel; -class UserResponseFormatterTests { +class UserResponseFormatterUnitTest { UserResponseFormatter userResponseFormatter = new UserResponseFormatter(); diff --git a/patterns/pom.xml b/patterns/pom.xml index a179d75ffe..112eecb606 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -24,6 +24,7 @@ hexagonal-architecture intercepting-filter solid + clean-architecture From 8f428d768807b78be053957082e053aacfe04b26 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 19 Jan 2021 12:22:02 -0300 Subject: [PATCH 493/590] fix extra test configuration properties error --- .../src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index da398f5beb..10570bb738 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -1,10 +1,11 @@ bael: root-level-property: defaultRootLevelValue ---- spring: profiles: group: multidocument-integration: multidocument-integration-extension +--- +spring: config: activate: on-profile: multidocument-staging From 42ca93dbbf17207d806cbcd2a9fc35429bfca406 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 19 Jan 2021 15:44:33 -0300 Subject: [PATCH 494/590] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests for spring-boot module --- spring-boot-modules/spring-boot/pom.xml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot/pom.xml b/spring-boot-modules/spring-boot/pom.xml index c1f1ea3072..9023ae92f3 100644 --- a/spring-boot-modules/spring-boot/pom.xml +++ b/spring-boot-modules/spring-boot/pom.xml @@ -1,7 +1,7 @@ + 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 @@ -58,6 +58,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + io.dropwizard.metrics From a41309f4c65af08cf0bd609388d2bb59810808f1 Mon Sep 17 00:00:00 2001 From: Mateusz Szablak 'Saber-k Date: Tue, 19 Jan 2021 21:40:10 +0100 Subject: [PATCH 495/590] [BAEL-4214] Converting java.util.Properties to HashMap --- .../core-java-collections-maps-3/pom.xml | 4 + .../PropertiesToHashMapConverter.java | 39 ++++ .../PropertiesToHashMapConverterUnitTest.java | 192 ++++++++++++++++++ .../src/test/resources/toHashMap.properties | 3 + 4 files changed, 238 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties diff --git a/core-java-modules/core-java-collections-maps-3/pom.xml b/core-java-modules/core-java-collections-maps-3/pom.xml index 577ad58255..2561f891f1 100644 --- a/core-java-modules/core-java-collections-maps-3/pom.xml +++ b/core-java-modules/core-java-collections-maps-3/pom.xml @@ -20,6 +20,10 @@ jmh-core ${jmh-core.version} + + com.google.guava + guava + diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java new file mode 100644 index 0000000000..2f333638a9 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java @@ -0,0 +1,39 @@ +package com.baeldung.map.propertieshashmap; + +import com.google.common.collect.Maps; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; + +public class PropertiesToHashMapConverter { + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static HashMap typeCastConvert(Properties prop) { + Map step1 = prop; + Map step2 = (Map) step1; + return new HashMap<>(step2); + } + + public static HashMap loopConvert(Properties prop) { + HashMap retMap = new HashMap<>(); + for (Map.Entry entry : prop.entrySet()) { + retMap.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); + } + return retMap; + } + + public static HashMap streamConvert(Properties prop) { + return prop.entrySet().stream().collect( + Collectors.toMap( + e -> String.valueOf(e.getKey()), + e -> String.valueOf(e.getValue()), + (prev, next) -> next, HashMap::new + )); + } + + public static HashMap guavaConvert(Properties prop) { + return Maps.newHashMap(Maps.fromProperties(prop)); + } +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java new file mode 100644 index 0000000000..b1370dcfbf --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java @@ -0,0 +1,192 @@ +package com.baeldung.map.propertieshashmap; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.*; + +class PropertiesToHashMapConverterUnitTest { + + private Properties properties; + + private final static String propertyFileName = "toHashMap.properties"; + + @BeforeEach + public void setup() throws IOException { + properties = new Properties(); + try (InputStream is = getClass().getClassLoader().getResourceAsStream(propertyFileName)) { + if (is != null) { + properties.load(is); + } + } + } + + @Test + public void havingPropertiesLoaded_whenCheck_thenEquals() { + assertEquals(3, properties.size()); + assertEquals("str_value", properties.get("property1")); + assertEquals("123", properties.get("property2")); + assertEquals("", properties.get("property3")); + } + + @Test + public void whenPropertiesModified_thenTypeSafeIssues() { + compromiseProperties(properties); + + assertEquals(5, properties.size()); + + assertNull(properties.getProperty("property4")); + assertNotEquals(String.class, properties.get("property4").getClass()); + assertEquals(456, properties.get("property4")); + + + assertNull(properties.getProperty("5")); + assertNotEquals(String.class, properties.get(5).getClass()); + assertEquals(10.11, properties.get(5)); + } + + @Test + public void havingNonModifiedProperties_whenTypeCastConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.typeCastConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenTypeCastConvert_thenClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.typeCastConvert(properties); + assertEquals(5, hMap.size()); + + assertThrows(ClassCastException.class, () -> { + String s = hMap.get("property4"); + }); + assertEquals(Integer.class, ((Object) hMap.get("property4")).getClass()); + + assertNull(hMap.get("5")); + assertNotNull(hMap.get(5)); + assertThrows(ClassCastException.class, () -> { + String s = hMap.get(5); + }); + assertEquals(Double.class, ((Object) hMap.get(5)).getClass()); + } + + @Test + public void havingNonModifiedProperties_whenLoopConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.loopConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenLoopConvert_thenNoClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.loopConvert(properties); + assertEquals(5, hMap.size()); + + assertDoesNotThrow(() -> { + String s = hMap.get("property4"); + }); + assertEquals(String.class, hMap.get("property4").getClass()); + assertEquals("456", hMap.get("property4")); + + assertDoesNotThrow(() -> { + String s = hMap.get("5"); + }); + assertEquals("10.11", hMap.get("5")); + } + + @Test + public void havingNonModifiedProperties_whenStreamConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.streamConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenStreamConvert_thenNoClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.streamConvert(properties); + assertEquals(5, hMap.size()); + + assertDoesNotThrow(() -> { + String s = hMap.get("property4"); + }); + assertEquals(String.class, hMap.get("property4").getClass()); + assertEquals("456", hMap.get("property4")); + + assertDoesNotThrow(() -> { + String s = hMap.get("5"); + }); + assertEquals("10.11", hMap.get("5")); + } + + @Test + public void havingModifiedProperties_whenLoopConvertAndStreamConvert_thenHashMapsSame() { + compromiseProperties(properties); + HashMap hMap1 = PropertiesToHashMapConverter.loopConvert(properties); + HashMap hMap2 = PropertiesToHashMapConverter.streamConvert(properties); + + assertEquals(hMap2, hMap1); + } + + @Test + public void havingNonModifiedProperties_whenGuavaConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.guavaConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenGuavaConvert_thenUnableToConvertAndThrowException() { + compromiseProperties(properties); + assertThrows(Exception.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + @Test + public void havingModifiedPropertiesWithNoIntegerValue_whenGuavaConvert_thenNullPointerException() { + properties.put("property4", 456); + assertThrows(NullPointerException.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + @Test + public void havingModifiedPropertiesWithNoIntegerKey_whenGuavaConvert_thenClassCastException() { + properties.put(5, 10.11); + assertThrows(ClassCastException.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + + private void compromiseProperties(Properties prop) { + prop.put("property4", 456); + prop.put(5, 10.11); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties b/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties new file mode 100644 index 0000000000..b731aa94bb --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties @@ -0,0 +1,3 @@ +property1=str_value +property2=123 +property3= \ No newline at end of file From 27c423c4e026c02395059c7a41e31782e514da73 Mon Sep 17 00:00:00 2001 From: Mateusz Szablak 'Saber-k Date: Tue, 19 Jan 2021 21:40:10 +0100 Subject: [PATCH 496/590] [BAEL-4214] Converting java.util.Properties to HashMap --- .../core-java-collections-maps-3/pom.xml | 4 + .../PropertiesToHashMapConverter.java | 39 ++++ .../PropertiesToHashMapConverterUnitTest.java | 192 ++++++++++++++++++ .../src/test/resources/toHashMap.properties | 3 + 4 files changed, 238 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties diff --git a/core-java-modules/core-java-collections-maps-3/pom.xml b/core-java-modules/core-java-collections-maps-3/pom.xml index 577ad58255..2561f891f1 100644 --- a/core-java-modules/core-java-collections-maps-3/pom.xml +++ b/core-java-modules/core-java-collections-maps-3/pom.xml @@ -20,6 +20,10 @@ jmh-core ${jmh-core.version} + + com.google.guava + guava + diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java new file mode 100644 index 0000000000..2f333638a9 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java @@ -0,0 +1,39 @@ +package com.baeldung.map.propertieshashmap; + +import com.google.common.collect.Maps; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; + +public class PropertiesToHashMapConverter { + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static HashMap typeCastConvert(Properties prop) { + Map step1 = prop; + Map step2 = (Map) step1; + return new HashMap<>(step2); + } + + public static HashMap loopConvert(Properties prop) { + HashMap retMap = new HashMap<>(); + for (Map.Entry entry : prop.entrySet()) { + retMap.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); + } + return retMap; + } + + public static HashMap streamConvert(Properties prop) { + return prop.entrySet().stream().collect( + Collectors.toMap( + e -> String.valueOf(e.getKey()), + e -> String.valueOf(e.getValue()), + (prev, next) -> next, HashMap::new + )); + } + + public static HashMap guavaConvert(Properties prop) { + return Maps.newHashMap(Maps.fromProperties(prop)); + } +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java new file mode 100644 index 0000000000..1985fbe673 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverterUnitTest.java @@ -0,0 +1,192 @@ +package com.baeldung.map.propertieshashmap; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.*; + +class PropertiesToHashMapConverterUnitTest { + + private Properties properties; + + private final static String propertyFileName = "toHashMap.properties"; + + @BeforeEach + public void setup() throws IOException { + properties = new Properties(); + try (InputStream is = getClass().getClassLoader().getResourceAsStream(propertyFileName)) { + if (is != null) { + properties.load(is); + } + } + } + + @Test + public void havingPropertiesLoaded_whenCheck_thenEquals() { + assertEquals(3, properties.size()); + assertEquals("str_value", properties.get("property1")); + assertEquals("123", properties.get("property2")); + assertEquals("", properties.get("property3")); + } + + @Test + public void whenPropertiesModified_thenTypeSafeIssues() { + compromiseProperties(properties); + + assertEquals(5, properties.size()); + + assertNull(properties.getProperty("property4")); + assertNotEquals(String.class, properties.get("property4").getClass()); + assertEquals(456, properties.get("property4")); + + + assertNull(properties.getProperty("5")); + assertNotEquals(String.class, properties.get(5).getClass()); + assertEquals(10.11, properties.get(5)); + } + + @Test + public void havingNonModifiedProperties_whenTypeCastConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.typeCastConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenTypeCastConvert_thenClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.typeCastConvert(properties); + assertEquals(5, hMap.size()); + + assertThrows(ClassCastException.class, () -> { + String s = hMap.get("property4"); + }); + assertEquals(Integer.class, ((Object) hMap.get("property4")).getClass()); + + assertNull(hMap.get("5")); + assertNotNull(hMap.get(5)); + assertThrows(ClassCastException.class, () -> { + String s = hMap.get(5); + }); + assertEquals(Double.class, ((Object) hMap.get(5)).getClass()); + } + + @Test + public void havingNonModifiedProperties_whenLoopConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.loopConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenLoopConvert_thenNoClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.loopConvert(properties); + assertEquals(5, hMap.size()); + + assertDoesNotThrow(() -> { + String s = hMap.get("property4"); + }); + assertEquals(String.class, hMap.get("property4").getClass()); + assertEquals("456", hMap.get("property4")); + + assertDoesNotThrow(() -> { + String s = hMap.get("5"); + }); + assertEquals("10.11", hMap.get("5")); + } + + @Test + public void havingNonModifiedProperties_whenStreamConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.streamConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenStreamConvert_thenNoClassCastException() { + compromiseProperties(properties); + HashMap hMap = PropertiesToHashMapConverter.streamConvert(properties); + assertEquals(5, hMap.size()); + + assertDoesNotThrow(() -> { + String s = hMap.get("property4"); + }); + assertEquals(String.class, hMap.get("property4").getClass()); + assertEquals("456", hMap.get("property4")); + + assertDoesNotThrow(() -> { + String s = hMap.get("5"); + }); + assertEquals("10.11", hMap.get("5")); + } + + @Test + public void havingModifiedProperties_whenLoopConvertAndStreamConvert_thenHashMapsSame() { + compromiseProperties(properties); + HashMap hMap1 = PropertiesToHashMapConverter.loopConvert(properties); + HashMap hMap2 = PropertiesToHashMapConverter.streamConvert(properties); + + assertEquals(hMap2, hMap1); + } + + @Test + public void havingNonModifiedProperties_whenGuavaConvert_thenNoTypeSafeIssues() { + HashMap hMap = PropertiesToHashMapConverter.guavaConvert(properties); + + assertEquals(3, hMap.size()); + assertEquals(String.class, hMap.get("property1").getClass()); + assertEquals(properties.get("property1"), hMap.get("property1")); + assertEquals(String.class, hMap.get("property2").getClass()); + assertEquals(properties.get("property2"), hMap.get("property2")); + assertEquals(String.class, hMap.get("property3").getClass()); + assertEquals(properties.get("property3"), hMap.get("property3")); + } + + @Test + public void havingModifiedProperties_whenGuavaConvert_thenUnableToConvertAndThrowException() { + compromiseProperties(properties); + assertThrows(Exception.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + @Test + public void havingModifiedPropertiesWithNoIntegerValue_whenGuavaConvert_thenNullPointerException() { + properties.put("property4", 456); + assertThrows(NullPointerException.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + @Test + public void havingModifiedPropertiesWithNoIntegerKey_whenGuavaConvert_thenClassCastException() { + properties.put(5, 10.11); + assertThrows(ClassCastException.class, () -> PropertiesToHashMapConverter.guavaConvert(properties)); + } + + + private void compromiseProperties(Properties prop) { + prop.put("property4", 456); + prop.put(5, 10.11); + } +} diff --git a/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties b/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties new file mode 100644 index 0000000000..727e858a8c --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/resources/toHashMap.properties @@ -0,0 +1,3 @@ +property1=str_value +property2=123 +property3= From d3156e1034f14b96336a76ff52e72b4852cf44f4 Mon Sep 17 00:00:00 2001 From: MeenaGawande Date: Wed, 20 Jan 2021 11:29:38 +0530 Subject: [PATCH 497/590] [BAEL-4715] Java HashMap Load Factor [BAEL-4715] Java HashMap Load Factor --- .../loadfactor/HashMapLoadFactorUnitTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java new file mode 100644 index 0000000000..89e2a189fe --- /dev/null +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.map.hashmap.loadfactor; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +public class HashMapLoadFactorUnitTest { + + @Test + public void whenCreateMapWithDefaultParam_thenSucces() { + Map mapWithDefaultParams = new HashMap(); + mapWithDefaultParams.put("1", "One"); + mapWithDefaultParams.put("2", "two"); + mapWithDefaultParams.put("3", "three"); + mapWithDefaultParams.put("4", "four"); + mapWithDefaultParams.put("5", "five"); + + Assert.assertEquals(5, mapWithDefaultParams.size()); + } + + @Test + public void whenCreateMapWithInitialCapacity_thenSucces() { + Map mapWithInitialCapacity = new HashMap(5); + mapWithInitialCapacity.put("1", "One"); + mapWithInitialCapacity.put("2", "two"); + mapWithInitialCapacity.put("3", "three"); + + Assert.assertEquals(3, mapWithInitialCapacity.size()); + } + + @Test + public void whenCreateMapWithInitialCapacityAndLF_thenSucces() { + Map mapWithInitialCapacityAndLF = new HashMap(5, 0.5f); + mapWithInitialCapacityAndLF.put("1", "one"); + mapWithInitialCapacityAndLF.put("2", "two"); + mapWithInitialCapacityAndLF.put("3", "three"); + mapWithInitialCapacityAndLF.put("4", "four"); + mapWithInitialCapacityAndLF.put("5", "five"); + mapWithInitialCapacityAndLF.put("6", "six"); + mapWithInitialCapacityAndLF.put("7", "seven"); + mapWithInitialCapacityAndLF.put("8", "eight"); + mapWithInitialCapacityAndLF.put("9", "nine"); + mapWithInitialCapacityAndLF.put("10", "ten"); + + Assert.assertEquals(10, mapWithInitialCapacityAndLF.size()); + } +} From 98cce29a737a390516a024404dab9ea8a7e9ca32 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:39:59 +0800 Subject: [PATCH 498/590] Update README.md --- java-collections-maps-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-collections-maps-3/README.md b/java-collections-maps-3/README.md index 4da8547824..39ac8575fa 100644 --- a/java-collections-maps-3/README.md +++ b/java-collections-maps-3/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Java Map With Case-Insensitive Keys](https://www.baeldung.com/java-map-with-case-insensitive-keys) +- [Using a Byte Array as Map Key in Java](https://www.baeldung.com/java-map-key-byte-array) From 1e16299ac522244bccbb84557c612ed8d316dbef Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:42:24 +0800 Subject: [PATCH 499/590] Update README.md --- java-numbers-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-4/README.md b/java-numbers-4/README.md index 7db25b283c..cdd53692e0 100644 --- a/java-numbers-4/README.md +++ b/java-numbers-4/README.md @@ -2,3 +2,4 @@ - [Probability in Java](https://www.baeldung.com/java-probability) - [Understanding the & 0xff Value in Java](https://www.baeldung.com/java-and-0xff) +- [Determine if an Integer’s Square Root Is an Integer in Java](https://www.baeldung.com/java-find-if-square-root-is-integer) From 093fb533fa14d317f95b9a966442132d8d0b4378 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:44:10 +0800 Subject: [PATCH 500/590] Update README.md --- core-java-modules/core-java-lang-math-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md index 9eee021f8f..dda3013407 100644 --- a/core-java-modules/core-java-lang-math-3/README.md +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -5,4 +5,5 @@ ### Relevant articles: - [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) +- [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) From f7f017037f4f0a7be3583721d9f171b0b0b33a27 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:46:34 +0800 Subject: [PATCH 501/590] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index 1949207364..9c9e040825 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -9,3 +9,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [Defining Indexes in JPA](https://www.baeldung.com/jpa-indexes) - [JPA CascadeType.REMOVE vs orphanRemoval](https://www.baeldung.com/jpa-cascade-remove-vs-orphanremoval) - [A Guide to MultipleBagFetchException in Hibernate](https://www.baeldung.com/java-hibernate-multiplebagfetchexception) +- [How to Convert a Hibernate Proxy to a Real Entity Object](https://www.baeldung.com/hibernate-proxy-to-real-entity-object) From c3f92c8b3846e571ff3ded44692fd8fb1b5b0cb7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:50:15 +0800 Subject: [PATCH 502/590] Create README.md --- patterns/clean-architecture/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 patterns/clean-architecture/README.md diff --git a/patterns/clean-architecture/README.md b/patterns/clean-architecture/README.md new file mode 100644 index 0000000000..aad8608447 --- /dev/null +++ b/patterns/clean-architecture/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Clean Architecture with Spring Boot](https://www.baeldung.com/spring-boot-clean-architecture) From 59e4bd98114616735188ffcb3171bcecb8c8e4be Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 20 Jan 2021 12:37:10 -0300 Subject: [PATCH 503/590] updated deprecation: HandlerInterceptorAdapter class -> HandlerInterceptor interface --- .../baeldung/loginredirect/LoginPageInterceptor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java index aa93201f37..f08b824369 100644 --- a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java +++ b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java @@ -1,16 +1,16 @@ package com.baeldung.loginredirect; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.http.HttpStatus; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.util.UrlPathHelper; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -class LoginPageInterceptor extends HandlerInterceptorAdapter { +class LoginPageInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { From c5a57eb06572f3baa619eea20ae666d96a7d3b69 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:31:35 +0530 Subject: [PATCH 504/590] JAVA-4012: Moved 1 article to spring-boot-persistence-mongodb --- .../src/main/resources/mongoConfig.xml | 31 ++++++++++++++++++ .../src/main/resources/test.png | Bin .../com/baeldung/gridfs/GridFSLiveTest.java | 0 .../src/main/resources/mongoConfig.xml | 5 --- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml rename persistence-modules/{spring-data-mongodb => spring-boot-persistence-mongodb}/src/main/resources/test.png (100%) rename persistence-modules/{spring-data-mongodb => spring-boot-persistence-mongodb}/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java (100%) diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml new file mode 100644 index 0000000000..c5b9068de3 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-mongodb/src/main/resources/test.png b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/test.png similarity index 100% rename from persistence-modules/spring-data-mongodb/src/main/resources/test.png rename to persistence-modules/spring-boot-persistence-mongodb/src/main/resources/test.png diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java similarity index 100% rename from persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java rename to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java diff --git a/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml b/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml index 074a203b1a..5067bec78e 100644 --- a/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml +++ b/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml @@ -14,11 +14,6 @@ - - - - - From 52c492f679220b77ec0488da155e766b40b165e1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:32:54 +0530 Subject: [PATCH 505/590] JAVA-4012: README changes --- persistence-modules/spring-boot-persistence-mongodb/README.md | 1 + persistence-modules/spring-data-mongodb/README.md | 2 -- persistence-modules/spring-jpa/README.md | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-mongodb/README.md b/persistence-modules/spring-boot-persistence-mongodb/README.md index f277ef66ca..aade8eb1c0 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/README.md +++ b/persistence-modules/spring-boot-persistence-mongodb/README.md @@ -3,3 +3,4 @@ - [Auto-Generated Field for MongoDB using Spring Boot](https://www.baeldung.com/spring-boot-mongodb-auto-generated-field) - [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb) - [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file) +- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index 381bf83fa8..0be8c57036 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -7,10 +7,8 @@ - [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) - [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) -- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) - [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) -- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) - [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index f60609e0de..937890cd13 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -7,6 +7,7 @@ - [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database) - [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source) - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - More articles: [[next -->]](/spring-jpa-2) ### Eclipse Config From a679b1997864a78543c1fdc4522a3743f0b448f1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:39:36 +0530 Subject: [PATCH 506/590] JAVA-4012: removed entry for article --- persistence-modules/spring-data-jpa-annotations/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-annotations/README.md b/persistence-modules/spring-data-jpa-annotations/README.md index 5f1c8dbc27..1ee579cf6c 100644 --- a/persistence-modules/spring-data-jpa-annotations/README.md +++ b/persistence-modules/spring-data-jpa-annotations/README.md @@ -4,7 +4,6 @@ This module contains articles about annotations used in Spring Data JPA ### Relevant articles -- [Spring Data Annotations](https://www.baeldung.com/spring-data-annotations) - [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) - [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable) - [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) From 5b1e5979782cbf0d6b468adcb01ef370df43a09a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 11:47:41 -0300 Subject: [PATCH 507/590] Updated deprecated BodyInserters.fromObject method, in favor of BodyInserters.fromValue --- .../com/baeldung/web/reactive/client/WebClientController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index a719259328..09134701e9 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -38,7 +38,7 @@ public class WebClientController { // request header specification WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromObject("data")); + WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); // inserters BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters @@ -49,7 +49,7 @@ public class WebClientController { map.add("key2", "value2"); // BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromObject("body"); + BodyInserter inserter3 = BodyInserters.fromValue("body"); // responses WebClient.ResponseSpec response1 = uri1.body(inserter3) From 14506a542df37ff132f307a35eeb91dfeba7dd66 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 11:50:55 -0300 Subject: [PATCH 508/590] removed unused reactor-spring version property --- spring-5-reactive/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 3b7383f726..60c8b90e16 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -149,7 +149,6 @@ - 1.0.1.RELEASE 1.1.3 1.0 1.0 From 52d458c05f5c1dd2eec3bb6aca1b2b0f9d362de7 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 12:43:26 -0300 Subject: [PATCH 509/590] formatted WebClientController class --- .../reactive/client/WebClientController.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 09134701e9..7c0dc1cff7 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -1,8 +1,17 @@ package com.baeldung.web.reactive.client; +import java.net.URI; +import java.nio.charset.Charset; +import java.time.ZonedDateTime; +import java.util.Collections; + import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; -import org.springframework.http.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -10,12 +19,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; -import java.net.URI; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.Collections; +import reactor.core.publisher.Mono; @RestController public class WebClientController { @@ -41,8 +46,7 @@ public class WebClientController { WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters - .fromPublisher(Subscriber::onComplete, String.class); + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "value1"); From dd60782928c438d33d05c07889eba964c3f62318 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 12:44:06 -0300 Subject: [PATCH 510/590] Added timeout WebClient configuration, as in article --- .../reactive/client/WebClientController.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 7c0dc1cff7..3132a4173d 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,6 +4,7 @@ import java.net.URI; import java.nio.charset.Charset; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; @@ -12,6 +13,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -20,7 +22,12 @@ import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import io.netty.channel.ChannelOption; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClient; +import reactor.netty.tcp.TcpClient; @RestController public class WebClientController { @@ -75,6 +82,19 @@ public class WebClientController { return WebClient.create("http://localhost:8081"); } + private WebClient createWebClientConfiguringTimeout() { + TcpClient tcpClient = TcpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) + .doOnConnected(connection -> { + connection.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)); + connection.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)); + }); + + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient))) + .build(); + } + private WebClient createWebClientWithServerURLAndDefaultValues() { return WebClient.builder() .baseUrl("http://localhost:8081") From 1f7e0f06b6d8286f8a053ad38a385ef41bd55bec Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 14:25:30 -0300 Subject: [PATCH 511/590] updated timeout logic due to deprecation --- .../web/reactive/client/WebClientController.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 3132a4173d..66f787eda3 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -27,7 +27,6 @@ import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; -import reactor.netty.tcp.TcpClient; @RestController public class WebClientController { @@ -83,15 +82,13 @@ public class WebClientController { } private WebClient createWebClientConfiguringTimeout() { - TcpClient tcpClient = TcpClient.create() + HttpClient httpClient = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(connection -> { - connection.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)); - connection.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)); - }); + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient))) + .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); } From e6ab521b6127a9949515da3ad47aac66e8963cf9 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 14:57:06 -0300 Subject: [PATCH 512/590] added LinkedMultiValueMap usage for inserter declaration, as in article --- .../com/baeldung/web/reactive/client/WebClientController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 66f787eda3..34de13bc28 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -13,8 +13,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -58,7 +60,7 @@ public class WebClientController { map.add("key1", "value1"); map.add("key2", "value2"); - // BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); + BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); BodyInserter inserter3 = BodyInserters.fromValue("body"); // responses From d90c7fed48fd86207471f821305ec8bbc109df54 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Fri, 22 Jan 2021 08:53:02 +0100 Subject: [PATCH 513/590] =?UTF-8?q?BAEL-4644:=20Small=20test=20to=20check?= =?UTF-8?q?=20Java=20JIT=20compiler=20performances=20vs=20C++=20=E2=80=A6?= =?UTF-8?q?=20(#10412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-4644: Small test to check Java JIT compiler performances vs C++ and JS * BAEL-4644: Remove CSV with performance test results * Revert "BAEL-4644: Remove CSV with performance test results" This reverts commit a69c9667 --- .../src/main/external/Fibonacci.cpp | 19 ++++ .../src/main/external/Fibonacci.js | 14 +++ .../performancetests/jit/Fibonacci.java | 20 ++++ .../FibonacciPerformancesResults.csv | 103 ++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 performance-tests/src/main/external/Fibonacci.cpp create mode 100644 performance-tests/src/main/external/Fibonacci.js create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java create mode 100644 performance-tests/src/main/resources/FibonacciPerformancesResults.csv diff --git a/performance-tests/src/main/external/Fibonacci.cpp b/performance-tests/src/main/external/Fibonacci.cpp new file mode 100644 index 0000000000..d23603c2ea --- /dev/null +++ b/performance-tests/src/main/external/Fibonacci.cpp @@ -0,0 +1,19 @@ +#include +#include + +using namespace std; + +int fibonacci(int n) { + if (n <= 1) + return n; + return fibonacci(n - 1) + fibonacci(n - 2); +} + +int main() { + for (int i = 0; i < 100; i++) { + auto startTime = chrono::high_resolution_clock::now().time_since_epoch(); + int result = fibonacci(12); + auto totalTime = chrono::high_resolution_clock::now().time_since_epoch() - startTime; + cout << totalTime << "\n"; + } +} \ No newline at end of file diff --git a/performance-tests/src/main/external/Fibonacci.js b/performance-tests/src/main/external/Fibonacci.js new file mode 100644 index 0000000000..ba41bf3ab9 --- /dev/null +++ b/performance-tests/src/main/external/Fibonacci.js @@ -0,0 +1,14 @@ +function fibonacci(index) { + if (index <= 1) + return index; + return fibonacci(index-1) + fibonacci(index-2); +} + +for (var i=0; i<100; i++) { + var startTime = process.hrtime.bigint(); + var result = fibonacci(12); + var totalTime = process.hrtime.bigint() - startTime; + console.log(totalTime); +} + + \ No newline at end of file diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java b/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java new file mode 100644 index 0000000000..c980093128 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java @@ -0,0 +1,20 @@ +package com.baeldung.performancetests.jit; + +public class Fibonacci { + + public static void main(String[] args) { + for (int i=0; i<100; i++) { + long startTime = System.nanoTime(); + int result = fibonacci(12); + long totalTime = System.nanoTime() - startTime; + System.out.println(totalTime); + } + } + + private static int fibonacci(int index) { + if (index <= 1) + return index; + return fibonacci(index-1) + fibonacci(index-2); + } + +} diff --git a/performance-tests/src/main/resources/FibonacciPerformancesResults.csv b/performance-tests/src/main/resources/FibonacciPerformancesResults.csv new file mode 100644 index 0000000000..01a1f3dd90 --- /dev/null +++ b/performance-tests/src/main/resources/FibonacciPerformancesResults.csv @@ -0,0 +1,103 @@ +Runs;Java using JIT;Java without JIT;C++ without O2;C++ with O2;JavaScript +1;21900;10572;8684;2643;35115 +2;60790;10572;8306;2643;20389 +3;1888;24543;7551;2265;20390 +4;4153;25675;8307;2265;19256 +5;1888;26053;8307;2265;19257 +6;5664;25675;8307;1887;35115 +7;1510;25676;29829;2266;20012 +8;1510;26053;7929;2643;35493 +9;1511;23787;7929;1888;40023 +10;3776;26431;26053;3776;20012 +11;1510;25676;7929;2265;35115 +12;1510;10195;7552;3775;19256 +13;17746;10572;7552;1888;40024 +14;26431;10194;7552;2265;19257 +15;1133;10195;8685;2265;18501 +16;1133;10572;7929;2265;18879 +17;1133;10572;7929;1888;53995 +18;756;10195;7929;1888;35115 +19;1133;10195;7930;2266;19634 +20;756;10573;7552;2266;37003 +21;1133;9817;7552;1888;35115 +22;1133;10194;7930;2266;32472 +23;1133;10195;7929;2266;18879 +24;755;10195;8307;3776;19257 +25;755;10195;7551;1888;34738 +26;1510;10194;7551;2265;18501 +27;3776;10194;7929;2266;33227 +28;1888;37758;9440;1888;19634 +29;1133;10573;8306;1888;32472 +30;1133;26430;7929;2265;32849 +31;1133;24165;8306;4153;32850 +32;755;24166;7929;2643;18879 +33;1133;10572;24920;4153;32850 +34;755;23788;10194;2643;19257 +35;756;23788;12837;4154;18501 +36;755;11328;8307;2643;33227 +37;1132;29829;8307;7174;1000211 +38;755;36625;8307;4531;39646 +39;1133;10950;7929;2643;34360 +40;1133;10950;7929;4531;3021 +41;1133;10573;7929;2643;2643 +42;755;29829;15104;2643;2643 +43;755;29829;13971;2643;3398 +44;1133;10950;8685;5664;3021 +45;1133;10950;9817;3020;3398 +46;1133;10950;8684;3776;3020 +47;1888;30962;7930;3020;3021 +48;1132;10950;8307;2643;3399 +49;1133;29451;7929;2265;2266 +50;1133;29452;8307;23033;2265 +51;755;10950;7929;2643;2266 +52;755;10950;7930;2643;2643 +53;755;11327;7929;4908;2265 +54;755;11328;7929;2265;2643 +55;1133;10572;7929;18879;16236 +56;756;36248;7929;2643;2643 +57;755;10572;7929;2265;2643 +58;755;10950;9818;2644;2643 +59;1132;10950;7929;2266;2643 +60;20012;30206;7929;2266;3021 +61;1133;30206;7929;2266;16613 +62;1511;30206;7552;2266;2643 +63;3021;30207;8307;1888;2643 +64;1510;10950;7929;1888;2266 +65;1510;30207;7929;2266;2644 +66;1888;30207;8307;2265;2643 +67;1511;29829;7929;2266;2643 +68;1888;10950;7930;2265;2266 +69;1510;29829;7929;21145;3020 +70;1511;29829;7929;1888;16613 +71;1510;30206;7929;2643;2265 +72;1510;10950;7929;2266;2644 +73;1888;10573;24921;18124;2266 +74;1888;10573;9062;6797;2644 +75;1888;10950;7929;2265;2643 +76;1133;10950;7929;2266;2644 +77;1133;29829;12460;2266;3020 +78;755;11328;8307;2643;2266 +79;755;11327;8684;2266;2643 +80;1133;30206;8307;2266;2643 +81;1133;29829;7929;2266;2266 +82;1888;30206;7929;2266;16236 +83;1510;11327;8307;2266;16613 +84;1888;11327;7929;2265;2643 +85;1133;10573;8307;6042;2266 +86;1133;10950;7929;2643;2266 +87;1133;10950;9817;2265;2265 +88;755;10950;24165;2643;2643 +89;755;11328;7929;3399;2643 +90;755;10950;8307;4909;3020 +91;755;10572;7552;23787;3020 +92;1133;10572;7929;2643;3021 +93;1132;10572;8307;2643;2643 +94;1132;10950;7551;2266;3398 +95;755;10950;23788;2265;2644 +96;755;10573;7551;1888;2265 +97;755;29829;12460;2266;2643 +98;1132;30207;7929;2266;2265 +99;1133;30206;7929;2265;2266 +100;755;10572;7929;2265;2643 +;;;;; +;;;;; From 10318d1145c2d2a87ec3e5d718aa8122c2609a9a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 10:29:15 -0300 Subject: [PATCH 514/590] updated inserter3 as in article --- .../com/baeldung/web/reactive/client/WebClientController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 34de13bc28..70919d8a2e 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -61,7 +61,8 @@ public class WebClientController { map.add("key2", "value2"); BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue("body"); + BodyInserter inserter3 = BodyInserters.fromValue(new Object()); + BodyInserter inserter4 = BodyInserters.fromValue("body"); // responses WebClient.ResponseSpec response1 = uri1.body(inserter3) From 814369e38cf68f9e3ff428c92bca3f044520bcf2 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 10:49:47 -0300 Subject: [PATCH 515/590] added exchange and retrieve examples as in teh article, updated due to deprecation --- .../baeldung/web/reactive/client/WebClientController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 70919d8a2e..de4f20a13f 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -72,8 +72,12 @@ public class WebClientController { .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()) .retrieve(); - WebClient.ResponseSpec response2 = requestSpec2.retrieve(); - + String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + String response3 = uri2.retrieve() + .bodyToMono(String.class) + .block(); + WebClient.ResponseSpec response4 = requestSpec2.retrieve(); } private WebClient createWebClient() { From 1b78d4be310efbb6dbaacac028b2e14305738e60 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 12:33:54 -0300 Subject: [PATCH 516/590] fixed and improved WebClient integration test --- .../reactive/client/WebClientApplication.java | 13 +++++ .../reactive/client/WebClientController.java | 7 ++- .../client/WebTestClientIntegrationTest.java | 54 ++++++++++++++++--- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java new file mode 100644 index 0000000000..f104ad30f1 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.web.reactive.client; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebClientApplication{ + + public static void main(String[] args) { + SpringApplication.run(WebClientApplication.class, args); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index de4f20a13f..2d42e848b2 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,6 +4,8 @@ import java.net.URI; import java.nio.charset.Charset; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; @@ -35,7 +37,10 @@ public class WebClientController { @ResponseStatus(HttpStatus.OK) @GetMapping("/resource") - public void getResource() { + public Map getResource() { + Map response = new HashMap<>(); + response.put("field", "value"); + return response; } public void demonstrateWebClient() { diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java index 2e37f2ffbd..07a4c81c91 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java @@ -1,11 +1,11 @@ package com.baeldung.web.client; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ApplicationContext; import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; @@ -13,18 +13,23 @@ import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.WebHandler; -import com.baeldung.reactive.Spring5ReactiveApplication; +import com.baeldung.web.reactive.client.WebClientApplication; +import com.baeldung.web.reactive.client.WebClientController; import reactor.core.publisher.Mono; -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5ReactiveApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@WithMockUser +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class WebTestClientIntegrationTest { @LocalServerPort private int port; + @Autowired + private ApplicationContext context; + + @Autowired + private WebClientController controller; + private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(RequestPredicates.GET("/resource"), request -> ServerResponse.ok() .build()); private final WebHandler WEB_HANDLER = exchange -> Mono.empty(); @@ -49,6 +54,7 @@ public class WebTestClientIntegrationTest { } @Test + @WithMockUser public void testWebTestClientWithServerURL() { WebTestClient.bindToServer() .baseUrl("http://localhost:" + port) @@ -58,7 +64,39 @@ public class WebTestClientIntegrationTest { .exchange() .expectStatus() .isOk() - .expectBody(); + .expectBody() + .jsonPath("field") + .isEqualTo("value"); + ; + } + + @Test + @WithMockUser + public void testWebTestClientWithApplicationContext() { + WebTestClient.bindToApplicationContext(context) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .jsonPath("field") + .isEqualTo("value"); + } + + @Test + public void testWebTestClientWithController() { + WebTestClient.bindToController(controller) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .jsonPath("field") + .isEqualTo("value"); } } From 30f0c13ef637377122af55df319774d31c66ce53 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 12:48:34 -0300 Subject: [PATCH 517/590] added context test for new WebClientApplication --- .../com/baeldung/web/client/SpringContextTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java new file mode 100644 index 0000000000..8d2ca41451 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java @@ -0,0 +1,14 @@ +package com.baeldung.web.client; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import com.baeldung.web.reactive.client.WebClientApplication; + +@SpringBootTest(classes = WebClientApplication.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} From 0c5441380750ef523d88d39469af1102d4e2d711 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Fri, 22 Jan 2021 19:56:18 +0100 Subject: [PATCH 518/590] BAEL-2517 --- .../core-java-lang-oop-generics/pom.xml | 28 ++++++++++++ .../UncheckedConversion.java | 45 +++++++++++++++++++ .../UncheckedConversionUnitTest.java | 39 ++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java create mode 100644 core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-generics/pom.xml b/core-java-modules/core-java-lang-oop-generics/pom.xml index 65a0aeac59..1a538edac9 100644 --- a/core-java-modules/core-java-lang-oop-generics/pom.xml +++ b/core-java-modules/core-java-lang-oop-generics/pom.xml @@ -13,4 +13,32 @@ core-java-lang-oop-generics jar + + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java b/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java new file mode 100644 index 0000000000..9ad4a92077 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java @@ -0,0 +1,45 @@ +package com.baeldung.uncheckedconversion; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +public class UncheckedConversion { + public static List getRawList() { + List result = new ArrayList(); + result.add("I am the 1st String."); + result.add("I am the 2nd String."); + result.add("I am the 3rd String."); + return result; + } + + public static List getRawListWithMixedTypes() { + List result = new ArrayList(); + result.add("I am the 1st String."); + result.add("I am the 2nd String."); + result.add("I am the 3rd String."); + result.add(new Date()); + return result; + } + + public static List castList(Class clazz, Collection rawCollection) { + List result = new ArrayList<>(rawCollection.size()); + for (Object o : rawCollection) { + try { + result.add(clazz.cast(o)); + } catch (ClassCastException e) { + // log the exception or other error handling + } + } + return result; + } + + public static List castList2(Class clazz, Collection rawCollection) throws ClassCastException { + List result = new ArrayList<>(rawCollection.size()); + for (Object o : rawCollection) { + result.add(clazz.cast(o)); + } + return result; + } +} diff --git a/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java b/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java new file mode 100644 index 0000000000..37b9a878d3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.uncheckedconversion; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class UncheckedConversionUnitTest { + + @Test + public void givenRawList_whenAssignToTypedList_shouldHaveCompilerWarning() { + List fromRawList = UncheckedConversion.getRawList(); + Assert.assertEquals(3, fromRawList.size()); + Assert.assertEquals("I am the 1st String.", fromRawList.get(0)); + } + + @Test(expected = ClassCastException.class) + public void givenRawList_whenListHasMixedType_shouldThrowClassCastException() { + List fromRawList = UncheckedConversion.getRawListWithMixedTypes(); + Assert.assertEquals(4, fromRawList.size()); + Assert.assertFalse(fromRawList.get(3).endsWith("String.")); + } + + @Test + public void givenRawList_whenAssignToTypedListAfterCallingCastList_shouldOnlyHaveElementsWithExpectedType() { + List rawList = UncheckedConversion.getRawListWithMixedTypes(); + List strList = UncheckedConversion.castList(String.class, rawList); + Assert.assertEquals(4, rawList.size()); + Assert.assertEquals("One element with the wrong type has been filtered out.", 3, strList.size()); + Assert.assertTrue(strList.stream().allMatch(el -> el.endsWith("String."))); + } + + @Test(expected = ClassCastException.class) + public void givenRawListWithWrongType_whenAssignToTypedListAfterCallingCastList2_shouldThrowException() { + List rawList = UncheckedConversion.getRawListWithMixedTypes(); + UncheckedConversion.castList2(String.class, rawList); + } + +} From 9144660a72defa218e1d0fbc64c98a592c323b28 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sat, 23 Jan 2021 07:08:50 +0100 Subject: [PATCH 519/590] BAEL-4756 - Mockito MockSettings - fix spelling (#10438) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings * BAEL-4756 - Mockito MockSettings - fix spelling Co-authored-by: Jonathan Cook --- .../baeldung/mockito/mocksettings/MockSettingsUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java index 596baf1954..907abc3d76 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java @@ -47,10 +47,10 @@ public class MockSettingsUnitTest { @Test public void whenMockSetupWithConstructor_thenConstructorIsInvoked() { - AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("expresso") + AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("espresso") .defaultAnswer(CALLS_REAL_METHODS)); - assertEquals("Coffee name: ", "expresso", coffeeSpy.getName()); + assertEquals("Coffee name: ", "espresso", coffeeSpy.getName()); } } From 70a0e0de969efdcb8da019e01a1ca122b47cb6e1 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 11:19:30 +0000 Subject: [PATCH 520/590] BAEL-4748 change user to reader and address to favouriteBooks --- .../webclient/json/ReaderConsumerService.java | 16 ++++ .../json/ReaderConsumerServiceImpl.java | 90 +++++++++++++++++++ .../webclient/json/UserConsumerService.java | 16 ---- .../json/UserConsumerServiceImpl.java | 90 ------------------- .../webclient/json/model/Address.java | 29 ------ .../baeldung/webclient/json/model/Book.java | 22 +++++ .../baeldung/webclient/json/model/Reader.java | 0 .../baeldung/webclient/json/model/User.java | 30 ------- .../ReaderConsumerServiceImplUnitTest.java | 77 ++++++++++++++++ .../json/UserConsumerServiceImplUnitTest.java | 74 --------------- 10 files changed, 205 insertions(+), 239 deletions(-) create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java delete mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java new file mode 100644 index 0000000000..b0bc71d2ed --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java @@ -0,0 +1,16 @@ +package com.baeldung.webclient.json; + +import java.util.List; + +public interface ReaderConsumerService { + + List processReaderDataFromObjectArray(); + + List processReaderDataFromReaderArray(); + + List processReaderDataFromReaderList(); + + List processNestedReaderDataFromReaderArray(); + + List processNestedReaderDataFromReaderList(); +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java new file mode 100644 index 0000000000..d1800a7f65 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java @@ -0,0 +1,90 @@ +package com.baeldung.webclient.json; + +import com.baeldung.webclient.json.model.Book; +import com.baeldung.webclient.json.model.Reader; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ReaderConsumerServiceImpl implements ReaderConsumerService { + + private final WebClient webClient; + private static final ObjectMapper mapper = new ObjectMapper(); + + public ReaderConsumerServiceImpl(WebClient webClient) { + this.webClient = webClient; + } + @Override + public List processReaderDataFromObjectArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Object[].class).log(); + Object[] objects = response.block(); + return Arrays.stream(objects) + .map(object -> mapper.convertValue(object, Reader.class)) + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processReaderDataFromReaderArray() { + Mono response = + webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Reader[].class).log(); + + Reader[] readers = response.block(); + return Arrays.stream(readers) + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processReaderDataFromReaderList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + List readers = response.block(); + + return readers.stream() + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processNestedReaderDataFromReaderArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Reader[].class).log(); + Reader[] readers = response.block(); + + return Arrays.stream(readers) + .flatMap(reader -> reader.getFavouriteBooks().stream()) + .map(Book::getAuthor) + .collect(Collectors.toList()); + } + + @Override + public List processNestedReaderDataFromReaderList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + + List readers = response.block(); + return readers.stream() + .flatMap(reader -> reader.getFavouriteBooks().stream()) + .map(Book::getAuthor) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java deleted file mode 100644 index 9afc207ff2..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.webclient.json; - -import java.util.List; - -public interface UserConsumerService { - - List processUserDataFromObjectArray(); - - List processUserDataFromUserArray(); - - List processUserDataFromUserList(); - - List processNestedUserDataFromUserArray(); - - List processNestedUserDataFromUserList(); -} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java deleted file mode 100644 index 30cd4a5617..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung.webclient.json; - -import com.baeldung.webclient.json.model.Address; -import com.baeldung.webclient.json.model.User; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.MediaType; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class UserConsumerServiceImpl implements UserConsumerService { - - private final WebClient webClient; - private static final ObjectMapper mapper = new ObjectMapper(); - - public UserConsumerServiceImpl(WebClient webClient) { - this.webClient = webClient; - } - @Override - public List processUserDataFromObjectArray() { - Mono response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(Object[].class).log(); - Object[] objects = response.block(); - return Arrays.stream(objects) - .map(object -> mapper.convertValue(object, User.class)) - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processUserDataFromUserArray() { - Mono response = - webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(User[].class).log(); - - User[] userArray = response.block(); - return Arrays.stream(userArray) - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processUserDataFromUserList() { - Mono> response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(new ParameterizedTypeReference>() {}); - List userList = response.block(); - - return userList.stream() - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processNestedUserDataFromUserArray() { - Mono response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(User[].class).log(); - User[] userArray = response.block(); - - return Arrays.stream(userArray) - .flatMap(user -> user.getAddressList().stream()) - .map(Address::getPostCode) - .collect(Collectors.toList()); - } - - @Override - public List processNestedUserDataFromUserList() { - Mono> response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(new ParameterizedTypeReference>() {}); - - List userList = response.block(); - return userList.stream() - .flatMap(user -> user.getAddressList().stream()) - .map(Address::getPostCode) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java deleted file mode 100644 index cc4323b72b..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.webclient.json.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Address { - private final String addressLine1; - private final String addressLine2; - private final String town; - private final String postCode; - - @JsonCreator - public Address( - @JsonProperty("addressLine1") String addressLine1, - @JsonProperty("addressLine2") String addressLine2, - @JsonProperty("town") String town, - @JsonProperty("postCode") String postCode) { - this.addressLine1 = addressLine1; - this.addressLine2 = addressLine2; - this.town = town; - this.postCode = postCode; - } - public String getPostCode() { - return postCode; - } -} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java new file mode 100644 index 0000000000..cb3fb258d4 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java @@ -0,0 +1,22 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Book { + private final String author; + private final String title; + + @JsonCreator + public Book( + @JsonProperty("author") String author, + @JsonProperty("title") String title) { + this.author = author; + this.title = title; + } + public String getAuthor() { + return this.author; + } +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java deleted file mode 100644 index 6ed359f9db..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.webclient.json.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class User { - private final int id; - private final String name; - private final List
    addressList; - - @JsonCreator - public User( - @JsonProperty("id") int id, - @JsonProperty("name") String name, - @JsonProperty("addressList") List
    addressList) { - this.id = id; - this.name = name; - this.addressList = addressList; - } - - public String getName() { - return name; - } - - public List
    getAddressList() { return addressList; } -} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java new file mode 100644 index 0000000000..92f7bf4f3f --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -0,0 +1,77 @@ +package com.baeldung.webclient.json; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +public class ReaderConsumerServiceImplUnitTest { + + private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBooks\":[{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + + "{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"}]}," + + "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; + + private static String BASE_URL = "http://localhost:8080"; + + WebClient webClientMock = WebClient.builder() + .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) + .header("content-type", "application/json") + .body(READER_JSON) + .build())) + .build(); + + private final ReaderConsumerService tested = new ReaderConsumerServiceImpl(webClientMock); + + @Test + void when_processReaderDataFromObjectArray_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromObjectArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processReaderDataFromReaderArray_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromReaderArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processReaderDataFromReaderList_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromReaderList(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processNestedReaderDataFromReaderArray_then_OK() { + List expected = Arrays.asList( + "Milan Kundera", + "Charles Dickens", + "J.R.R. Tolkien", + "Douglas Adams"); + + List actual = tested.processNestedReaderDataFromReaderArray(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + } + + @Test + void when_processNestedReaderDataFromReaderList_then_OK() { + List expected = Arrays.asList( + "Milan Kundera", + "Charles Dickens", + "J.R.R. Tolkien", + "Douglas Adams"); + + List actual = tested.processNestedReaderDataFromReaderList(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java deleted file mode 100644 index 151554efde..0000000000 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.webclient.json; - -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; -import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; - -public class UserConsumerServiceImplUnitTest { - - private static String USER_JSON = "[{\"id\":1,\"name\":\"user1\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user1_address1_postCode\"}," + - "{\"addressLine1\":\"address2_addressLine1\",\"addressLine2\":\"address2_addressLine2\",\"town\":\"address2_town\",\"postCode\":\"user1_address2_postCode\"}]}," + - "{\"id\":2,\"name\":\"user2\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user2_address1_postCode\"}]}]"; - - private static String BASE_URL = "http://localhost:8080"; - - WebClient webClientMock = WebClient.builder() - .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) - .header("content-type", "application/json") - .body(USER_JSON) - .build())) - .build(); - - private final UserConsumerService tested = new UserConsumerServiceImpl(webClientMock); - - @Test - void when_processUserDataFromObjectArray_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromObjectArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processUserDataFromUserArray_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromUserArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processUserDataFromUserList_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromUserList(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processNestedUserDataFromUserArray_then_OK() { - List expected = Arrays.asList( - "user1_address1_postCode", - "user1_address2_postCode", - "user2_address1_postCode"); - - List actual = tested.processNestedUserDataFromUserArray(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); - } - - @Test - void when_processNestedUserDataFromUserList_then_OK() { - List expected = Arrays.asList( - "user1_address1_postCode", - "user1_address2_postCode", - "user2_address1_postCode"); - - List actual = tested.processNestedUserDataFromUserList(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); - } -} \ No newline at end of file From a0425afd1b8710216221e0c16ba4a473f1cac373 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 11:25:11 +0000 Subject: [PATCH 521/590] MASH-4748 fix Reader object and url with WebClient --- .../baeldung/webclient/json/model/Reader.java | 30 +++++++++++++++++++ .../ReaderConsumerServiceImplUnitTest.java | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java index e69de29bb2..9fc480c3df 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java @@ -0,0 +1,30 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Reader { + private final int id; + private final String name; + private final List favouriteBooks; + + @JsonCreator + public Reader( + @JsonProperty("id") int id, + @JsonProperty("name") String name, + @JsonProperty("favouriteBooks") List favoriteBooks) { + this.id = id; + this.name = name; + this.favouriteBooks = favoriteBooks; + } + + public String getName() { + return name; + } + + public List getFavouriteBooks() { return favouriteBooks; } +} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java index 92f7bf4f3f..065f1dc11a 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -19,9 +19,9 @@ public class ReaderConsumerServiceImplUnitTest { "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; - private static String BASE_URL = "http://localhost:8080"; + private static String BASE_URL = "http://localhost:8080/readers"; - WebClient webClientMock = WebClient.builder() + WebClient webClientMock = WebClient.builder().baseUrl(BASE_URL) .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) .header("content-type", "application/json") .body(READER_JSON) From c3741487d89705dc28eac515330d9e4adb301c1f Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 12:56:18 +0000 Subject: [PATCH 522/590] BAEL-4748 update examples with favouriteBook --- .../webclient/json/ReaderConsumerService.java | 8 ++-- .../json/ReaderConsumerServiceImpl.java | 16 ++++---- .../baeldung/webclient/json/model/Reader.java | 15 ++++--- .../ReaderConsumerServiceImplUnitTest.java | 41 ++++++++++++------- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java index b0bc71d2ed..17676b3f33 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java @@ -1,14 +1,16 @@ package com.baeldung.webclient.json; +import com.baeldung.webclient.json.model.Book; + import java.util.List; public interface ReaderConsumerService { - List processReaderDataFromObjectArray(); + List processReaderDataFromObjectArray(); - List processReaderDataFromReaderArray(); + List processReaderDataFromReaderArray(); - List processReaderDataFromReaderList(); + List processReaderDataFromReaderList(); List processNestedReaderDataFromReaderArray(); diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java index d1800a7f65..8f1a4c019a 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java @@ -21,7 +21,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { this.webClient = webClient; } @Override - public List processReaderDataFromObjectArray() { + public List processReaderDataFromObjectArray() { Mono response = webClient.get() .accept(MediaType.APPLICATION_JSON) .retrieve() @@ -29,12 +29,12 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Object[] objects = response.block(); return Arrays.stream(objects) .map(object -> mapper.convertValue(object, Reader.class)) - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @Override - public List processReaderDataFromReaderArray() { + public List processReaderDataFromReaderArray() { Mono response = webClient.get() .accept(MediaType.APPLICATION_JSON) @@ -43,12 +43,12 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Reader[] readers = response.block(); return Arrays.stream(readers) - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @Override - public List processReaderDataFromReaderList() { + public List processReaderDataFromReaderList() { Mono> response = webClient.get() .accept(MediaType.APPLICATION_JSON) .retrieve() @@ -56,7 +56,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { List readers = response.block(); return readers.stream() - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @@ -69,7 +69,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Reader[] readers = response.block(); return Arrays.stream(readers) - .flatMap(reader -> reader.getFavouriteBooks().stream()) + .flatMap(reader -> reader.getBooksRead().stream()) .map(Book::getAuthor) .collect(Collectors.toList()); } @@ -83,7 +83,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { List readers = response.block(); return readers.stream() - .flatMap(reader -> reader.getFavouriteBooks().stream()) + .flatMap(reader -> reader.getBooksRead().stream()) .map(Book::getAuthor) .collect(Collectors.toList()); } diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java index 9fc480c3df..7d02853ea1 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java @@ -10,21 +10,24 @@ import java.util.List; public class Reader { private final int id; private final String name; - private final List favouriteBooks; + private final Book favouriteBook; + private final List booksRead; @JsonCreator public Reader( @JsonProperty("id") int id, @JsonProperty("name") String name, - @JsonProperty("favouriteBooks") List favoriteBooks) { + @JsonProperty("favouriteBook") Book favouriteBook, + @JsonProperty("booksRead") List booksRead) { this.id = id; this.name = name; - this.favouriteBooks = favoriteBooks; + this.favouriteBook = favouriteBook; + this.booksRead =booksRead; } - public String getName() { - return name; + public Book getFavouriteBook() { + return favouriteBook; } - public List getFavouriteBooks() { return favouriteBooks; } + public List getBooksRead() { return booksRead; } } diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java index 065f1dc11a..51f0a5c1bb 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.webclient.json; +import com.baeldung.webclient.json.model.Book; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.ClientResponse; @@ -10,13 +11,16 @@ import java.util.Arrays; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasProperty; public class ReaderConsumerServiceImplUnitTest { - private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBooks\":[{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + - "{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"}]}," + - "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + + private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBook\":{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + + "\"booksRead\":[{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"},{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}]}," + + "{\"id\":2,\"name\":\"reader2\",\"favouriteBook\":{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}," + + "\"booksRead\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; private static String BASE_URL = "http://localhost:8080/readers"; @@ -32,23 +36,30 @@ public class ReaderConsumerServiceImplUnitTest { @Test void when_processReaderDataFromObjectArray_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromObjectArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromObjectArray(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); } @Test void when_processReaderDataFromReaderArray_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromReaderArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromReaderArray(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); } @Test void when_processReaderDataFromReaderList_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromReaderList(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromReaderList(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); + } @Test @@ -60,7 +71,7 @@ public class ReaderConsumerServiceImplUnitTest { "Douglas Adams"); List actual = tested.processNestedReaderDataFromReaderArray(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + assertThat(actual, hasItems(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); } @Test @@ -72,6 +83,6 @@ public class ReaderConsumerServiceImplUnitTest { "Douglas Adams"); List actual = tested.processNestedReaderDataFromReaderList(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + assertThat(actual, hasItems(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); } } \ No newline at end of file From 0de9172dc6035454d7b923d5cf40aef327544e83 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 11:36:58 -0300 Subject: [PATCH 523/590] Moved spring-5-webclient example code to new test class, to verify everything is working as expected --- .../reactive/client/WebClientController.java | 95 --------------- .../web/client/WebClientIntegrationTest.java | 110 ++++++++++++++++++ 2 files changed, 110 insertions(+), 95 deletions(-) create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 2d42e848b2..765cd561d8 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -1,36 +1,12 @@ package com.baeldung.web.reactive.client; -import java.net.URI; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.TimeUnit; -import org.reactivestreams.Publisher; -import org.reactivestreams.Subscriber; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ReactiveHttpOutputMessage; -import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.BodyInserter; -import org.springframework.web.reactive.function.BodyInserters; -import org.springframework.web.reactive.function.client.WebClient; - -import io.netty.channel.ChannelOption; -import io.netty.handler.timeout.ReadTimeoutHandler; -import io.netty.handler.timeout.WriteTimeoutHandler; -import reactor.core.publisher.Mono; -import reactor.netty.http.client.HttpClient; @RestController public class WebClientController { @@ -42,75 +18,4 @@ public class WebClientController { response.put("field", "value"); return response; } - - public void demonstrateWebClient() { - // request - WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); - - // request body specifications - WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) - .uri("/resource"); - WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() - .uri(URI.create("/resource")); - - // request header specification - WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); - - // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - - LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add("key1", "value1"); - map.add("key2", "value2"); - - BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue(new Object()); - BodyInserter inserter4 = BodyInserters.fromValue("body"); - - // responses - WebClient.ResponseSpec response1 = uri1.body(inserter3) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .acceptCharset(Charset.forName("UTF-8")) - .ifNoneMatch("*") - .ifModifiedSince(ZonedDateTime.now()) - .retrieve(); - String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) - .block(); - String response3 = uri2.retrieve() - .bodyToMono(String.class) - .block(); - WebClient.ResponseSpec response4 = requestSpec2.retrieve(); - } - - private WebClient createWebClient() { - return WebClient.create(); - } - - private WebClient createWebClientWithServerURL() { - return WebClient.create("http://localhost:8081"); - } - - private WebClient createWebClientConfiguringTimeout() { - HttpClient httpClient = HttpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) - .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); - - return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(httpClient)) - .build(); - } - - private WebClient createWebClientWithServerURLAndDefaultValues() { - return WebClient.builder() - .baseUrl("http://localhost:8081") - .defaultCookie("cookieKey", "cookieValue") - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) - .build(); - } - } diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java new file mode 100644 index 0000000000..df873c618d --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -0,0 +1,110 @@ +package com.baeldung.web.client; + +import java.net.URI; +import java.nio.charset.Charset; +import java.time.ZonedDateTime; +import java.util.Collections; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; +import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.reactive.function.BodyInserter; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; + +import com.baeldung.web.reactive.client.WebClientApplication; + +import io.netty.channel.ChannelOption; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; +import reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClient; + +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class WebClientIntegrationTest { + + @LocalServerPort + private int port; + + @Test + public void demonstrateWebClient() { + // request + WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); + WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); + + // request body specifications + WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) + .uri("/resource"); + WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() + .uri(URI.create("/resource")); + + // request header specification + WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); + WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); + + // inserters + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + + LinkedMultiValueMap map = new LinkedMultiValueMap<>(); + map.add("key1", "value1"); + map.add("key2", "value2"); + + BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); + BodyInserter inserter3 = BodyInserters.fromValue(new Object()); + BodyInserter inserter4 = BodyInserters.fromValue("body"); + + // responses + WebClient.ResponseSpec response1 = uri1.body(inserter3) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + .acceptCharset(Charset.forName("UTF-8")) + .ifNoneMatch("*") + .ifModifiedSince(ZonedDateTime.now()) + .retrieve(); + String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + String response3 = uri2.retrieve() + .bodyToMono(String.class) + .block(); + WebClient.ResponseSpec response4 = requestSpec2.retrieve(); + } + + private WebClient createWebClient() { + return WebClient.create(); + } + + private WebClient createWebClientWithServerURL() { + return WebClient.create("http://localhost:8081"); + } + + private WebClient createWebClientConfiguringTimeout() { + HttpClient httpClient = HttpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); + + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(httpClient)) + .build(); + } + + private WebClient createWebClientWithServerURLAndDefaultValues() { + return WebClient.builder() + .baseUrl("http://localhost:8081") + .defaultCookie("cookieKey", "cookieValue") + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) + .build(); + } +} From 3e5a1f3e50c4d18ee4e7a7be34c8aa9821aa31c8 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 12:40:28 -0300 Subject: [PATCH 524/590] added endpoints to test functionality properly --- .../web/reactive/client/WebClientController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 765cd561d8..2dfcd7533b 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,7 +4,11 @@ import java.util.HashMap; import java.util.Map; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -18,4 +22,14 @@ public class WebClientController { response.put("field", "value"); return response; } + + @PostMapping("/resource") + public String postResource(@RequestBody String bodyString) { + return "processed-" + bodyString; + } + + @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String handleFormUpload(@RequestPart("key1") String value1, @RequestPart("key2") String value2) { + return "processed-" + value1 + value2; + } } From 725465b0b6e42202a5f66498773ced8b00ec5355 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 12:41:13 -0300 Subject: [PATCH 525/590] disabled security for WebClient codebase application --- .../baeldung/web/reactive/client/WebClientApplication.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java index f104ad30f1..aa9b81de4f 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java @@ -2,9 +2,10 @@ package com.baeldung.web.reactive.client; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; -@SpringBootApplication -public class WebClientApplication{ +@SpringBootApplication(exclude = { ReactiveSecurityAutoConfiguration.class }) +public class WebClientApplication { public static void main(String[] args) { SpringApplication.run(WebClientApplication.class, args); From 268fe2dfe65da6315c59b1e84bcb7d88e357f3cd Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 24 Jan 2021 12:33:05 +0100 Subject: [PATCH 526/590] BASE-4535: Example for overriding compareTo --- .../com/baeldung/compareto/BankAccount.java | 16 ++++++++ .../baeldung/compareto/BankAccountFix.java | 16 ++++++++ .../baeldung/compareto/FootballPlayer.java | 28 +++++++++++++ .../baeldung/compareto/HandballPlayer.java | 12 ++++++ .../compareto/ArraysSortingUnitTest.java | 25 ++++++++++++ .../compareto/BankAccountFixUnitTest.java | 25 ++++++++++++ .../compareto/BankAccountUnitTest.java | 25 ++++++++++++ .../compareto/FootballPlayerUnitTest.java | 40 +++++++++++++++++++ .../compareto/HandballPlayerUnitTest.java | 26 ++++++++++++ 9 files changed, 213 insertions(+) create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java create mode 100644 core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java create mode 100644 core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java new file mode 100644 index 0000000000..db1f41e6df --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java @@ -0,0 +1,16 @@ +package com.baeldung.compareto; + +public class BankAccount implements Comparable { + + private final int balance; + + public BankAccount(int balance) { + this.balance = balance; + } + + @Override + public int compareTo(BankAccount anotherAccount) { + return this.balance - anotherAccount.balance; + } + +} diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java new file mode 100644 index 0000000000..95e55fdf22 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java @@ -0,0 +1,16 @@ +package com.baeldung.compareto; + +public class BankAccountFix implements Comparable { + + private final int balance; + + public BankAccountFix(int balance) { + this.balance = balance; + } + + @Override + public int compareTo(BankAccountFix anotherAccount) { + return Integer.compare(this.balance, anotherAccount.balance); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java new file mode 100644 index 0000000000..5d065aa298 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java @@ -0,0 +1,28 @@ +package com.baeldung.compareto; + +public class FootballPlayer implements Comparable { + + private final String name; + private final int goalsScored; + + public FootballPlayer(String name, int goalsScored) { + this.name = name; + this.goalsScored = goalsScored; + } + + @Override + public int compareTo(FootballPlayer anotherPlayer) { + return this.goalsScored - anotherPlayer.goalsScored; + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + FootballPlayer player = (FootballPlayer) object; + return name.equals(player.name); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java new file mode 100644 index 0000000000..022155ccae --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java @@ -0,0 +1,12 @@ +package com.baeldung.compareto; + +public class HandballPlayer { + + private final String name; + private final int height; + + public HandballPlayer(String name, int height) { + this.name = name; + this.height = height; + } +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java new file mode 100644 index 0000000000..2082386dba --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.compareto; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ArraysSortingUnitTest { + + @Test + public void givenArrayOfNumbers_whenSortingArray_thenNumbersAreSortedAscending() { + int[] numbers = new int[] {5, 3, 9, 11, 1, 7}; + Arrays.sort(numbers); + assertThat(numbers).containsExactly(1, 3, 5, 7, 9, 11); + } + + @Test + public void givenArrayOfStrings_whenSortingArray_thenStringsAreSortedAlphabetically() { + String[] players = new String[] {"ronaldo", "modric", "ramos", "messi"}; + Arrays.sort(players); + assertThat(players).containsExactly("messi", "modric", "ramos", "ronaldo"); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java new file mode 100644 index 0000000000..9ca16d1372 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.compareto; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BankAccountFixUnitTest { + + @Test + public void givenComparisonBasedImpl_whenUsingSmallIntegers_thenComparisonWorks() { + BankAccountFix accountOne = new BankAccountFix(5000); + BankAccountFix accountTwo = new BankAccountFix(1000); + int comparison = accountOne.compareTo(accountTwo); + assertThat(comparison).isPositive(); + } + + @Test + public void givenComparisonBasedImpl_whenUsingLargeIntegers_thenComparisonWorks() { + BankAccountFix accountOne = new BankAccountFix(1900000000); + BankAccountFix accountTwo = new BankAccountFix(-2000000000); + int comparison = accountOne.compareTo(accountTwo); + assertThat(comparison).isPositive(); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java new file mode 100644 index 0000000000..6ef9372ff9 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.compareto; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +public class BankAccountUnitTest { + + @Test + public void givenSubtractionBasedImpl_whenUsingSmallIntegers_thenComparisonWorks() { + BankAccount accountOne = new BankAccount(5000); + BankAccount accountTwo = new BankAccount(1000); + int comparison = accountOne.compareTo(accountTwo); + assertThat(comparison).isPositive(); + } + + @Test + public void givenSubtractionBasedImpl_whenUsingLargeIntegers_thenComparisonBreaks() { + BankAccount accountOne = new BankAccount(1900000000); + BankAccount accountTwo = new BankAccount(-2000000000); + int comparison = accountOne.compareTo(accountTwo); + assertThat(comparison).isNegative(); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java new file mode 100644 index 0000000000..11a8a10585 --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.compareto; + +import org.junit.jupiter.api.Test; + +import java.util.Map; +import java.util.TreeMap; +import java.util.TreeSet; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FootballPlayerUnitTest { + + @Test + public void givenInconsistentCompareToAndEqualsImpl_whenUsingSortedSet_thenElementsAreNotAdded() { + FootballPlayer messi = new FootballPlayer("Messi", 800); + FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 800); + + TreeSet set = new TreeSet<>(); + set.add(messi); + set.add(ronaldo); + + assertThat(set).hasSize(1); + assertThat(set).doesNotContain(ronaldo); + } + + @Test + public void givenCompareToImpl_whenSavingElementsInTreeMap_thenKeysAreSortedUsingCompareTo() { + FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 900); + FootballPlayer messi = new FootballPlayer("Messi", 800); + FootballPlayer modric = new FootballPlayer("modric", 100); + + Map players = new TreeMap<>(); + players.put(ronaldo, "forward"); + players.put(messi, "forward"); + players.put(modric, "midfielder"); + + assertThat(players.keySet()).containsExactly(modric, messi, ronaldo); + } + +} diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java new file mode 100644 index 0000000000..cd017a5c0c --- /dev/null +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.compareto; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.TreeSet; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +public class HandballPlayerUnitTest { + + @Test + public void givenComparableIsNotImplemented_whenSortingArray_thenExceptionIsThrown() { + HandballPlayer duvnjak = new HandballPlayer("Duvnjak", 197); + HandballPlayer hansen = new HandballPlayer("Hansen", 196); + + HandballPlayer[] players = new HandballPlayer[] {duvnjak, hansen}; + + assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> Arrays.sort(players)); + } + +} From 51e2fe20b1132c9e6262d03fedaee1b92f335596 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 24 Jan 2021 16:37:24 +0100 Subject: [PATCH 527/590] BASE-4535: Update examples for overriding compareTo --- .../baeldung/compareto/FootballPlayer.java | 6 +++++- .../compareto/FootballPlayerUnitTest.java | 21 +++++++++++++++++-- .../compareto/HandballPlayerUnitTest.java | 6 ------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java index 5d065aa298..173ee32434 100644 --- a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java +++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java @@ -10,9 +10,13 @@ public class FootballPlayer implements Comparable { this.goalsScored = goalsScored; } + public String getName() { + return name; + } + @Override public int compareTo(FootballPlayer anotherPlayer) { - return this.goalsScored - anotherPlayer.goalsScored; + return Integer.compare(this.goalsScored, anotherPlayer.goalsScored); } @Override diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java index 11a8a10585..6abd1e113b 100644 --- a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java @@ -2,6 +2,10 @@ package com.baeldung.compareto; import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; @@ -11,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class FootballPlayerUnitTest { @Test - public void givenInconsistentCompareToAndEqualsImpl_whenUsingSortedSet_thenElementsAreNotAdded() { + public void givenInconsistentCompareToAndEqualsImpl_whenUsingSortedSet_thenSomeElementsAreNotAdded() { FootballPlayer messi = new FootballPlayer("Messi", 800); FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 800); @@ -23,11 +27,24 @@ public class FootballPlayerUnitTest { assertThat(set).doesNotContain(ronaldo); } + @Test + public void givenCompareToImpl_whenUsingCustomComparator_thenComparatorLogicIsApplied() { + FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 900); + FootballPlayer messi = new FootballPlayer("Messi", 800); + FootballPlayer modric = new FootballPlayer("Modric", 100); + + List players = Arrays.asList(ronaldo, messi, modric); + Comparator nameComparator = Comparator.comparing(FootballPlayer::getName); + Collections.sort(players, nameComparator); + + assertThat(players).containsExactly(messi, modric, ronaldo); + } + @Test public void givenCompareToImpl_whenSavingElementsInTreeMap_thenKeysAreSortedUsingCompareTo() { FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 900); FootballPlayer messi = new FootballPlayer("Messi", 800); - FootballPlayer modric = new FootballPlayer("modric", 100); + FootballPlayer modric = new FootballPlayer("Modric", 100); Map players = new TreeMap<>(); players.put(ronaldo, "forward"); diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java index cd017a5c0c..143286f15f 100644 --- a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java +++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java @@ -2,13 +2,7 @@ package com.baeldung.compareto; import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.TreeSet; - -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class HandballPlayerUnitTest { From 0fe15633887f0e47baf0c8118269e39a7448c8f7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 24 Jan 2021 23:40:00 +0530 Subject: [PATCH 528/590] JAVA-4012: Moved 1 article from spring-data-mongodb to spring-boot-persistence-mongodb --- .../spring-boot-persistence-mongodb/README.md | 2 + .../zoneddatetime/config/MongoConfig.java | 53 +++++++++++++++++++ .../converter/ZonedDateTimeReadConverter.java | 2 +- .../ZonedDateTimeWriteConverter.java | 2 +- .../baeldung/zoneddatetime}/model/Action.java | 2 +- .../repository/ActionRepository.java | 5 +- .../ActionRepositoryLiveTest.java | 8 +-- .../spring-data-mongodb/README.md | 5 +- .../java/com/baeldung/config/MongoConfig.java | 5 -- 9 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java rename persistence-modules/{spring-data-mongodb/src/main/java => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/converter/ZonedDateTimeReadConverter.java (88%) rename persistence-modules/{spring-data-mongodb/src/main/java => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/converter/ZonedDateTimeWriteConverter.java (87%) rename persistence-modules/{spring-data-mongodb/src/main/java/com/baeldung => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/model/Action.java (96%) rename persistence-modules/{spring-data-mongodb/src/main/java/com/baeldung => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/repository/ActionRepository.java (55%) rename persistence-modules/{spring-data-mongodb/src/test/java/com/baeldung/repository => spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime}/ActionRepositoryLiveTest.java (87%) diff --git a/persistence-modules/spring-boot-persistence-mongodb/README.md b/persistence-modules/spring-boot-persistence-mongodb/README.md index aade8eb1c0..97241ad464 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/README.md +++ b/persistence-modules/spring-boot-persistence-mongodb/README.md @@ -4,3 +4,5 @@ - [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb) - [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file) - [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) +- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) + diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java new file mode 100644 index 0000000000..3cfefa099c --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java @@ -0,0 +1,53 @@ +package com.baeldung.zoneddatetime.config; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; +import org.springframework.data.mongodb.core.convert.MongoCustomConversions; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; + +import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter; +import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; + +@Configuration +@EnableMongoRepositories(basePackages = { "com.baeldung" }) +public class MongoConfig extends AbstractMongoClientConfiguration { + + private final List> converters = new ArrayList>(); + + @Override + protected String getDatabaseName() { + return "test"; + } + + @Override + public MongoClient mongoClient() { + final ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/test"); + final MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return MongoClients.create(mongoClientSettings); + } + + @Override + public Collection getMappingBasePackages() { + return Collections.singleton("com.baeldung"); + } + + @Override + public MongoCustomConversions customConversions() { + converters.add(new ZonedDateTimeReadConverter()); + converters.add(new ZonedDateTimeWriteConverter()); + return new MongoCustomConversions(converters); + } + +} diff --git a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java similarity index 88% rename from persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java index a2d847957b..f4a4c2d040 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java @@ -1,4 +1,4 @@ -package converter; +package com.baeldung.zoneddatetime.converter; import org.springframework.core.convert.converter.Converter; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java similarity index 87% rename from persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java index e13ac2d130..2244a1460a 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java @@ -1,4 +1,4 @@ -package converter; +package com.baeldung.zoneddatetime.converter; import org.springframework.core.convert.converter.Converter; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java similarity index 96% rename from persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java index aa480dbdf7..06202fe465 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.zoneddatetime.model; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java similarity index 55% rename from persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java index bdca490fe6..e214c4b3c4 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java @@ -1,6 +1,7 @@ -package com.baeldung.repository; +package com.baeldung.zoneddatetime.repository; -import com.baeldung.model.Action; import org.springframework.data.mongodb.repository.MongoRepository; +import com.baeldung.zoneddatetime.model.Action; + public interface ActionRepository extends MongoRepository { } \ No newline at end of file diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java similarity index 87% rename from persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java rename to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java index 79648f1a20..3a241418ca 100644 --- a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java @@ -1,7 +1,5 @@ -package com.baeldung.repository; +package com.baeldung.zoneddatetime; -import com.baeldung.config.MongoConfig; -import com.baeldung.model.Action; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -12,6 +10,10 @@ import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.baeldung.zoneddatetime.config.MongoConfig; +import com.baeldung.zoneddatetime.model.Action; +import com.baeldung.zoneddatetime.repository.ActionRepository; + import java.time.ZoneOffset; import java.time.ZonedDateTime; diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index 0be8c57036..acc978c68e 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -9,9 +9,8 @@ - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) - [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) -- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) -- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) - +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) +- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions) ## Spring Data MongoDB Live Testing diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 8036bbbca2..3819558e8b 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java +++ b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -25,9 +25,6 @@ import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; -import converter.ZonedDateTimeReadConverter; -import converter.ZonedDateTimeWriteConverter; - @Configuration @EnableMongoRepositories(basePackages = "com.baeldung.repository") public class MongoConfig extends AbstractMongoClientConfiguration { @@ -69,8 +66,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { @Override public MongoCustomConversions customConversions() { converters.add(new UserWriterConverter()); - converters.add(new ZonedDateTimeReadConverter()); - converters.add(new ZonedDateTimeWriteConverter()); return new MongoCustomConversions(converters); } From 992a33fe7dd6f2c766df2ddee288243a2c2e7a16 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 24 Jan 2021 23:46:39 +0530 Subject: [PATCH 529/590] JAVA-4012: clean-up --- .../main/java/com/baeldung/config/MongoConfig.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 3819558e8b..90b1268133 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java +++ b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -5,16 +5,13 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.data.mongodb.MongoDatabaseFactory; import org.springframework.data.mongodb.MongoTransactionManager; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; -import org.springframework.data.mongodb.core.convert.MappingMongoConverter; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; -import org.springframework.data.mongodb.gridfs.GridFsTemplate; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import com.baeldung.converter.UserWriterConverter; @@ -31,9 +28,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { private final List> converters = new ArrayList>(); - @Autowired - private MappingMongoConverter mongoConverter; - @Override protected String getDatabaseName() { return "test"; @@ -69,11 +63,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { return new MongoCustomConversions(converters); } - @Bean - public GridFsTemplate gridFsTemplate() throws Exception { - return new GridFsTemplate(mongoDbFactory(), mongoConverter); - } - @Bean MongoTransactionManager transactionManager(MongoDatabaseFactory dbFactory) { return new MongoTransactionManager(dbFactory); From 2bc7dbc70868ac34ac8d3e7edb8113338fa991d4 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 24 Jan 2021 15:18:29 -0300 Subject: [PATCH 530/590] added and ordered tests in WebClientIntegrationTest to match article - test not passing (reusing specs) --- .../web/client/WebClientIntegrationTest.java | 82 +++++++++++++------ 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index df873c618d..837ea679d2 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,7 +1,7 @@ package com.baeldung.web.client; import java.net.URI; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -22,6 +23,10 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; +import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; +import org.springframework.web.reactive.function.client.WebClient.UriSpec; import com.baeldung.web.reactive.client.WebClientApplication; @@ -31,7 +36,7 @@ import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; -@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class WebClientIntegrationTest { @LocalServerPort @@ -40,44 +45,73 @@ public class WebClientIntegrationTest { @Test public void demonstrateWebClient() { // request - WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); + UriSpec requestPost1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); + UriSpec requestPost2 = createWebClientWithServerURLAndDefaultValues().post(); + UriSpec requestGet = createWebClientWithServerURLAndDefaultValues().get(); // request body specifications - WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) - .uri("/resource"); - WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() - .uri(URI.create("/resource")); + RequestBodySpec bodySpecPost = requestPost1.uri("/resource"); + RequestBodySpec bodySpecPostMultipart = requestPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + .build()); + RequestBodySpec bodySpecOverridenBaseUri = requestPost2.uri(URI.create("/resource")); // request header specification - WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); + String bodyValue = "bodyValue"; + RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); + RequestHeadersSpec headerSpecPost2 = bodySpecPost.body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); - // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + // request header specification using inserters + BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add("key1", "value1"); - map.add("key2", "value2"); + map.add("key1", "multipartValue1"); + map.add("key2", "multipartValue2"); - BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue(new Object()); - BodyInserter inserter4 = BodyInserters.fromValue("body"); + BodyInserter, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(map); + BodyInserter inserterObject = BodyInserters.fromValue(new Object()); + BodyInserter inserterString = BodyInserters.fromValue(bodyValue); + + RequestHeadersSpec headerSpecInserterCompleteSuscriber = bodySpecPost.body(inserterCompleteSuscriber); + RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); + RequestHeadersSpec headerSpecInserterObject = bodySpecPost.body(inserterObject); + RequestHeadersSpec headerSpecInserterString = bodySpecPost.body(inserterString); // responses - WebClient.ResponseSpec response1 = uri1.body(inserter3) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + ResponseSpec responsePostObject = headerSpecInserterObject.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .acceptCharset(Charset.forName("UTF-8")) + .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()) .retrieve(); - String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + String responsePostString = headerSpecInserterString.exchangeToMono(response -> response.bodyToMono(String.class)) .block(); - String response3 = uri2.retrieve() + String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + .retrieve() .bodyToMono(String.class) .block(); - WebClient.ResponseSpec response4 = requestSpec2.retrieve(); + String responsePostCompleteSubsciber = headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithBody1 = headerSpecPost1.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithBody3 = headerSpecPost2.retrieve() + .bodyToMono(String.class) + .block(); + String responseGet = headerSpecGet.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithNoBody = bodySpecPost.retrieve() + .bodyToMono(String.class) + .block(); + try { + bodySpecOverridenBaseUri.retrieve() + .bodyToMono(String.class) + .block(); + } catch (Exception ex) { + System.out.println(ex.getClass()); + } } private WebClient createWebClient() { @@ -101,7 +135,7 @@ public class WebClientIntegrationTest { private WebClient createWebClientWithServerURLAndDefaultValues() { return WebClient.builder() - .baseUrl("http://localhost:8081") + .baseUrl("http://localhost:" + port) .defaultCookie("cookieKey", "cookieValue") .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) From 84737e1056097486bdce4f7b6bc65cfafd930065 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 24 Jan 2021 17:41:34 -0300 Subject: [PATCH 531/590] added Foo for post Object scenario, removed Subscriber::onComplete scenario, fixed some other errors in examples --- .../com/baeldung/web/reactive/client/Foo.java | 20 +++ .../reactive/client/WebClientController.java | 7 +- .../web/client/WebClientIntegrationTest.java | 141 +++++++++++------- 3 files changed, 116 insertions(+), 52 deletions(-) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java new file mode 100644 index 0000000000..1fc4834cfa --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java @@ -0,0 +1,20 @@ +package com.baeldung.web.reactive.client; + +public class Foo { + + private String name; + + public Foo(String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 2dfcd7533b..4c7941ac35 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -28,8 +28,13 @@ public class WebClientController { return "processed-" + bodyString; } + @PostMapping("/resource-foo") + public String postResource(@RequestBody Foo bodyFoo) { + return "processedFoo-" + bodyFoo.getName(); + } + @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public String handleFormUpload(@RequestPart("key1") String value1, @RequestPart("key2") String value2) { - return "processed-" + value1 + value2; + return "processed-" + value1 + "-" + value2; } } diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 837ea679d2..b49aff9575 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,9 +1,13 @@ package com.baeldung.web.client; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; @@ -12,6 +16,7 @@ import org.reactivestreams.Subscriber; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; @@ -24,13 +29,17 @@ import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; +import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; import org.springframework.web.reactive.function.client.WebClient.UriSpec; +import org.springframework.web.reactive.function.client.WebClientRequestException; +import com.baeldung.web.reactive.client.Foo; import com.baeldung.web.reactive.client.WebClientApplication; import io.netty.channel.ChannelOption; +import io.netty.channel.ConnectTimeoutException; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; @@ -43,27 +52,37 @@ public class WebClientIntegrationTest { private int port; @Test - public void demonstrateWebClient() { - // request - UriSpec requestPost1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - UriSpec requestPost2 = createWebClientWithServerURLAndDefaultValues().post(); - UriSpec requestGet = createWebClientWithServerURLAndDefaultValues().get(); + public void givenDifferentScenarios_whenRequestsSent_thenObtainExpectedResponses() { + // WebClient + WebClient client1 = WebClient.create(); + WebClient client2 = WebClient.create("http://localhost:" + port); + WebClient client3 = WebClient.builder() + .baseUrl("http://localhost:" + port) + .defaultCookie("cookieKey", "cookieValue") + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) + .build(); + + // request specification + UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); + UriSpec uriSpecPost2 = client2.post(); + UriSpec requestGet = client3.get(); + + // uri specification + RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); + RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + .build()); + RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri(URI.create("/resource-foo")); // request body specifications - RequestBodySpec bodySpecPost = requestPost1.uri("/resource"); - RequestBodySpec bodySpecPostMultipart = requestPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") - .build()); - RequestBodySpec bodySpecOverridenBaseUri = requestPost2.uri(URI.create("/resource")); - - // request header specification String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headerSpecPost2 = bodySpecPost.body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(BodyInserters.fromValue(new Foo("fooName"))); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); - // request header specification using inserters - BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - + // request body specifications - using inserters LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "multipartValue1"); map.add("key2", "multipartValue2"); @@ -72,73 +91,93 @@ public class WebClientIntegrationTest { BodyInserter inserterObject = BodyInserters.fromValue(new Object()); BodyInserter inserterString = BodyInserters.fromValue(bodyValue); - RequestHeadersSpec headerSpecInserterCompleteSuscriber = bodySpecPost.body(inserterCompleteSuscriber); RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headerSpecInserterObject = bodySpecPost.body(inserterObject); - RequestHeadersSpec headerSpecInserterString = bodySpecPost.body(inserterString); + RequestHeadersSpec headerSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); + RequestHeadersSpec headerSpecInserterString = createDefaultPostResourceRequest().body(inserterString); - // responses - ResponseSpec responsePostObject = headerSpecInserterObject.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + // request header specification + RequestHeadersSpec headerSpecInserterStringWithHeaders = headerSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") - .ifModifiedSince(ZonedDateTime.now()) - .retrieve(); - String responsePostString = headerSpecInserterString.exchangeToMono(response -> response.bodyToMono(String.class)) + .ifModifiedSince(ZonedDateTime.now()); + + // request + ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); + String responsePostString = responseSpecPostString.bodyToMono(String.class) .block(); String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() .bodyToMono(String.class) .block(); - String responsePostCompleteSubsciber = headerSpecInserterCompleteSuscriber.retrieve() - .bodyToMono(String.class) - .block(); String responsePostWithBody1 = headerSpecPost1.retrieve() .bodyToMono(String.class) .block(); String responsePostWithBody3 = headerSpecPost2.retrieve() .bodyToMono(String.class) .block(); - String responseGet = headerSpecGet.retrieve() + String responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class) .block(); + ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { + }; + Map responseGet = headerSpecGet.retrieve() + .bodyToMono(ref) + .block(); String responsePostWithNoBody = bodySpecPost.retrieve() .bodyToMono(String.class) .block(); - try { + + // response assertions + assertThat(responsePostString).isEqualTo("processed-bodyValue"); + assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); + assertThat(responsePostWithBody1).isEqualTo("processed-"); + assertThat(responsePostWithBody3).isEqualTo("processed-"); + assertThat(responseGet).containsEntry("field", "value"); + assertThat(responsePostWithNoBody).isEqualTo("processed-"); + assertThat(responsePostFoo).isEqualTo("processed-fooName"); + + assertThrows(WebClientRequestException.class, () -> { + String responsePostObject = headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + }); + assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) .block(); - } catch (Exception ex) { - System.out.println(ex.getClass()); - } + }); + } - private WebClient createWebClient() { - return WebClient.create(); - } - - private WebClient createWebClientWithServerURL() { - return WebClient.create("http://localhost:8081"); - } - - private WebClient createWebClientConfiguringTimeout() { + @Test + public void givenWebClientWithTimeoutConfigurations_whenRequestUsingWronglyConfiguredPublisher_thenObtainTimeout() { HttpClient httpClient = HttpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) - .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(1000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(1000, TimeUnit.MILLISECONDS))); - return WebClient.builder() + WebClient timeoutClient = WebClient.builder() .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); + + BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() + .uri("/resource") + .body(inserterCompleteSuscriber); + WebClientRequestException exception = assertThrows(WebClientRequestException.class, () -> { + headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class) + .block(); + }); + assertThat(exception.getCause()).isInstanceOf(ConnectTimeoutException.class); } - private WebClient createWebClientWithServerURLAndDefaultValues() { - return WebClient.builder() - .baseUrl("http://localhost:" + port) - .defaultCookie("cookieKey", "cookieValue") - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) - .build(); + private RequestBodyUriSpec createDefaultPostRequest() { + return WebClient.create("http://localhost:" + port) + .post(); + } + + private RequestBodySpec createDefaultPostResourceRequest() { + return createDefaultPostRequest().uri("/resource"); } } From 431442e3cab7bd575b1f136f362517aecab0d279 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Mon, 25 Jan 2021 12:29:01 +0200 Subject: [PATCH 532/590] BAEL-4499 - Synchronization bad practice and solution example --- .../AnimalBadPractice.java | 35 +++++++++++++ .../AnimalSolution.java | 42 +++++++++++++++ .../SynchronizationBadPracticeExample.java | 51 +++++++++++++++++++ .../SynchronizationSolutionExample.java | 30 +++++++++++ 4 files changed, 158 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java new file mode 100644 index 0000000000..ca6b7db765 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java @@ -0,0 +1,35 @@ +package com.baeldung.synchronizationbadpractices; + +public class AnimalBadPractice { + + private String name; + private String owner; + + public String getName() { + return name; + } + + public String getOwner() { + return owner; + } + + public synchronized void setName(String name) { + this.name = name; + } + + public void setOwner(String owner) { + synchronized(this) { + this.owner = owner; + } + } + + public AnimalBadPractice() { + + } + + public AnimalBadPractice(String name, String owner) { + this.name = name; + this.owner = owner; + } + +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java new file mode 100644 index 0000000000..b49cfa05d4 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java @@ -0,0 +1,42 @@ +package com.baeldung.synchronizationbadpractices; + +public class AnimalSolution { + + private final Object objLock1 = new Object(); + private final Object objLock2 = new Object(); + + private String name; + private String owner; + + public String getName() { + return name; + } + + public String getOwner() { + return owner; + } + + + public void setName(String name) { + synchronized(objLock1) { + this.name = name; + } + } + + public void setOwner(String owner) { + synchronized(objLock2) { + this.owner = owner; + } + } + + public AnimalSolution() { + + } + + public AnimalSolution(String name, String owner) { + this.name = name; + this.owner = owner; + } + + +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java new file mode 100644 index 0000000000..84d2e1cbb6 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java @@ -0,0 +1,51 @@ +package com.baeldung.synchronizationbadpractices; + +public class SynchronizationBadPracticeExample { + + public void stringBadPractice1() { + String stringLock = "LOCK_STRING"; + synchronized (stringLock) { + // ... + } + } + + private final String stringLock = "LOCK_STRING"; + public void stringBadPractice2() { + synchronized (stringLock) { + // ... + } + } + + private final String internedStringLock = new String("LOCK_STRING").intern(); + public void stringBadPractice3() { + synchronized (internedStringLock) { + // ... + } + } + + private final Boolean booleanLock = Boolean.FALSE; + public void booleanBadPractice() { + synchronized (booleanLock) { + // ... + } + } + + private int count = 0; + private final Integer intLock = count; + public void boxedPrimitiveBadPractice() { + synchronized (intLock) { + count++; + // ... + } + } + + public void classBadPractice() throws InterruptedException { + AnimalBadPractice animalObj = new AnimalBadPractice("Tommy", "John"); + synchronized(animalObj) { + while (true) { + Thread.sleep(Integer.MAX_VALUE); + } + } + } + +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java new file mode 100644 index 0000000000..a3ab8a2cee --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java @@ -0,0 +1,30 @@ +package com.baeldung.synchronizationbadpractices; + +public class SynchronizationSolutionExample { + + private final String stringLock = new String("LOCK_STRING"); + public void stringSolution() { + synchronized (stringLock) { + // ... + } + } + + private int count = 0; + private final Integer intLock = new Integer(count); + public void boxedPrimitiveSolution() { + synchronized(intLock) { + count++; + // ... + } + } + + private static int staticCount = 0; + private static final Object staticObjLock = new Object(); + public void staticVariableSolution() { + synchronized(staticObjLock) { + staticCount++; + // ... + } + } + +} From cfe47f772a434eb3b1c462144c9a2301e3418cf4 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:37:12 -0300 Subject: [PATCH 533/590] fixed rest of tests --- .../com/baeldung/web/reactive/client/Foo.java | 4 ++++ .../reactive/client/WebClientController.java | 10 ++++---- .../web/client/WebClientIntegrationTest.java | 24 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java index 1fc4834cfa..c6e3678832 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java @@ -4,6 +4,10 @@ public class Foo { private String name; + public Foo() { + super(); + } + public Foo(String name) { super(); this.name = name; diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 4c7941ac35..1a91001807 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + @RestController public class WebClientController { @@ -24,13 +26,13 @@ public class WebClientController { } @PostMapping("/resource") - public String postResource(@RequestBody String bodyString) { - return "processed-" + bodyString; + public Mono postStringResource(@RequestBody Mono bodyString) { + return bodyString.map(body -> "processed-" + body); } @PostMapping("/resource-foo") - public String postResource(@RequestBody Foo bodyFoo) { - return "processedFoo-" + bodyFoo.getName(); + public Mono postFooResource(@RequestBody Mono bodyFoo) { + return bodyFoo.map(foo -> "processedFoo-" + foo.getName()); } @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index b49aff9575..04a4031c62 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -17,8 +17,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.codec.CodecException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.client.reactive.ClientHttpRequest; @@ -72,8 +74,8 @@ public class WebClientIntegrationTest { RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") .build()); + RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); - RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri(URI.create("/resource-foo")); // request body specifications String bodyValue = "bodyValue"; @@ -124,23 +126,27 @@ public class WebClientIntegrationTest { Map responseGet = headerSpecGet.retrieve() .bodyToMono(ref) .block(); - String responsePostWithNoBody = bodySpecPost.retrieve() - .bodyToMono(String.class) + Map responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + return responseHandler.bodyToMono(ref); + }) .block(); // response assertions assertThat(responsePostString).isEqualTo("processed-bodyValue"); assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); - assertThat(responsePostWithBody1).isEqualTo("processed-"); - assertThat(responsePostWithBody3).isEqualTo("processed-"); + assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); + assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); assertThat(responseGet).containsEntry("field", "value"); - assertThat(responsePostWithNoBody).isEqualTo("processed-"); - assertThat(responsePostFoo).isEqualTo("processed-fooName"); + assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); + assertThat(responsePostWithNoBody).containsEntry("error", "Bad Request"); - assertThrows(WebClientRequestException.class, () -> { - String responsePostObject = headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) + // assert sending plain `new Object()` as request body + assertThrows(CodecException.class, () -> { + headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) .block(); }); + // assert sending request overriding base uri assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) From 0cda08a95e6326c4e5dfec76c54e2a865974b1d5 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:41:57 -0300 Subject: [PATCH 534/590] replaced existing scenario to use an alternative body method --- .../java/com/baeldung/web/client/WebClientIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 04a4031c62..34627b00ed 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -81,7 +81,7 @@ public class WebClientIntegrationTest { String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(BodyInserters.fromValue(new Foo("fooName"))); + RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); // request body specifications - using inserters From a37812ce04cb20c7a1a76deabbe15137c6fb5c26 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:44:44 -0300 Subject: [PATCH 535/590] added additional scenario using bodyValue method --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 34627b00ed..032d62b04d 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -81,6 +81,7 @@ public class WebClientIntegrationTest { String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); @@ -115,6 +116,9 @@ public class WebClientIntegrationTest { String responsePostWithBody1 = headerSpecPost1.retrieve() .bodyToMono(String.class) .block(); + String responsePostWithBody2 = headerSpecPost2.retrieve() + .bodyToMono(String.class) + .block(); String responsePostWithBody3 = headerSpecPost2.retrieve() .bodyToMono(String.class) .block(); @@ -136,6 +140,7 @@ public class WebClientIntegrationTest { assertThat(responsePostString).isEqualTo("processed-bodyValue"); assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); + assertThat(responsePostWithBody2).isEqualTo("processed-bodyValue"); assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); assertThat(responseGet).containsEntry("field", "value"); assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); From 615322468ecf4093d2e96c453b6c389dac7e9e5c Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 12:26:37 -0300 Subject: [PATCH 536/590] made tests assertions non-blocking --- spring-5-reactive/pom.xml | 11 ++- .../web/client/WebClientIntegrationTest.java | 68 ++++++++++--------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 60c8b90e16..40791faaaf 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 spring-5-reactive 0.0.1-SNAPSHOT @@ -73,6 +74,12 @@ spring-security-test test + + io.projectreactor + reactor-test + test + + diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 032d62b04d..01de550a9c 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -46,6 +46,7 @@ import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; +import reactor.test.StepVerifier; @SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class WebClientIntegrationTest { @@ -107,44 +108,46 @@ public class WebClientIntegrationTest { // request ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); - String responsePostString = responseSpecPostString.bodyToMono(String.class) - .block(); - String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + Mono responsePostString = responseSpecPostString.bodyToMono(String.class); + Mono responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody1 = headerSpecPost1.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody2 = headerSpecPost2.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody3 = headerSpecPost2.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostFoo = headerSpecFooPost.retrieve() - .bodyToMono(String.class) - .block(); + .bodyToMono(String.class); + Mono responsePostWithBody1 = headerSpecPost1.retrieve() + .bodyToMono(String.class); + Mono responsePostWithBody2 = headerSpecPost2.retrieve() + .bodyToMono(String.class); + Mono responsePostWithBody3 = headerSpecPost2.retrieve() + .bodyToMono(String.class); + Mono responsePostFoo = headerSpecFooPost.retrieve() + .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - Map responseGet = headerSpecGet.retrieve() - .bodyToMono(ref) - .block(); - Map responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + Mono> responseGet = headerSpecGet.retrieve() + .bodyToMono(ref); + Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); return responseHandler.bodyToMono(ref); - }) - .block(); + }); // response assertions - assertThat(responsePostString).isEqualTo("processed-bodyValue"); - assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); - assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); - assertThat(responsePostWithBody2).isEqualTo("processed-bodyValue"); - assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); - assertThat(responseGet).containsEntry("field", "value"); - assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); - assertThat(responsePostWithNoBody).containsEntry("error", "Bad Request"); + StepVerifier.create(responsePostString) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostMultipart) + .expectNext("processed-multipartValue1-multipartValue2"); + StepVerifier.create(responsePostWithBody1) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostWithBody2) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostWithBody3) + .expectNext("processed-bodyValue"); + StepVerifier.create(responseGet) + .expectNextMatches(nextMap -> nextMap.get("field") + .equals("value")); + StepVerifier.create(responsePostFoo) + .expectNext("processedFoo-fooName"); + StepVerifier.create(responsePostWithNoBody) + .expectNextMatches(nextMap -> nextMap.get("error") + .equals("Bad Request")); // assert sending plain `new Object()` as request body assertThrows(CodecException.class, () -> { @@ -152,11 +155,12 @@ public class WebClientIntegrationTest { .block(); }); // assert sending request overriding base uri - assertThrows(WebClientRequestException.class, () -> { + Exception exception = assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) .block(); }); + assertThat(exception.getMessage()).contains("Connection refused"); } From e8569d56b0eb251b49baf091ecaf3dc792f74bca Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Tue, 26 Jan 2021 04:09:58 +0500 Subject: [PATCH 537/590] add file for constantpool (#10442) * Create ConstantPool.java add file for constantpool * update the module with most relevant update the module with most relevant --- .../main/java/com/baeldung/constantpool/ConstantPool.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java new file mode 100644 index 0000000000..b9aea05272 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java @@ -0,0 +1,8 @@ +package com.baeldung.constantpool; + +public class ConstantPool { + + public void sayHello() { + System.out.println("Hello World"); + } +} From b018825dc40e2b0a2d0e242bcf88ed4d6253a488 Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Tue, 26 Jan 2021 20:36:04 +0530 Subject: [PATCH 538/590] BAEL-4710 - Hiding endpoints using @Hidden (#10431) * Added code for checking if a class is abstract or not. * Renamed test name as per review comments. * BAEL-4695 - Added code to evaluate math expressions. * BAEL-4695 - Added test case for math function. * BAEL-4695 Added consistent examples and entry in parent pom. * BAEL-4695 - Added more examples * BAEL-4710 - Hiding endpoints using @Hidden --- .../controller/RegularRestController.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java new file mode 100644 index 0000000000..f3135229d6 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java @@ -0,0 +1,31 @@ +package com.baeldung.springdoc.controller; + +import java.time.LocalDate; +import java.time.LocalTime; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Hidden; + +@Hidden +@RestController +public class RegularRestController { + + @Hidden + @GetMapping("/getAuthor") + public String getAuthor() { + return "Umang Budhwar"; + } + + @GetMapping("/getDate") + public LocalDate getDate() { + return LocalDate.now(); + } + + @GetMapping("/getTime") + public LocalTime getTime() { + return LocalTime.now(); + } + +} From 609c4db4fba6764034ea94394ed4ec8c4413a3c5 Mon Sep 17 00:00:00 2001 From: Yavuz Tas <12643010+yavuztas@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:10:30 +0100 Subject: [PATCH 539/590] BAEL-3828 Where Should @Service Annotation Be Kept? (#10430) * BAEL-3828 add code samples and tests for the article * BAEL-3828 fix maven test folder structure and test executions * BAEL-3828 fix indentation in continuation lines --- .../annotations/service/AuthApplication.java | 22 ++++++++ .../AbstractAuthenticationService.java | 12 +++++ .../InMemoryAuthenticationService.java | 14 +++++ .../concretes/LdapAuthenticationService.java | 14 +++++ .../interfaces/AuthenticationService.java | 10 ++++ .../EmployeeApplicationUnitTest.java} | 2 +- .../service/AuthApplicationUnitTest.java | 51 +++++++++++++++++++ .../AbstractsAnnotatedTestConfiguration.java | 10 ++++ ...reteClassesAnnotatedTestConfiguration.java | 10 ++++ .../InterfacesAnnotatedTestConfiguration.java | 10 ++++ 10 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java rename spring-boot-modules/spring-boot-annotations/src/{main/test/com.baeldung.annotations/EmployeeApplicationTest.java => test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java} (96%) create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java new file mode 100644 index 0000000000..fa5770b08e --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java @@ -0,0 +1,22 @@ +package com.baeldung.annotations.service; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AuthApplication { + + @Autowired + private AuthenticationService inMemoryAuthService; + + @Autowired + private AbstractAuthenticationService ldapAuthService; + + public static void main(String[] args) { + SpringApplication.run(AuthApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java new file mode 100644 index 0000000000..47fac229f7 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java @@ -0,0 +1,12 @@ +package com.baeldung.annotations.service.abstracts; + +import org.springframework.stereotype.Service; + +@Service +public abstract class AbstractAuthenticationService { + + public boolean authenticate(String username, String password) { + return false; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java new file mode 100644 index 0000000000..8f80cb8593 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java @@ -0,0 +1,14 @@ +package com.baeldung.annotations.service.concretes; + +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.springframework.stereotype.Service; + +@Service +public class InMemoryAuthenticationService implements AuthenticationService { + + @Override + public boolean authenticate(String username, String password) { + return false; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java new file mode 100644 index 0000000000..af93ea13be --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java @@ -0,0 +1,14 @@ +package com.baeldung.annotations.service.concretes; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import org.springframework.stereotype.Service; + +@Service +public class LdapAuthenticationService extends AbstractAuthenticationService { + + @Override + public boolean authenticate(String username, String password) { + return true; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java new file mode 100644 index 0000000000..0537343266 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.interfaces; + +import org.springframework.stereotype.Service; + +@Service +public interface AuthenticationService { + + boolean authenticate(String username, String password); + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java similarity index 96% rename from spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java rename to spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java index 66700cf781..8dfc743f3d 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertAll; -public class EmployeeApplicationTest { +public class EmployeeApplicationUnitTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withUserConfiguration(EmployeeApplication.class); diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java new file mode 100644 index 0000000000..ecbf1b38e5 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.annotations.service; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import com.baeldung.annotations.service.config.AbstractsAnnotatedTestConfiguration; +import com.baeldung.annotations.service.config.ConcreteClassesAnnotatedTestConfiguration; +import com.baeldung.annotations.service.config.InterfacesAnnotatedTestConfiguration; +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +public class AuthApplicationUnitTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + + @Test + void whenOnlyInterfacesAnnotated_noSuchBeanDefinitionExceptionThrown() { + contextRunner + .withUserConfiguration(InterfacesAnnotatedTestConfiguration.class) + .run(context -> { + Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> { + context.getBean(AuthenticationService.class); + }); + }); + } + + @Test + void whenOnlyAbstractClassesAnnotated_noSuchBeanDefinitionExceptionThrown() { + contextRunner + .withUserConfiguration(AbstractsAnnotatedTestConfiguration.class) + .run(context -> { + Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> { + context.getBean(AbstractAuthenticationService.class); + }); + }); + } + + @Test + void whenConcreteClassesAnnotated_noExceptionThrown() { + contextRunner + .withUserConfiguration(ConcreteClassesAnnotatedTestConfiguration.class) + .run(context -> { + AuthenticationService inMemoryAuthService = context.getBean(AuthenticationService.class); + AbstractAuthenticationService ldapAuthService = context.getBean(AbstractAuthenticationService.class); + + Assertions.assertNotNull(inMemoryAuthService); + Assertions.assertNotNull(ldapAuthService); + }); + } +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..4c52401a06 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.abstracts") +public class AbstractsAnnotatedTestConfiguration { + +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..baf7fb970c --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.concretes") +public class ConcreteClassesAnnotatedTestConfiguration { + +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..94659902a1 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.interfaces") +public class InterfacesAnnotatedTestConfiguration { + +} From 384b89d3ea78c39568fadf8e6a051f670952e398 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 12:57:49 -0300 Subject: [PATCH 540/590] added response timeout to timeout configuration --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 01de550a9c..f54d8a6c3d 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.ZonedDateTime; import java.util.Collections; import java.util.Map; @@ -116,7 +117,7 @@ public class WebClientIntegrationTest { .bodyToMono(String.class); Mono responsePostWithBody2 = headerSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost2.retrieve() + Mono responsePostWithBody3 = headerSpecPost3.retrieve() .bodyToMono(String.class); Mono responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class); @@ -168,6 +169,7 @@ public class WebClientIntegrationTest { public void givenWebClientWithTimeoutConfigurations_whenRequestUsingWronglyConfiguredPublisher_thenObtainTimeout() { HttpClient httpClient = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) + .responseTimeout(Duration.ofMillis(1000)) .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(1000, TimeUnit.MILLISECONDS)) .addHandlerLast(new WriteTimeoutHandler(1000, TimeUnit.MILLISECONDS))); From f8ca77bc71323ac704fb138db497e05b4bd11562 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 16:05:31 -0300 Subject: [PATCH 541/590] fixed and improved reactive tests not getting verified --- .../web/client/WebClientIntegrationTest.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index f54d8a6c3d..cbf11766e1 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,7 +1,6 @@ package com.baeldung.web.client; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -42,7 +41,6 @@ import com.baeldung.web.reactive.client.Foo; import com.baeldung.web.reactive.client.WebClientApplication; import io.netty.channel.ChannelOption; -import io.netty.channel.ConnectTimeoutException; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; @@ -129,40 +127,45 @@ public class WebClientIntegrationTest { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); return responseHandler.bodyToMono(ref); }); + Mono responsePostOverridenBaseUri = bodySpecOverridenBaseUri.retrieve() + .bodyToMono(String.class); // response assertions StepVerifier.create(responsePostString) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostMultipart) - .expectNext("processed-multipartValue1-multipartValue2"); + .expectNext("processed-multipartValue1-multipartValue2") + .verifyComplete(); StepVerifier.create(responsePostWithBody1) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostWithBody2) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostWithBody3) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responseGet) .expectNextMatches(nextMap -> nextMap.get("field") - .equals("value")); + .equals("value")) + .verifyComplete(); StepVerifier.create(responsePostFoo) - .expectNext("processedFoo-fooName"); + .expectNext("processedFoo-fooName") + .verifyComplete(); StepVerifier.create(responsePostWithNoBody) .expectNextMatches(nextMap -> nextMap.get("error") - .equals("Bad Request")); - - // assert sending plain `new Object()` as request body - assertThrows(CodecException.class, () -> { - headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) - .block(); - }); + .equals("Bad Request")) + .verifyComplete(); // assert sending request overriding base uri - Exception exception = assertThrows(WebClientRequestException.class, () -> { - bodySpecOverridenBaseUri.retrieve() - .bodyToMono(String.class) - .block(); - }); - assertThat(exception.getMessage()).contains("Connection refused"); - + StepVerifier.create(responsePostOverridenBaseUri) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + // assert error plain `new Object()` as request body + StepVerifier.create(headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) + .expectError(CodecException.class) + .verify(); } @Test @@ -181,12 +184,11 @@ public class WebClientIntegrationTest { RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() .uri("/resource") .body(inserterCompleteSuscriber); - WebClientRequestException exception = assertThrows(WebClientRequestException.class, () -> { - headerSpecInserterCompleteSuscriber.retrieve() - .bodyToMono(String.class) - .block(); - }); - assertThat(exception.getCause()).isInstanceOf(ConnectTimeoutException.class); + + StepVerifier.create(headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class)) + .expectTimeout(Duration.ofMillis(2000)) + .verify(); } private RequestBodyUriSpec createDefaultPostRequest() { From d87cd065aa9ecb87dd080cce8b9b4dc14203a341 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 16:31:14 -0300 Subject: [PATCH 542/590] cleaned WebClient. definition for spec, for consistency and simplicity --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index cbf11766e1..c8a306c4bc 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -66,8 +66,8 @@ public class WebClientIntegrationTest { .build(); // request specification - UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); - UriSpec uriSpecPost2 = client2.post(); + UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); + UriSpec uriSpecPost2 = client2.post(); UriSpec requestGet = client3.get(); // uri specification From 32f35285754fc004ad48e08a645dc2759b0b851a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 17:41:44 -0300 Subject: [PATCH 543/590] added more common exchangeToMono example for article --- .../web/client/WebClientIntegrationTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index c8a306c4bc..9116ff3e63 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -115,8 +115,18 @@ public class WebClientIntegrationTest { .bodyToMono(String.class); Mono responsePostWithBody2 = headerSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost3.retrieve() - .bodyToMono(String.class); + Mono responsePostWithBody3 = headerSpecPost3.exchangeToMono(response -> { + if (response.statusCode() + .equals(HttpStatus.OK)) { + return response.bodyToMono(String.class); + } else if (response.statusCode() + .is4xxClientError()) { + return Mono.just("Error response"); + } else { + return response.createException() + .flatMap(Mono::error); + } + }); Mono responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { From 0f668a63b91dadf4a9e5dc479a38f1d8c954a33b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 17:53:48 -0300 Subject: [PATCH 544/590] renamed headersSpec to match article --- .../web/client/WebClientIntegrationTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 9116ff3e63..49edf422b0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -79,11 +79,11 @@ public class WebClientIntegrationTest { // request body specifications String bodyValue = "bodyValue"; - RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headerSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); - RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); - RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); + RequestHeadersSpec headersSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); + RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); + RequestHeadersSpec headersSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); + RequestHeadersSpec headersSpecGet = requestGet.uri("/resource"); // request body specifications - using inserters LinkedMultiValueMap map = new LinkedMultiValueMap<>(); @@ -94,28 +94,28 @@ public class WebClientIntegrationTest { BodyInserter inserterObject = BodyInserters.fromValue(new Object()); BodyInserter inserterString = BodyInserters.fromValue(bodyValue); - RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headerSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); - RequestHeadersSpec headerSpecInserterString = createDefaultPostResourceRequest().body(inserterString); + RequestHeadersSpec headersSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); + RequestHeadersSpec headersSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); + RequestHeadersSpec headersSpecInserterString = createDefaultPostResourceRequest().body(inserterString); // request header specification - RequestHeadersSpec headerSpecInserterStringWithHeaders = headerSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + RequestHeadersSpec headersSpecInserterStringWithHeaders = headersSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()); // request - ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); + ResponseSpec responseSpecPostString = headersSpecInserterStringWithHeaders.retrieve(); Mono responsePostString = responseSpecPostString.bodyToMono(String.class); - Mono responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + Mono responsePostMultipart = headersSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() .bodyToMono(String.class); - Mono responsePostWithBody1 = headerSpecPost1.retrieve() + Mono responsePostWithBody1 = headersSpecPost1.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody2 = headerSpecPost2.retrieve() + Mono responsePostWithBody2 = headersSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost3.exchangeToMono(response -> { + Mono responsePostWithBody3 = headersSpecPost3.exchangeToMono(response -> { if (response.statusCode() .equals(HttpStatus.OK)) { return response.bodyToMono(String.class); @@ -127,11 +127,11 @@ public class WebClientIntegrationTest { .flatMap(Mono::error); } }); - Mono responsePostFoo = headerSpecFooPost.retrieve() + Mono responsePostFoo = headersSpecFooPost.retrieve() .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - Mono> responseGet = headerSpecGet.retrieve() + Mono> responseGet = headersSpecGet.retrieve() .bodyToMono(ref); Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -173,7 +173,7 @@ public class WebClientIntegrationTest { .contains("Connection refused")) .verify(); // assert error plain `new Object()` as request body - StepVerifier.create(headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) + StepVerifier.create(headersSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) .expectError(CodecException.class) .verify(); } @@ -191,11 +191,11 @@ public class WebClientIntegrationTest { .build(); BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() + RequestHeadersSpec headersSpecInserterCompleteSuscriber = timeoutClient.post() .uri("/resource") .body(inserterCompleteSuscriber); - StepVerifier.create(headerSpecInserterCompleteSuscriber.retrieve() + StepVerifier.create(headersSpecInserterCompleteSuscriber.retrieve() .bodyToMono(String.class)) .expectTimeout(Duration.ofMillis(2000)) .verify(); From c477f22f27fbe4c3900fa5e5ea79223e9dc255b6 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 18:17:17 -0300 Subject: [PATCH 545/590] modified url override example, to use the client3 (the one defining the baseUrl) --- .../java/com/baeldung/web/client/WebClientIntegrationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 49edf422b0..eddbf74868 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -75,7 +75,8 @@ public class WebClientIntegrationTest { RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") .build()); RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); - RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec bodySpecOverridenBaseUri = client3.post() + .uri(URI.create("/resource")); // request body specifications String bodyValue = "bodyValue"; From 047dfdef258719a8c91bde81329075f2dc5dc589 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 27 Jan 2021 12:28:41 -0300 Subject: [PATCH 546/590] split integration test into different test scenarios, one for each step in the webclient process --- .../web/client/WebClientIntegrationTest.java | 266 +++++++++++++----- 1 file changed, 192 insertions(+), 74 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index eddbf74868..39adf0b5c0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -33,8 +33,8 @@ import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; -import org.springframework.web.reactive.function.client.WebClient.UriSpec; import org.springframework.web.reactive.function.client.WebClientRequestException; import com.baeldung.web.reactive.client.Foo; @@ -53,9 +53,13 @@ public class WebClientIntegrationTest { @LocalServerPort private int port; + private static final String BODY_VALUE = "bodyValue"; + private static final ParameterizedTypeReference> MAP_RESPONSE_REF = new ParameterizedTypeReference>() { + }; + @Test - public void givenDifferentScenarios_whenRequestsSent_thenObtainExpectedResponses() { - // WebClient + public void givenDifferentWebClientCreationMethods_whenUsed_thenObtainExpectedResponse() { + // WebClient creation WebClient client1 = WebClient.create(); WebClient client2 = WebClient.create("http://localhost:" + port); WebClient client3 = WebClient.builder() @@ -65,58 +69,149 @@ public class WebClientIntegrationTest { .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) .build(); - // request specification - UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); - UriSpec uriSpecPost2 = client2.post(); - UriSpec requestGet = client3.get(); + // response assertions + StepVerifier.create(retrieveResponse(client1.post() + .uri("http://localhost:" + port + "/resource"))) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(client2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(client3)) + .expectNext("processed-bodyValue") + .verifyComplete(); + // assert response without specifying URI + StepVerifier.create(retrieveResponse(client1)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + } + @Test + public void givenDifferentMethodSpecifications_whenUsed_thenObtainExpectedResponse() { + // request specification + RequestBodyUriSpec uriSpecPost1 = createDefaultClient().method(HttpMethod.POST); + RequestBodyUriSpec uriSpecPost2 = createDefaultClient().post(); + RequestHeadersUriSpec requestGet = createDefaultClient().get(); + + // response assertions + StepVerifier.create(retrieveResponse(uriSpecPost1)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(uriSpecPost2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveGetResponse(requestGet)) + .expectNextMatches(nextMap -> nextMap.get("field") + .equals("value")) + .verifyComplete(); + } + + @Test + public void givenDifferentUriSpecifications_whenUsed_thenObtainExpectedResponse() { // uri specification - RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); - RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + RequestBodySpec bodySpecUsingString = createDefaultPostRequest().uri("/resource"); + RequestBodySpec bodySpecUsingUriBuilder = createDefaultPostRequest().uri(uriBuilder -> uriBuilder.pathSegment("resource") .build()); - RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); - RequestBodySpec bodySpecOverridenBaseUri = client3.post() + RequestBodySpec bodySpecusingURI = createDefaultPostRequest().uri(URI.create("http://localhost:" + port + "/resource")); + RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec bodySpecOverridenBaseUri2 = WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .post() .uri(URI.create("/resource")); - // request body specifications - String bodyValue = "bodyValue"; - RequestHeadersSpec headersSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); - RequestHeadersSpec headersSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); - RequestHeadersSpec headersSpecGet = requestGet.uri("/resource"); + // response assertions + StepVerifier.create(retrieveResponse(bodySpecUsingString)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(bodySpecUsingUriBuilder)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(bodySpecusingURI)) + .expectNext("processed-bodyValue") + .verifyComplete(); + // assert sending request overriding base URI + StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri2)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + } - // request body specifications - using inserters + @Test + public void givenDifferentBodySpecifications_whenUsed_thenObtainExpectedResponse() { + // request body specifications + RequestHeadersSpec headersSpecPost1 = createDefaultPostResourceRequest().body(BodyInserters.fromPublisher(Mono.just(BODY_VALUE), String.class)); + RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(BODY_VALUE)); + RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(BODY_VALUE); + RequestHeadersSpec headersSpecFooPost = createDefaultPostRequest().uri("/resource-foo") + .body(Mono.just(new Foo("fooName")), Foo.class); + BodyInserter inserterPlainObject = BodyInserters.fromValue(new Object()); + RequestHeadersSpec headersSpecPlainObject = createDefaultPostResourceRequest().body(inserterPlainObject); + + // request body specifications - using other inserter method (multipart request) LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "multipartValue1"); map.add("key2", "multipartValue2"); - BodyInserter, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(map); - BodyInserter inserterObject = BodyInserters.fromValue(new Object()); - BodyInserter inserterString = BodyInserters.fromValue(bodyValue); + RequestHeadersSpec headersSpecInserterMultipart = createDefaultPostRequest().uri("/resource-multipart") + .body(inserterMultipart); - RequestHeadersSpec headersSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headersSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); - RequestHeadersSpec headersSpecInserterString = createDefaultPostResourceRequest().body(inserterString); + // response assertions + StepVerifier.create(retrieveResponse(headersSpecPost1)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecPost2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecPost3)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecFooPost)) + .expectNext("processedFoo-fooName") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecInserterMultipart)) + .expectNext("processed-multipartValue1-multipartValue2") + .verifyComplete(); + // assert error plain `new Object()` as request body + StepVerifier.create(retrieveResponse(headersSpecPlainObject)) + .expectError(CodecException.class) + .verify(); + // assert response for request with no body + Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + return responseHandler.bodyToMono(MAP_RESPONSE_REF); + }); + StepVerifier.create(responsePostWithNoBody) + .expectNextMatches(nextMap -> nextMap.get("error") + .equals("Bad Request")) + .verifyComplete(); + } + @Test + public void givenPostSpecifications_whenHeadersAdded_thenObtainExpectedResponse() { // request header specification - RequestHeadersSpec headersSpecInserterStringWithHeaders = headersSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + RequestHeadersSpec headersSpecInserterStringWithHeaders = createDefaultPostResourceRequestResponse().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()); - // request - ResponseSpec responseSpecPostString = headersSpecInserterStringWithHeaders.retrieve(); + // response assertions + StepVerifier.create(retrieveResponse(headersSpecInserterStringWithHeaders)) + .expectNext("processed-bodyValue") + .verifyComplete(); + } + + @Test + public void givenDifferentResponseSpecifications_whenUsed_thenObtainExpectedResponse() { + ResponseSpec responseSpecPostString = createDefaultPostResourceRequestResponse().retrieve(); Mono responsePostString = responseSpecPostString.bodyToMono(String.class); - Mono responsePostMultipart = headersSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) - .retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody1 = headersSpecPost1.retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody2 = headersSpecPost2.retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody3 = headersSpecPost3.exchangeToMono(response -> { + Mono responsePostString2 = createDefaultPostResourceRequestResponse().exchangeToMono(response -> { if (response.statusCode() .equals(HttpStatus.OK)) { return response.bodyToMono(String.class); @@ -128,55 +223,37 @@ public class WebClientIntegrationTest { .flatMap(Mono::error); } }); - Mono responsePostFoo = headersSpecFooPost.retrieve() - .bodyToMono(String.class); - ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { - }; - Mono> responseGet = headersSpecGet.retrieve() - .bodyToMono(ref); - Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { - assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); - return responseHandler.bodyToMono(ref); + Mono responsePostNoBody = createDefaultPostResourceRequest().exchangeToMono(response -> { + if (response.statusCode() + .equals(HttpStatus.OK)) { + return response.bodyToMono(String.class); + } else if (response.statusCode() + .is4xxClientError()) { + return Mono.just("Error response"); + } else { + return response.createException() + .flatMap(Mono::error); + } }); - Mono responsePostOverridenBaseUri = bodySpecOverridenBaseUri.retrieve() - .bodyToMono(String.class); + Mono> responseGet = createDefaultClient().get() + .uri("/resource") + .retrieve() + .bodyToMono(MAP_RESPONSE_REF); // response assertions StepVerifier.create(responsePostString) .expectNext("processed-bodyValue") .verifyComplete(); - StepVerifier.create(responsePostMultipart) - .expectNext("processed-multipartValue1-multipartValue2") - .verifyComplete(); - StepVerifier.create(responsePostWithBody1) + StepVerifier.create(responsePostString2) .expectNext("processed-bodyValue") .verifyComplete(); - StepVerifier.create(responsePostWithBody2) - .expectNext("processed-bodyValue") - .verifyComplete(); - StepVerifier.create(responsePostWithBody3) - .expectNext("processed-bodyValue") + StepVerifier.create(responsePostNoBody) + .expectNext("Error response") .verifyComplete(); StepVerifier.create(responseGet) .expectNextMatches(nextMap -> nextMap.get("field") .equals("value")) .verifyComplete(); - StepVerifier.create(responsePostFoo) - .expectNext("processedFoo-fooName") - .verifyComplete(); - StepVerifier.create(responsePostWithNoBody) - .expectNextMatches(nextMap -> nextMap.get("error") - .equals("Bad Request")) - .verifyComplete(); - // assert sending request overriding base uri - StepVerifier.create(responsePostOverridenBaseUri) - .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() - .contains("Connection refused")) - .verify(); - // assert error plain `new Object()` as request body - StepVerifier.create(headersSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) - .expectError(CodecException.class) - .verify(); } @Test @@ -202,12 +279,53 @@ public class WebClientIntegrationTest { .verify(); } + // helper methods to create default instances + private WebClient createDefaultClient() { + return WebClient.create("http://localhost:" + port); + } + private RequestBodyUriSpec createDefaultPostRequest() { - return WebClient.create("http://localhost:" + port) - .post(); + return createDefaultClient().post(); } private RequestBodySpec createDefaultPostResourceRequest() { return createDefaultPostRequest().uri("/resource"); } + + private RequestHeadersSpec createDefaultPostResourceRequestResponse() { + return createDefaultPostResourceRequest().bodyValue(BODY_VALUE); + } + + // helper methods to retrieve a response based on different steps of the process (specs) + private Mono retrieveResponse(WebClient client) { + return client.post() + .uri("/resource") + .bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono retrieveResponse(RequestBodyUriSpec spec) { + return spec.uri("/resource") + .bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono> retrieveGetResponse(RequestHeadersUriSpec spec) { + return spec.uri("/resource") + .retrieve() + .bodyToMono(MAP_RESPONSE_REF); + } + + private Mono retrieveResponse(RequestBodySpec spec) { + return spec.bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono retrieveResponse(RequestHeadersSpec spec) { + return spec.retrieve() + .bodyToMono(String.class); + } } From b6570de6379a1818164aa401ddce8c12f787306c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:11:32 +0800 Subject: [PATCH 547/590] 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 c7b62182b5..4bd2ff9759 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -9,3 +9,4 @@ - [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) +- [Overview of Mockito MockSettings](https://www.baeldung.com/mockito-mocksettings) From fe2aab7fb9ccfbd53c54f4e867111f187d357ed4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:21:00 +0800 Subject: [PATCH 548/590] Update README.md --- spring-web-modules/spring-rest-http-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/spring-rest-http-2/README.md b/spring-web-modules/spring-rest-http-2/README.md index 97cdc2d068..b5358f888f 100644 --- a/spring-web-modules/spring-rest-http-2/README.md +++ b/spring-web-modules/spring-rest-http-2/README.md @@ -8,3 +8,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) +- [Setting a Request Timeout for a Spring REST API](https://www.baeldung.com/spring-rest-timeout) From 7634f6a6bd281294188f5056f048477659d3bfd2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:23:32 +0800 Subject: [PATCH 549/590] Update README.md --- performance-tests/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/performance-tests/README.md b/performance-tests/README.md index 27c0363010..09bf6dba1f 100644 --- a/performance-tests/README.md +++ b/performance-tests/README.md @@ -6,6 +6,7 @@ This module contains articles about performance testing. - [Performance of Java Mapping Frameworks](https://www.baeldung.com/java-performance-mapping-frameworks) - [Performance Effects of Exceptions in Java](https://www.baeldung.com/java-exceptions-performance) +- [Is Java a Compiled or Interpreted Language?](https://www.baeldung.com/java-compiled-interpreted) ### Running From a65de428fd776ed6fd10849b172ca2001834fdce Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:26:15 +0800 Subject: [PATCH 550/590] Update README.md --- spring-boot-modules/spring-boot-annotations/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-annotations/README.md b/spring-boot-modules/spring-boot-annotations/README.md index 6ead94de86..1b2bca435c 100644 --- a/spring-boot-modules/spring-boot-annotations/README.md +++ b/spring-boot-modules/spring-boot-annotations/README.md @@ -10,3 +10,4 @@ This module contains articles about Spring Boot annotations - [Spring Core Annotations](https://www.baeldung.com/spring-core-annotations) - [Spring Bean Annotations](https://www.baeldung.com/spring-bean-annotations) - [Difference Between @ComponentScan and @EnableAutoConfiguration in Spring Boot](https://www.baeldung.com/spring-componentscan-vs-enableautoconfiguration) +- [Where Should the Spring @Service Annotation Be Kept?](https://www.baeldung.com/spring-service-annotation-placement) From d11f1163abe40a87787fed5c6d0e31ee26357adf Mon Sep 17 00:00:00 2001 From: dvyshd <34768329+dvyshd@users.noreply.github.com> Date: Thu, 28 Jan 2021 23:53:49 +0000 Subject: [PATCH 551/590] BAEL-4719 - Using the Map.Entry Java Class (#10428) * BAEL-4719 Using the Map.Entry Java Class * BAEL-4719 Using the Map.Entry Java Class * BAEL-4719 Change description * BAEL-4719 Feedback from first draft --- .../java/com/baeldung/map/entry/Book.java | 35 +++++++++++++++++++ .../map/entry/MapEntryEfficiencyExample.java | 34 ++++++++++++++++++ .../map/entry/MapEntryTupleExample.java | 25 +++++++++++++ .../baeldung/map/entry/MapEntryUnitTest.java | 33 +++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java create mode 100644 java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java new file mode 100644 index 0000000000..7e47e22908 --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java @@ -0,0 +1,35 @@ +package com.baeldung.map.entry; + +public class Book { + private String title; + private String author; + + public Book(String title, String author) { + this.title = title; + this.author = author; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + @Override + public String toString() { + return "Book{" + + "title='" + title + '\'' + + ", author='" + author + '\'' + + '}'; + } +} diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java new file mode 100644 index 0000000000..d64bcb38df --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java @@ -0,0 +1,34 @@ +package com.baeldung.map.entry; + +import java.util.HashMap; +import java.util.Map; + +public class MapEntryEfficiencyExample { + + public static void main(String[] args) { + MapEntryEfficiencyExample mapEntryEfficiencyExample = new MapEntryEfficiencyExample(); + Map map = new HashMap<>(); + + map.put("Robert C. Martin", "Clean Code"); + map.put("Joshua Bloch", "Effective Java"); + + System.out.println("Iterating Using Map.KeySet - 2 operations"); + mapEntryEfficiencyExample.usingKeySet(map); + + System.out.println("Iterating Using Map.Entry - 1 operation"); + mapEntryEfficiencyExample.usingEntrySet(map); + + } + + public void usingKeySet(Map bookMap) { + for (String key : bookMap.keySet()) { + System.out.println("key: " + key + " value: " + bookMap.get(key)); + } + } + + public void usingEntrySet(Map bookMap) { + for (Map.Entry book: bookMap.entrySet()) { + System.out.println("key: " + book.getKey() + " value: " + book.getValue()); + } + } +} diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java new file mode 100644 index 0000000000..edcbd263fe --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java @@ -0,0 +1,25 @@ +package com.baeldung.map.entry; + +import java.util.*; + +public class MapEntryTupleExample { + + public static void main(String[] args) { + Map.Entry tuple1; + Map.Entry tuple2; + Map.Entry tuple3; + + tuple1 = new AbstractMap.SimpleEntry<>("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch")); + tuple2 = new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin")); + tuple3 = new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin")); + + List> orderedTuples = new ArrayList<>(); + orderedTuples.add(tuple1); + orderedTuples.add(tuple2); + orderedTuples.add(tuple3); + + for (Map.Entry tuple : orderedTuples) { + System.out.println("key: " + tuple.getKey() + " value: " + tuple.getValue()); + } + } +} diff --git a/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java b/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java new file mode 100644 index 0000000000..7340558023 --- /dev/null +++ b/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.map.entry; + +import org.junit.Test; + +import java.util.*; + +import static org.junit.Assert.assertEquals; + +public class MapEntryUnitTest { + + @Test + public void givenSimpleEntryList_whenAddDuplicateKey_thenDoesNotOverwriteExistingKey() { + List> orderedTuples = new ArrayList<>(); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch"))); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin"))); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin"))); + + assertEquals(3, orderedTuples.size()); + assertEquals("9780134685991", orderedTuples.get(0).getKey()); + assertEquals("9780132350884", orderedTuples.get(1).getKey()); + assertEquals("9780132350884", orderedTuples.get(2).getKey()); + } + + @Test + public void givenRegularMap_whenAddDuplicateKey_thenOverwritesExistingKey() { + Map entries = new HashMap<>(); + entries.put("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch")); + entries.put("9780132350884", new Book("Clean Code", "Robert C Martin")); + entries.put("9780132350884", new Book("Clean Code", "Robert C Martin")); + + assertEquals(2, entries.size()); + } +} From 28fe37cac435bc65feef7fac44c7cc1336762658 Mon Sep 17 00:00:00 2001 From: sampada07 <46674082+sampada07@users.noreply.github.com> Date: Sun, 31 Jan 2021 23:09:23 +0530 Subject: [PATCH 552/590] BAEL-3820: Multiple submit button to a Form (#10457) --- .../springmvcforms/controller/EmployeeController.java | 8 +++++++- .../src/main/webapp/WEB-INF/views/employeeHome.jsp | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java index 3ece77bb18..478b3532fe 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java @@ -26,7 +26,7 @@ public class EmployeeController { return employeeMap.get(Id); } - @RequestMapping(value = "/addEmployee", method = RequestMethod.POST) + @RequestMapping(value = "/addEmployee", method = RequestMethod.POST, params = "submit") public String submit(@Valid @ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) { if (result.hasErrors()) { return "error"; @@ -37,5 +37,11 @@ public class EmployeeController { employeeMap.put(employee.getId(), employee); return "employeeView"; } + + @RequestMapping(value = "/addEmployee", method = RequestMethod.POST, params = "cancel") + public String cancel(@Valid @ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) { + model.addAttribute("message", "You clicked cancel, please re-enter employee details:"); + return "employeeHome"; + } } diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp index 5ed572000a..82f2cbae00 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/webapp/WEB-INF/views/employeeHome.jsp @@ -7,6 +7,7 @@

    Welcome, Enter The Employee Details

    +

    ${message}

    @@ -23,7 +24,8 @@ - + +
    From f5bb8ab648a19a0214e88858e00b2bef27943f75 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Sun, 31 Jan 2021 16:40:50 +0100 Subject: [PATCH 553/590] improvement --- .../check/abstractclass/InterfaceExample.java | 4 +++ .../AbstractExampleUnitTest.java | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java new file mode 100644 index 0000000000..d226611084 --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java @@ -0,0 +1,4 @@ +package com.baeldung.reflection.check.abstractclass; + +public interface InterfaceExample { +} diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java index cb5d927c23..d9a955ca6d 100644 --- a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java +++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java @@ -1,16 +1,36 @@ package com.baeldung.reflection.check.abstractclass; -import java.lang.reflect.Modifier; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.lang.reflect.Modifier; +import java.util.Date; + class AbstractExampleUnitTest { @Test - void givenAbstractClass_whenCheckModifierIsAbstract_thenTrue() throws Exception { + void givenAbstractClass_whenCheckModifierIsAbstract_thenTrue() { Class clazz = AbstractExample.class; Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers())); } + @Test + void givenInterface_whenCheckModifierIsAbstract_thenTrue() { + Class clazz = InterfaceExample.class; + Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers())); + } + + @Test + void givenAbstractClass_whenCheckIsAbstractClass_thenTrue() { + Class clazz = AbstractExample.class; + int mod = clazz.getModifiers(); + Assertions.assertTrue(Modifier.isAbstract(mod) && !Modifier.isInterface(mod)); + } + + @Test + void givenConcreteClass_whenCheckIsAbstractClass_thenFalse() { + Class clazz = Date.class; + int mod = clazz.getModifiers(); + Assertions.assertFalse(Modifier.isAbstract(mod) && !Modifier.isInterface(mod)); + } } From b689760b0752e9e3f6697ec699eee59313a5578d Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 1 Feb 2021 11:04:42 +0530 Subject: [PATCH 554/590] JAVA-4312: Update deprecations in spring-5-reactive module --- .../main/java/com/baeldung/functional/FormHandler.java | 4 ++-- .../functional/FunctionalSpringBootApplication.java | 4 ++-- .../baeldung/functional/FunctionalWebApplication.java | 4 ++-- .../main/java/com/baeldung/functional/RootServlet.java | 6 +++--- .../errorhandling/GlobalErrorWebExceptionHandler.java | 10 ++++++---- .../reactive/errorhandling/handlers/Handler1.java | 2 +- .../reactive/errorhandling/handlers/Handler2.java | 4 ++-- .../reactive/errorhandling/handlers/Handler3.java | 4 ++-- .../ExploreSpring5URLPatternUsingRouterFunctions.java | 10 +++++----- .../com/baeldung/reactive/urlmatch/FormHandler.java | 4 ++-- .../reactive/urlmatch/FunctionalWebApplication.java | 4 ++-- .../FunctionalWebApplicationIntegrationTest.java | 6 ++---- .../errorhandling/ErrorHandlingIntegrationTest.java | 4 ++-- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java index c4f8c9f41f..2b415d5f1e 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java @@ -11,7 +11,7 @@ import java.util.concurrent.atomic.AtomicLong; import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; import static org.springframework.web.reactive.function.BodyExtractors.toFormData; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.ServerResponse.ok; public class FormHandler { @@ -29,7 +29,7 @@ public class FormHandler { Mono handleUpload(ServerRequest request) { return request.body(toDataBuffers()) .collectList() - .flatMap(dataBuffers -> ok().body(fromObject(extractData(dataBuffers).toString()))); + .flatMap(dataBuffers -> ok().body(fromValue(extractData(dataBuffers).toString()))); } private AtomicLong extractData(List dataBuffers) { diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java index 9cbc1b7669..9bfd0afe7e 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java @@ -1,6 +1,6 @@ package com.baeldung.functional; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; import static org.springframework.web.reactive.function.server.RequestPredicates.path; @@ -44,7 +44,7 @@ public class FunctionalSpringBootApplication { .doOnNext(actors::add) .then(ok().build())); - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))) + return route(GET("/test"), serverRequest -> ok().body(fromValue("helloworld"))) .andRoute(POST("/login"), formHandler::handleLogin) .andRoute(POST("/upload"), formHandler::handleUpload) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java index b89f74ad92..9930ffb474 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java @@ -1,6 +1,6 @@ package com.baeldung.functional; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; import static org.springframework.web.reactive.function.server.RequestPredicates.accept; @@ -42,7 +42,7 @@ public class FunctionalWebApplication { .doOnNext(actors::add) .then(ok().build())); - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) + return route(GET("/test"), serverRequest -> ok().body(fromValue("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) .andRoute(POST("/upload"), formHandler::handleUpload) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) .andNest(accept(MediaType.APPLICATION_JSON), restfulRouter) diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java b/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java index 8fe24821de..6c36b7fa03 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java @@ -2,7 +2,7 @@ package com.baeldung.functional; import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; import static org.springframework.web.reactive.function.BodyExtractors.toFormData; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; import static org.springframework.web.reactive.function.server.RequestPredicates.path; @@ -46,7 +46,7 @@ public class RootServlet extends ServletHttpHandlerAdapter { private static RouterFunction routingFunction() { - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), serverRequest -> serverRequest.body(toFormData()) + return route(GET("/test"), serverRequest -> ok().body(fromValue("helloworld"))).andRoute(POST("/login"), serverRequest -> serverRequest.body(toFormData()) .map(MultiValueMap::toSingleValueMap) .map(formData -> { System.out.println("form data: " + formData.toString()); @@ -65,7 +65,7 @@ public class RootServlet extends ServletHttpHandlerAdapter { dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() .array().length)); System.out.println("data length:" + atomicLong.get()); - return ok().body(fromObject(atomicLong.toString())) + return ok().body(fromValue(atomicLong.toString())) .block(); })) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java index 051e4b8df5..4f3f1795da 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java @@ -2,7 +2,8 @@ package com.baeldung.reactive.errorhandling; import java.util.Map; -import org.springframework.boot.autoconfigure.web.ResourceProperties; + +import org.springframework.boot.autoconfigure.web.WebProperties; import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.reactive.error.ErrorAttributes; @@ -18,6 +19,7 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; + import reactor.core.publisher.Mono; @Component @@ -26,7 +28,7 @@ public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHan public GlobalErrorWebExceptionHandler(GlobalErrorAttributes g, ApplicationContext applicationContext, ServerCodecConfigurer serverCodecConfigurer) { - super(g, new ResourceProperties(), applicationContext); + super(g, new WebProperties.Resources(), applicationContext); super.setMessageWriters(serverCodecConfigurer.getWriters()); super.setMessageReaders(serverCodecConfigurer.getReaders()); } @@ -41,8 +43,8 @@ public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHan final Map errorPropertiesMap = getErrorAttributes(request, ErrorAttributeOptions.defaults()); return ServerResponse.status(HttpStatus.BAD_REQUEST) - .contentType(MediaType.APPLICATION_JSON_UTF8) - .body(BodyInserters.fromObject(errorPropertiesMap)); + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue(errorPropertiesMap)); } } diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler1.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler1.java index 87b78a4654..c71c8ecac0 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler1.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler1.java @@ -14,7 +14,7 @@ public class Handler1 { return sayHello(request).onErrorReturn("Hello, Stranger") .flatMap(s -> ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .syncBody(s)); + .bodyValue(s)); } private Mono sayHello(ServerRequest request) { diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler2.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler2.java index 12172a0f54..92e881543e 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler2.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler2.java @@ -15,11 +15,11 @@ public Mono handleRequest2(ServerRequest request) { sayHello(request) .flatMap(s -> ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .syncBody(s)) + .bodyValue(s)) .onErrorResume(e -> sayHelloFallback() .flatMap(s -> ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .syncBody(s))); + .bodyValue(s))); } private Mono sayHello(ServerRequest request) { diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler3.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler3.java index e95b039cce..8c988a6633 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler3.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/handlers/Handler3.java @@ -15,11 +15,11 @@ public class Handler3 { sayHello(request) .flatMap(s -> ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .syncBody(s)) + .bodyValue(s)) .onErrorResume(e -> (Mono.just("Hi, I looked around for your name but found: " + e.getMessage())).flatMap(s -> ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .syncBody(s))); + .bodyValue(s))); } private Mono sayHello(ServerRequest request) { diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java index 115a057915..34abada2f1 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java @@ -1,6 +1,6 @@ package com.baeldung.reactive.urlmatch; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RouterFunctions.route; import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; @@ -24,10 +24,10 @@ public class ExploreSpring5URLPatternUsingRouterFunctions { private RouterFunction routingFunction() { - return route(GET("/p?ths"), serverRequest -> ok().body(fromObject("/p?ths"))).andRoute(GET("/test/{*id}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("id")))) - .andRoute(GET("/*card"), serverRequest -> ok().body(fromObject("/*card path was accessed"))) - .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) - .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromObject("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) + return route(GET("/p?ths"), serverRequest -> ok().body(fromValue("/p?ths"))).andRoute(GET("/test/{*id}"), serverRequest -> ok().body(fromValue(serverRequest.pathVariable("id")))) + .andRoute(GET("/*card"), serverRequest -> ok().body(fromValue("/*card path was accessed"))) + .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromValue(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) + .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromValue("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) .and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/"))); } diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java index 0781230379..7b1fb06459 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java @@ -11,7 +11,7 @@ import java.util.concurrent.atomic.AtomicLong; import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; import static org.springframework.web.reactive.function.BodyExtractors.toFormData; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.ServerResponse.ok; public class FormHandler { @@ -29,7 +29,7 @@ public class FormHandler { Mono handleUpload(ServerRequest request) { return request.body(toDataBuffers()) .collectList() - .flatMap(dataBuffers -> ok().body(fromObject(extractData(dataBuffers).toString()))); + .flatMap(dataBuffers -> ok().body(fromValue(extractData(dataBuffers).toString()))); } private AtomicLong extractData(List dataBuffers) { diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java index 2ea5420a2b..6cec902a0d 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java @@ -1,6 +1,6 @@ package com.baeldung.reactive.urlmatch; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; import static org.springframework.web.reactive.function.server.RequestPredicates.path; @@ -40,7 +40,7 @@ public class FunctionalWebApplication { .doOnNext(actors::add) .then(ok().build())); - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) + return route(GET("/test"), serverRequest -> ok().body(fromValue("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) .andRoute(POST("/upload"), formHandler::handleUpload) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) .andNest(path("/actor"), restfulRouter) diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java index 5c0b4f69d0..3164adbe4a 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java @@ -1,17 +1,15 @@ package com.baeldung.functional; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromValue; import static org.springframework.web.reactive.function.BodyInserters.fromResource; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.springframework.boot.web.server.WebServer; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -115,7 +113,7 @@ public class FunctionalWebApplicationIntegrationTest { client.post() .uri("/actor") - .body(fromObject(new Actor("Clint", "Eastwood"))) + .body(fromValue(new Actor("Clint", "Eastwood"))) .exchange() .expectStatus() .isOk(); diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java index 3bbbed0d77..38443a4eac 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java @@ -133,7 +133,7 @@ public class ErrorHandlingIntegrationTest { .expectStatus() .isBadRequest() .expectHeader() - .contentType(MediaType.APPLICATION_JSON_UTF8) + .contentType(MediaType.APPLICATION_JSON) .expectBody() .jsonPath("$.message") .isNotEmpty() @@ -164,7 +164,7 @@ public class ErrorHandlingIntegrationTest { .expectStatus() .isBadRequest() .expectHeader() - .contentType(MediaType.APPLICATION_JSON_UTF8) + .contentType(MediaType.APPLICATION_JSON) .expectBody() .jsonPath("$.message") .isNotEmpty() From e07bcb53153e8d8929c75d4979958fc1823f7fbe Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 1 Feb 2021 17:44:05 +0100 Subject: [PATCH 555/590] BAEL-2674 - Upgrade the Okhttp article (#10462) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings * BAEL-4756 - Mockito MockSettings - fix spelling * BAEL-2674 - Upgrade the Okhttp article Co-authored-by: Jonathan Cook --- libraries-http/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-http/pom.xml b/libraries-http/pom.xml index 74e00a7291..257cb988d6 100644 --- a/libraries-http/pom.xml +++ b/libraries-http/pom.xml @@ -120,7 +120,7 @@ 4.5.3 3.6.2 - 3.14.2 + 4.9.1 1.23.0 2.2.0 2.3.0 From a50cec28827e1ef662471f1792883f5ebed98bdb Mon Sep 17 00:00:00 2001 From: MeenaGawande Date: Tue, 2 Feb 2021 11:25:34 +0530 Subject: [PATCH 556/590] [BAEL-4715] Java HashMap Load Factor Fixed HashMap creation and few entries --- .../hashmap/loadfactor/HashMapLoadFactorUnitTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java index 89e2a189fe..94967a4905 100644 --- a/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java +++ b/core-java-modules/core-java-collections-maps-3/src/test/java/com/baeldung/map/hashmap/loadfactor/HashMapLoadFactorUnitTest.java @@ -10,8 +10,8 @@ public class HashMapLoadFactorUnitTest { @Test public void whenCreateMapWithDefaultParam_thenSucces() { - Map mapWithDefaultParams = new HashMap(); - mapWithDefaultParams.put("1", "One"); + Map mapWithDefaultParams = new HashMap<>(); + mapWithDefaultParams.put("1", "one"); mapWithDefaultParams.put("2", "two"); mapWithDefaultParams.put("3", "three"); mapWithDefaultParams.put("4", "four"); @@ -22,8 +22,8 @@ public class HashMapLoadFactorUnitTest { @Test public void whenCreateMapWithInitialCapacity_thenSucces() { - Map mapWithInitialCapacity = new HashMap(5); - mapWithInitialCapacity.put("1", "One"); + Map mapWithInitialCapacity = new HashMap<>(5); + mapWithInitialCapacity.put("1", "one"); mapWithInitialCapacity.put("2", "two"); mapWithInitialCapacity.put("3", "three"); @@ -32,7 +32,7 @@ public class HashMapLoadFactorUnitTest { @Test public void whenCreateMapWithInitialCapacityAndLF_thenSucces() { - Map mapWithInitialCapacityAndLF = new HashMap(5, 0.5f); + Map mapWithInitialCapacityAndLF = new HashMap<>(5, 0.5f); mapWithInitialCapacityAndLF.put("1", "one"); mapWithInitialCapacityAndLF.put("2", "two"); mapWithInitialCapacityAndLF.put("3", "three"); From 387ee88c2d3b5f746b062065f062751db418060e Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Tue, 2 Feb 2021 10:32:22 +0100 Subject: [PATCH 557/590] upgrade to springboot 2.3.2 and fix application properties --- spring-boot-modules/spring-boot-actuator/pom.xml | 2 +- .../src/main/resources/application.properties | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-actuator/pom.xml b/spring-boot-modules/spring-boot-actuator/pom.xml index 18da6d3a9a..a808b8cb1b 100644 --- a/spring-boot-modules/spring-boot-actuator/pom.xml +++ b/spring-boot-modules/spring-boot-actuator/pom.xml @@ -11,7 +11,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.0.RELEASE + 2.3.2.RELEASE diff --git a/spring-boot-modules/spring-boot-actuator/src/main/resources/application.properties b/spring-boot-modules/spring-boot-actuator/src/main/resources/application.properties index 00100d6d97..de7be417a8 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-actuator/src/main/resources/application.properties @@ -1,4 +1,6 @@ -management.health.probes.enabled=true +management.endpoint.health.probes.enabled=true +management.health.livenessState.enabled=true +management.health.readinessState.enabled=true management.endpoint.health.show-details=always management.endpoint.health.status.http-mapping.down=500 management.endpoint.health.status.http-mapping.out_of_service=503 @@ -8,4 +10,4 @@ management.endpoint.health.status.http-mapping.warning=500 info.app.name=Spring Sample Application info.app.description=This is my first spring boot application G1 info.app.version=1.0.0 -info.java-vendor = ${java.specification.vendor} \ No newline at end of file +info.java-vendor = ${java.specification.vendor} From 7d78e63edfdd759800d1b9e25605db0cd87c0b1a Mon Sep 17 00:00:00 2001 From: osser-sam <46674082+osser-sam@users.noreply.github.com> Date: Wed, 3 Feb 2021 01:12:29 +0530 Subject: [PATCH 558/590] JAVA-4277: Fix tests in spring-resttemplate module (#10447) * JAVA-4277: Fix tests in spring-resttemplate module * JAVA-4277: Moved article from spring-resttemplate to spring-resttemplate-2 --- .../spring-resttemplate-2/README.md | 1 + .../spring-resttemplate-2/pom.xml | 2 +- .../redirect/RedirectController.java | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 36 +++++++++++++++++++ .../src/main/webapp/WEB-INF/spring-views.xml | 10 ++++++ .../RedirectControllerIntegrationTest.java | 0 .../spring-resttemplate/pom.xml | 4 +-- .../web/service => mock}/EmployeeService.java | 2 +- .../client/TestRestTemplateBasicLiveTest.java | 1 + ...eServiceMockRestServiceServerUnitTest.java | 5 +-- .../EmployeeServiceUnitTest.java | 5 +-- .../RestTemplateBasicLiveTest.java | 1 + 12 files changed, 59 insertions(+), 8 deletions(-) rename spring-web-modules/{spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java (100%) create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/api-servlet.xml create mode 100644 spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/spring-views.xml rename spring-web-modules/{spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java (100%) rename spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/{resttemplate/web/service => mock}/EmployeeService.java (95%) rename spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/{web/service => mock}/EmployeeServiceMockRestServiceServerUnitTest.java (96%) rename spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/{web/service => mock}/EmployeeServiceUnitTest.java (92%) diff --git a/spring-web-modules/spring-resttemplate-2/README.md b/spring-web-modules/spring-resttemplate-2/README.md index a903757bb4..b2000e0481 100644 --- a/spring-web-modules/spring-resttemplate-2/README.md +++ b/spring-web-modules/spring-resttemplate-2/README.md @@ -10,3 +10,4 @@ This module contains articles about Spring RestTemplate - [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) - [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) - [Get list of JSON objects with Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-json-list) +- [A Guide To Spring Redirects](https://www.baeldung.com/spring-redirect-and-forward) diff --git a/spring-web-modules/spring-resttemplate-2/pom.xml b/spring-web-modules/spring-resttemplate-2/pom.xml index 04be058638..158380b403 100644 --- a/spring-web-modules/spring-resttemplate-2/pom.xml +++ b/spring-web-modules/spring-resttemplate-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - parent-boot-2/pom.xml + ../../parent-boot-2/pom.xml diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java similarity index 100% rename from spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java rename to spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java diff --git a/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/api-servlet.xml new file mode 100644 index 0000000000..ed37a962e9 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/api-servlet.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + /WEB-INF/spring-views.xml + + + + + + + + + + + + + diff --git a/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/spring-views.xml b/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/spring-views.xml new file mode 100644 index 0000000000..2944828d6d --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/main/webapp/WEB-INF/spring-views.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java similarity index 100% rename from spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java rename to spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java diff --git a/spring-web-modules/spring-resttemplate/pom.xml b/spring-web-modules/spring-resttemplate/pom.xml index c0f266fd62..1db6b5db57 100644 --- a/spring-web-modules/spring-resttemplate/pom.xml +++ b/spring-web-modules/spring-resttemplate/pom.xml @@ -188,7 +188,7 @@ cargo-maven2-plugin ${cargo-maven2-plugin.version} - + true tomcat8x embedded @@ -297,7 +297,7 @@ 20.0 - 1.6.0 + 1.6.1 3.0.4 diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/mock/EmployeeService.java similarity index 95% rename from spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/mock/EmployeeService.java index 18dff3db1b..16180a3640 100644 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java +++ b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/mock/EmployeeService.java @@ -1,4 +1,4 @@ -package com.baeldung.resttemplate.web.service; +package com.baeldung.mock; import com.baeldung.resttemplate.web.model.Employee; import org.slf4j.Logger; diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java index 9f4b3c9b35..406dd5979b 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java @@ -18,6 +18,7 @@ import org.springframework.web.client.RestTemplate; import okhttp3.Request; import okhttp3.RequestBody; +// This test needs RestTemplateConfigurationApplication to be up and running public class TestRestTemplateBasicLiveTest { private RestTemplate restTemplate; diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceMockRestServiceServerUnitTest.java similarity index 96% rename from spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceMockRestServiceServerUnitTest.java index ee01cb6a50..309e0635a4 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceMockRestServiceServerUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.web.service; +package com.baeldung.mock; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; @@ -7,8 +7,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat import java.net.URI; import com.baeldung.SpringTestConfig; +import com.baeldung.mock.EmployeeService; import com.baeldung.resttemplate.web.model.Employee; -import com.baeldung.resttemplate.web.service.EmployeeService; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceUnitTest.java similarity index 92% rename from spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceUnitTest.java index 6eb040414b..9a992f390a 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/mock/EmployeeServiceUnitTest.java @@ -1,7 +1,8 @@ -package com.baeldung.web.service; +package com.baeldung.mock; +import com.baeldung.mock.EmployeeService; import com.baeldung.resttemplate.web.model.Employee; -import com.baeldung.resttemplate.web.service.EmployeeService; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java index 0dab124316..8d52394dd1 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java @@ -38,6 +38,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.google.common.base.Charsets; +// This test needs RestTemplateConfigurationApplication to be up and running public class RestTemplateBasicLiveTest { private RestTemplate restTemplate; From cfbdbe1001aa330905eb15c0c60c0b27d80fcc54 Mon Sep 17 00:00:00 2001 From: osser-sam <46674082+osser-sam@users.noreply.github.com> Date: Wed, 3 Feb 2021 01:16:00 +0530 Subject: [PATCH 559/590] JAVA-4012: fix failing test (#10455) --- .../zoneddatetime/config/MongoConfig.java | 22 ------------------- .../src/main/resources/mongoConfig.xml | 4 ++-- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java index 3cfefa099c..4eb3872e34 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java @@ -1,11 +1,8 @@ package com.baeldung.zoneddatetime.config; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; @@ -13,12 +10,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter; import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter; -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -@Configuration @EnableMongoRepositories(basePackages = { "com.baeldung" }) public class MongoConfig extends AbstractMongoClientConfiguration { @@ -29,20 +21,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { return "test"; } - @Override - public MongoClient mongoClient() { - final ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/test"); - final MongoClientSettings mongoClientSettings = MongoClientSettings.builder() - .applyConnectionString(connectionString) - .build(); - return MongoClients.create(mongoClientSettings); - } - - @Override - public Collection getMappingBasePackages() { - return Collections.singleton("com.baeldung"); - } - @Override public MongoCustomConversions customConversions() { converters.add(new ZonedDateTimeReadConverter()); diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml index c5b9068de3..7a10ef6a69 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml @@ -24,8 +24,8 @@ - - + + \ No newline at end of file From 6f2e23e1665ce746d66ca779ba74e3f70b37193f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 3 Feb 2021 23:59:04 +0800 Subject: [PATCH 560/590] Update README.md --- core-java-modules/core-java-jvm-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md index 36cafd3288..ccca3a11ac 100644 --- a/core-java-modules/core-java-jvm-2/README.md +++ b/core-java-modules/core-java-jvm-2/README.md @@ -11,4 +11,5 @@ This module contains articles about working with the Java Virtual Machine (JVM). - [Where Is the Array Length Stored in JVM?](https://www.baeldung.com/java-jvm-array-length) - [Memory Address of Objects in Java](https://www.baeldung.com/java-object-memory-address) - [List All Classes Loaded in a Specific Class Loader](https://www.baeldung.com/java-list-classes-class-loader) +- [An Introduction to the Constant Pool in the JVM](https://www.baeldung.com/jvm-constant-pool) - More articles: [[<-- prev]](/core-java-modules/core-java-jvm) From 5774d53d0b5f45937ed26166ce0856dc791bb5b7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:02:05 +0800 Subject: [PATCH 561/590] Update README.md --- java-collections-maps-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-collections-maps-3/README.md b/java-collections-maps-3/README.md index 39ac8575fa..bd1029c9cf 100644 --- a/java-collections-maps-3/README.md +++ b/java-collections-maps-3/README.md @@ -2,3 +2,4 @@ - [Java Map With Case-Insensitive Keys](https://www.baeldung.com/java-map-with-case-insensitive-keys) - [Using a Byte Array as Map Key in Java](https://www.baeldung.com/java-map-key-byte-array) +- [Using the Map.Entry Java Class](https://www.baeldung.com/java-map-entry) From 3ff1ba2185ac0571764d0e148ebc933cb4ba1652 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:03:53 +0800 Subject: [PATCH 562/590] Update README.md --- core-java-modules/core-java-lang-oop-generics/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-oop-generics/README.md b/core-java-modules/core-java-lang-oop-generics/README.md index 74b9df7c65..9c9080ece3 100644 --- a/core-java-modules/core-java-lang-oop-generics/README.md +++ b/core-java-modules/core-java-lang-oop-generics/README.md @@ -7,3 +7,4 @@ This module contains articles about generics in Java - [Type Erasure in Java Explained](https://www.baeldung.com/java-type-erasure) - [Raw Types in Java](https://www.baeldung.com/raw-types-java) - [Super Type Tokens in Java Generics](https://www.baeldung.com/java-super-type-tokens) +- [Java Warning “unchecked conversion”](https://www.baeldung.com/java-unchecked-conversion) From 2a365df31834bb042f9039cb3fb082a478e5a7f9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:07:17 +0800 Subject: [PATCH 563/590] Update README.md --- spring-aop/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-aop/README.md b/spring-aop/README.md index 91cccbd114..c92e132d1e 100644 --- a/spring-aop/README.md +++ b/spring-aop/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring aspect oriented programming (AOP) - [Introduction to Pointcut Expressions in Spring](https://www.baeldung.com/spring-aop-pointcut-tutorial) - [Introduction to Advice Types in Spring](https://www.baeldung.com/spring-aop-advice-tutorial) - [When Does Java Throw UndeclaredThrowableException?](https://www.baeldung.com/java-undeclaredthrowableexception) +- [Get Advised Method Info in Spring AOP](https://www.baeldung.com/spring-aop-get-advised-method-info) From 1bc84889aa660fce20c3ad2f6835e193eb4727e0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:09:00 +0800 Subject: [PATCH 564/590] Update README.md --- core-java-modules/core-java-concurrency-advanced-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-concurrency-advanced-4/README.md b/core-java-modules/core-java-concurrency-advanced-4/README.md index 98f2894515..5b93cec0dd 100644 --- a/core-java-modules/core-java-concurrency-advanced-4/README.md +++ b/core-java-modules/core-java-concurrency-advanced-4/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Binary Semaphore vs Reentrant Lock](https://www.baeldung.com/java-binary-semaphore-vs-reentrant-lock) +- [Bad Practices With Synchronization](https://www.baeldung.com/java-synchronization-bad-practices) From 44552d1fa42f1413194a0af1a09a505655c6fe87 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:10:36 +0800 Subject: [PATCH 565/590] Update README.md --- spring-5-reactive-client/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive-client/README.md b/spring-5-reactive-client/README.md index eebdc23aed..b247a1669b 100644 --- a/spring-5-reactive-client/README.md +++ b/spring-5-reactive-client/README.md @@ -11,3 +11,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls) - [Mocking a WebClient in Spring](https://www.baeldung.com/spring-mocking-webclient) - [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) +- [Get List of JSON Objects with WebClient](https://www.baeldung.com/spring-webclient-json-list) From d779223e57296fab6c8895baaaa46c54f7c874a6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:13:24 +0800 Subject: [PATCH 566/590] Update README.md --- spring-web-modules/spring-resttemplate-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/spring-resttemplate-2/README.md b/spring-web-modules/spring-resttemplate-2/README.md index b2000e0481..54fad5e01b 100644 --- a/spring-web-modules/spring-resttemplate-2/README.md +++ b/spring-web-modules/spring-resttemplate-2/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring RestTemplate - [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) - [Get list of JSON objects with Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-json-list) - [A Guide To Spring Redirects](https://www.baeldung.com/spring-redirect-and-forward) +- [Spring RestTemplate Exception: “Not enough variables available to expand”](https://www.baeldung.com/spring-not-enough-variables-available) From bb5c2386317c533b759b8bbb4015ec5fe50c8495 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 4 Feb 2021 00:14:49 +0800 Subject: [PATCH 567/590] Update README.md --- spring-web-modules/spring-mvc-forms-jsp/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/spring-mvc-forms-jsp/README.md b/spring-web-modules/spring-mvc-forms-jsp/README.md index 2c077f5171..afbf7afe40 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/README.md +++ b/spring-web-modules/spring-mvc-forms-jsp/README.md @@ -7,3 +7,4 @@ This module contains articles about Spring MVC Forms using JSP - [Getting Started with Forms in Spring MVC](https://www.baeldung.com/spring-mvc-form-tutorial) - [Form Validation with AngularJS and Spring MVC](https://www.baeldung.com/validation-angularjs-spring-mvc) - [A Guide to the JSTL Library](https://www.baeldung.com/jstl) +- [Multiple Submit Buttons on a Form](https://www.baeldung.com/spring-form-multiple-submit-buttons) From 23ee2df79e36362ea7aced96489afbaccb3158e9 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 8 Feb 2021 22:48:54 +0100 Subject: [PATCH 568/590] JAVA-4395: Fix typo in addTagsOfOtherProduct method --- .../src/main/java/com/baeldung/map/Product.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java index 5559895730..09b1a8847d 100644 --- a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java +++ b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java @@ -26,7 +26,7 @@ public class Product { return tags; } - public Product addTagsOfOtherProdcut(Product product) { + public Product addTagsOfOtherProduct(Product product) { this.tags.addAll(product.getTags()); return this; } @@ -100,11 +100,11 @@ public class Product { HashMap productsByName = new HashMap<>(); Product eBike2 = new Product("E-Bike", "A bike with a battery"); eBike2.getTags().add("sport"); - productsByName.merge("E-Bike", eBike2, Product::addTagsOfOtherProdcut); + productsByName.merge("E-Bike", eBike2, Product::addTagsOfOtherProduct); //Prior to Java 8: if(productsByName.containsKey("E-Bike")) { - productsByName.get("E-Bike").addTagsOfOtherProdcut(eBike2); + productsByName.get("E-Bike").addTagsOfOtherProduct(eBike2); } else { productsByName.put("E-Bike", eBike2); } @@ -117,7 +117,7 @@ public class Product { productsByName.compute("E-Bike", (k,v) -> { if(v != null) { - return v.addTagsOfOtherProdcut(eBike2); + return v.addTagsOfOtherProduct(eBike2); } else { return eBike2; } @@ -125,7 +125,7 @@ public class Product { //Prior to Java 8: if(productsByName.containsKey("E-Bike")) { - productsByName.get("E-Bike").addTagsOfOtherProdcut(eBike2); + productsByName.get("E-Bike").addTagsOfOtherProduct(eBike2); } else { productsByName.put("E-Bike", eBike2); } From 6c5c6fe3174e4a70a9049e6157401c7f7a4cfbbd Mon Sep 17 00:00:00 2001 From: Amy DeGregorio Date: Mon, 8 Feb 2021 21:11:25 -0500 Subject: [PATCH 569/590] BAEL-4331 (#10460) * BAEL-4331 * Add an integration test --- spring-boot-modules/pom.xml | 1 + .../spring-boot-runtime-2/README.md | 6 ++ .../spring-boot-runtime-2/pom.xml | 66 +++++++++++++++++++ .../heap/HeapSizeDemoApplication.java | 12 ++++ .../java/com/baeldung/heap/MemoryStats.java | 31 +++++++++ .../baeldung/heap/MemoryStatusController.java | 20 ++++++ .../resources/heap/spring-boot-runtime-2.conf | 1 + ...MemoryStatusControllerIntegrationTest.java | 32 +++++++++ 8 files changed, 169 insertions(+) create mode 100644 spring-boot-modules/spring-boot-runtime-2/README.md create mode 100644 spring-boot-modules/spring-boot-runtime-2/pom.xml create mode 100644 spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/HeapSizeDemoApplication.java create mode 100644 spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStats.java create mode 100644 spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStatusController.java create mode 100644 spring-boot-modules/spring-boot-runtime-2/src/main/resources/heap/spring-boot-runtime-2.conf create mode 100644 spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/heap/MemoryStatusControllerIntegrationTest.java diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index ee088c357a..263d2af089 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -62,6 +62,7 @@ spring-boot-properties-3 spring-boot-property-exp spring-boot-runtime + spring-boot-runtime-2 spring-boot-security spring-boot-springdoc spring-boot-swagger diff --git a/spring-boot-modules/spring-boot-runtime-2/README.md b/spring-boot-modules/spring-boot-runtime-2/README.md new file mode 100644 index 0000000000..f997f2473d --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/README.md @@ -0,0 +1,6 @@ +## Spring Boot Runtime 2 + +This module contains articles about administering a Spring Boot runtime + +### Relevant Articles: + - diff --git a/spring-boot-modules/spring-boot-runtime-2/pom.xml b/spring-boot-modules/spring-boot-runtime-2/pom.xml new file mode 100644 index 0000000000..8f6351165a --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ + + + spring-boot-runtime-2 + jar + + spring-boot-runtime-2 + Demo project for Spring Boot + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + ${project.artifactId} + + + src/main/resources/heap + ${project.build.directory} + true + + ${project.name}.conf + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.baeldung.heap.HeapSizeDemoApplication + + + + + true + + -Xms256m + -Xmx1g + + + + + + diff --git a/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/HeapSizeDemoApplication.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/HeapSizeDemoApplication.java new file mode 100644 index 0000000000..60d4bf7bab --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/HeapSizeDemoApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.heap; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HeapSizeDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(HeapSizeDemoApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStats.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStats.java new file mode 100644 index 0000000000..0d2f471a12 --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStats.java @@ -0,0 +1,31 @@ +package com.baeldung.heap; + +public class MemoryStats { + private long heapSize; + private long heapMaxSize; + private long heapFreeSize; + + public long getHeapSize() { + return heapSize; + } + + public void setHeapSize(long heapSize) { + this.heapSize = heapSize; + } + + public long getHeapMaxSize() { + return heapMaxSize; + } + + public void setHeapMaxSize(long heapMaxSize) { + this.heapMaxSize = heapMaxSize; + } + + public long getHeapFreeSize() { + return heapFreeSize; + } + + public void setHeapFreeSize(long heapFreeSize) { + this.heapFreeSize = heapFreeSize; + } +} diff --git a/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStatusController.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStatusController.java new file mode 100644 index 0000000000..293747fbd1 --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/heap/MemoryStatusController.java @@ -0,0 +1,20 @@ +package com.baeldung.heap; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MemoryStatusController { + + @GetMapping("memory-status") + public MemoryStats getMemoryStatistics() { + MemoryStats stats = new MemoryStats(); + stats.setHeapSize(Runtime.getRuntime() + .totalMemory()); + stats.setHeapMaxSize(Runtime.getRuntime() + .maxMemory()); + stats.setHeapFreeSize(Runtime.getRuntime() + .freeMemory()); + return stats; + } +} diff --git a/spring-boot-modules/spring-boot-runtime-2/src/main/resources/heap/spring-boot-runtime-2.conf b/spring-boot-modules/spring-boot-runtime-2/src/main/resources/heap/spring-boot-runtime-2.conf new file mode 100644 index 0000000000..3bfde4e3d9 --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/src/main/resources/heap/spring-boot-runtime-2.conf @@ -0,0 +1 @@ +JAVA_OPTS="-Xms512m -Xmx1024m" \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/heap/MemoryStatusControllerIntegrationTest.java b/spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/heap/MemoryStatusControllerIntegrationTest.java new file mode 100644 index 0000000000..2e744285d8 --- /dev/null +++ b/spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/heap/MemoryStatusControllerIntegrationTest.java @@ -0,0 +1,32 @@ +package com.baeldung.heap; + +import static org.hamcrest.Matchers.notANumber; +import static org.hamcrest.Matchers.not; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@WebMvcTest(MemoryStatusController.class) +public class MemoryStatusControllerIntegrationTest { + + @Autowired + private MockMvc mvc; + + @Test + public void whenGetMemoryStatistics_thenReturnJsonArray() throws Exception { + mvc.perform(get("/memory-status").contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("heapSize", not(notANumber()))) + .andExpect(jsonPath("heapMaxSize", not(notANumber()))) + .andExpect(jsonPath("heapFreeSize", not(notANumber()))); + } +} From 4f0173ebae5eb50b8f5423f6501dbd291e6df7f9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:08:46 +0800 Subject: [PATCH 570/590] Update README.md --- spring-web-modules/spring-resttemplate-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-web-modules/spring-resttemplate-2/README.md b/spring-web-modules/spring-resttemplate-2/README.md index 54fad5e01b..ace7ae817b 100644 --- a/spring-web-modules/spring-resttemplate-2/README.md +++ b/spring-web-modules/spring-resttemplate-2/README.md @@ -10,5 +10,4 @@ This module contains articles about Spring RestTemplate - [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) - [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests) - [Get list of JSON objects with Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-json-list) -- [A Guide To Spring Redirects](https://www.baeldung.com/spring-redirect-and-forward) - [Spring RestTemplate Exception: “Not enough variables available to expand”](https://www.baeldung.com/spring-not-enough-variables-available) From 9ed2982f8f0d9691dcc0ad7366cb1d94b456286a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:12:06 +0800 Subject: [PATCH 571/590] Update README.md --- spring-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5/README.md b/spring-5/README.md index cce18bedf8..845d602480 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring 5 - [Spring Assert Statements](https://www.baeldung.com/spring-assert) - [Difference between \ vs \](https://www.baeldung.com/spring-contextannotation-contextcomponentscan) - [Finding the Spring Version](https://www.baeldung.com/spring-find-version) +- [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) From 59da123a98e892e10eea60c2580a367ef76d1d85 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:15:15 +0800 Subject: [PATCH 572/590] Create README.md --- spring-5/src/test/java/com/baeldung/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-5/src/test/java/com/baeldung/README.md diff --git a/spring-5/src/test/java/com/baeldung/README.md b/spring-5/src/test/java/com/baeldung/README.md new file mode 100644 index 0000000000..0ff61914d5 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) From 944c965952a4a06f9b5663961927303c6a0213f7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:17:27 +0800 Subject: [PATCH 573/590] Update README.md --- core-java-modules/core-java-lang-math-3/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md index dda3013407..1dd3a3c7e0 100644 --- a/core-java-modules/core-java-lang-math-3/README.md +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -4,6 +4,5 @@ ### Relevant articles: -- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) - [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) From 9e867ffc0d35523c5a7ea8b9a2b7e57f6ad00cab Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:20:19 +0800 Subject: [PATCH 574/590] Update README.md --- spring-boot-modules/spring-boot-data-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md index c21ce02a2e..d5020ce354 100644 --- a/spring-boot-modules/spring-boot-data-2/README.md +++ b/spring-boot-modules/spring-boot-data-2/README.md @@ -1,4 +1,3 @@ ### Relevant Articles: - [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper) -- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) From 43efec8e232a3450cf5c8f3dcbe3912ec223594c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:44:24 +0800 Subject: [PATCH 575/590] Update README.md --- spring-web-modules/spring-mvc-basics-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-web-modules/spring-mvc-basics-4/README.md b/spring-web-modules/spring-mvc-basics-4/README.md index d0bca4a303..211564a363 100644 --- a/spring-web-modules/spring-mvc-basics-4/README.md +++ b/spring-web-modules/spring-mvc-basics-4/README.md @@ -5,7 +5,7 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Quick Guide to Spring Controllers](https://www.baeldung.com/spring-controllers) -- [Model, ModelMap, and ModelView in Spring MVC](https://www.baeldung.com/spring-mvc-model-model-map-model-view) +- [Model, ModelMap, and ModelAndView in Spring MVC](https://www.baeldung.com/spring-mvc-model-model-map-model-view) - [Spring Web Contexts](https://www.baeldung.com/spring-web-contexts) - [Spring Optional Path variables](https://www.baeldung.com/spring-optional-path-variables) - [JSON Parameters with Spring MVC](https://www.baeldung.com/spring-mvc-send-json-parameters) From 5ab8f0678f06deeca9e494af1e5abcedc958d8a1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:46:38 +0800 Subject: [PATCH 576/590] Update README.md --- core-java-modules/core-java-9-new-features/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-9-new-features/README.md b/core-java-modules/core-java-9-new-features/README.md index 5af069c6f0..4045a37d9d 100644 --- a/core-java-modules/core-java-9-new-features/README.md +++ b/core-java-modules/core-java-9-new-features/README.md @@ -4,7 +4,7 @@ This module contains articles about core Java features that have been introduced ### Relevant Articles: -- [Java 9 New Features](https://www.baeldung.com/new-java-9) +- [New Features in Java 9](https://www.baeldung.com/new-java-9) - [Java 9 Variable Handles Demystified](http://www.baeldung.com/java-variable-handles) - [Exploring the New HTTP Client in Java 9 and 11](http://www.baeldung.com/java-9-http-client) - [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar) From d9fcd0de3451076224819b2946207f66729ee723 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:49:18 +0800 Subject: [PATCH 577/590] Update README.md --- core-java-modules/core-java-10/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-10/README.md b/core-java-modules/core-java-10/README.md index 38b1db1c05..11c2051816 100644 --- a/core-java-modules/core-java-10/README.md +++ b/core-java-modules/core-java-10/README.md @@ -5,7 +5,7 @@ This module contains articles about Java 10 core features ### Relevant Articles: - [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference) -- [Guide to Java 10](http://www.baeldung.com/java-10-overview) +- [New Features in Java 10](https://www.baeldung.com/java-10-overview) - [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another) - [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler) - [Copying Sets in Java](https://www.baeldung.com/java-copy-sets) From 0e93e2f779c2ca47b4ca1f474ec01724e6e50614 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:52:55 +0800 Subject: [PATCH 578/590] Update README.md --- core-java-modules/core-java-13/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-13/README.md b/core-java-modules/core-java-13/README.md index 697f89c362..9215139dd4 100644 --- a/core-java-modules/core-java-13/README.md +++ b/core-java-modules/core-java-13/README.md @@ -1,4 +1,4 @@ ### Relevant articles: - [Java Switch Statement](https://www.baeldung.com/java-switch) -- [New Java 13 Features](https://www.baeldung.com/java-13-new-features) +- [New Features in Java 13](https://www.baeldung.com/java-13-new-features) From 25d4cd922284b3db470d761013699f67d4352552 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:55:38 +0800 Subject: [PATCH 579/590] Update README.md --- core-java-modules/core-java-12/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java-modules/core-java-12/README.md b/core-java-modules/core-java-12/README.md index c28df26c6f..b509be876c 100644 --- a/core-java-modules/core-java-12/README.md +++ b/core-java-modules/core-java-12/README.md @@ -1,5 +1,4 @@ ## Relevant Articles: - - [String API Updates in Java 12](https://www.baeldung.com/java12-string-api) -- [Java 12 New Features](https://www.baeldung.com/java-12-new-features) +- [New Features in Java 12](https://www.baeldung.com/java-12-new-features) From 15d247be80f9563d13f31ed90ce8ffa5835e4186 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:59:24 +0800 Subject: [PATCH 580/590] Update README.md --- core-java-modules/core-java-char/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md index fd79da15ab..5f33aa6914 100644 --- a/core-java-modules/core-java-char/README.md +++ b/core-java-modules/core-java-char/README.md @@ -3,4 +3,4 @@ This module contains articles about Java Character Class ### Relevant Articles: -- [Character#isAlphabetic vs Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic) +- [Character#isAlphabetic vs. Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic) From 5d2087c7116212cfe9fc6de91b3d5e814e7181df Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 02:04:28 +0800 Subject: [PATCH 581/590] Update README.md --- core-java-modules/core-java-14/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md index 004b3587c4..07cdf9859c 100644 --- a/core-java-modules/core-java-14/README.md +++ b/core-java-modules/core-java-14/README.md @@ -10,4 +10,4 @@ This module contains articles about Java 14. - [Helpful NullPointerExceptions in Java 14](https://www.baeldung.com/java-14-nullpointerexception) - [Foreign Memory Access API in Java 14](https://www.baeldung.com/java-foreign-memory-access) - [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword) -- [Java 14 – New Features](https://www.baeldung.com/java-14-new-features) +- [New Features in Java 14](https://www.baeldung.com/java-14-new-features) From e043ad6d20efa7f574744672c663ad004b139dd9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 02:19:55 +0800 Subject: [PATCH 582/590] Update README.md --- spring-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5/README.md b/spring-5/README.md index 845d602480..2ddd9fa94f 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -12,3 +12,4 @@ This module contains articles about Spring 5 - [Difference between \ vs \](https://www.baeldung.com/spring-contextannotation-contextcomponentscan) - [Finding the Spring Version](https://www.baeldung.com/spring-find-version) - [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) +- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) From 5ae0cce72e3ab250455b3c4bfdb5dcc033f24d27 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 02:25:06 +0800 Subject: [PATCH 583/590] Update README.md --- spring-boot-modules/spring-boot-springdoc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-springdoc/README.md b/spring-boot-modules/spring-boot-springdoc/README.md index 2447f30f6b..608e4afa2e 100644 --- a/spring-boot-modules/spring-boot-springdoc/README.md +++ b/spring-boot-modules/spring-boot-springdoc/README.md @@ -2,3 +2,4 @@ - [Documenting a Spring REST API Using OpenAPI 3.0](https://www.baeldung.com/spring-rest-openapi-documentation) - [Spring REST Docs vs OpenAPI](https://www.baeldung.com/spring-rest-docs-vs-openapi) +- [Hiding Endpoints From Swagger Documentation in Spring Boot](https://www.baeldung.com/spring-swagger-hiding-endpoints) From ec93dbe7f2d0f19a9710905e196403c46cf37563 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Feb 2021 02:41:03 +0800 Subject: [PATCH 584/590] Update README.md --- guest/core-kotlin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guest/core-kotlin/README.md b/guest/core-kotlin/README.md index c211773f27..fad62ebea6 100644 --- a/guest/core-kotlin/README.md +++ b/guest/core-kotlin/README.md @@ -1,3 +1,3 @@ ### Relevant Articles: -- [Kotlin vs Java](https://www.baeldung.com/kotlin/kotlin-vs-java) +- [Kotlin vs Java](https://www.baeldung.com/kotlin/vs-java) From 0315847ad7e93d95590cba85158a153141df2434 Mon Sep 17 00:00:00 2001 From: Mateusz Szablak Date: Wed, 10 Feb 2021 00:40:55 +0100 Subject: [PATCH 585/590] Update PropertiesToHashMapConverter.java --- .../map/propertieshashmap/PropertiesToHashMapConverter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java index 2f333638a9..3472f998f5 100644 --- a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java +++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java @@ -27,9 +27,9 @@ public class PropertiesToHashMapConverter { public static HashMap streamConvert(Properties prop) { return prop.entrySet().stream().collect( Collectors.toMap( - e -> String.valueOf(e.getKey()), - e -> String.valueOf(e.getValue()), - (prev, next) -> next, HashMap::new + e -> String.valueOf(e.getKey()), + e -> String.valueOf(e.getValue()), + (prev, next) -> next, HashMap::new )); } From 153f600c627648f5262c6a5ad882124b83d3c21c Mon Sep 17 00:00:00 2001 From: kwoyke Date: Wed, 10 Feb 2021 07:51:44 +0100 Subject: [PATCH 586/590] BAEL-4758: Override autoIndexCreation in MongoConfig (#10474) --- .../src/main/java/com/baeldung/config/MongoConfig.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 90b1268133..a7db26eba5 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java +++ b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -68,4 +68,8 @@ public class MongoConfig extends AbstractMongoClientConfiguration { return new MongoTransactionManager(dbFactory); } + @Override + protected boolean autoIndexCreation() { + return true; + } } From 92b4049195720ee321e311dc7f0fca2ec40060f5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 11 Feb 2021 01:07:33 +0800 Subject: [PATCH 587/590] 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 5279cc23b0..8ed945a56c 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -11,4 +11,5 @@ This module contains articles about core features in the Java language - [The transient Keyword in Java](https://www.baeldung.com/java-transient-keyword) - [How to Access an Iteration Counter in a For Each Loop](https://www.baeldung.com/java-foreach-counter) - [Comparing Doubles in Java](https://www.baeldung.com/java-comparing-doubles) +- [Guide to Implementing the compareTo Method](https://www.baeldung.com/java-compareto) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From db46684ab9d8d462312637072a0fb2c23b3f6754 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 11 Feb 2021 18:20:25 +0800 Subject: [PATCH 588/590] Update README.md --- stripe/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stripe/README.md b/stripe/README.md index 9e41dcf945..36f0d6e3f3 100644 --- a/stripe/README.md +++ b/stripe/README.md @@ -5,4 +5,4 @@ This module contains articles about Stripe ### Relevant articles - [Introduction to the Stripe API for Java](https://www.baeldung.com/java-stripe-api) - +- [Viewing Contents of a JAR File](https://www.baeldung.com/java-view-jar-contents) From 676bc680f2def5434e9075ac97bd17bc4f134c44 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 11 Feb 2021 19:06:27 +0800 Subject: [PATCH 589/590] Update README.md --- .../spring-session/spring-session-jdbc/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/spring-security-modules/spring-session/spring-session-jdbc/README.md b/spring-security-modules/spring-session/spring-session-jdbc/README.md index a31ee044e8..6af3f53137 100644 --- a/spring-security-modules/spring-session/spring-session-jdbc/README.md +++ b/spring-security-modules/spring-session/spring-session-jdbc/README.md @@ -3,5 +3,3 @@ This module contains articles about Spring Session with JDBC. ### Relevant Articles: - -- [Spring Session with JDBC](https://www.baeldung.com/spring-session-jdbc) From 89eb93a46c195b775e8b817823f9238fc42f1e6e Mon Sep 17 00:00:00 2001 From: Hamid Reza Sharifi Date: Fri, 12 Feb 2021 14:20:52 +0330 Subject: [PATCH 590/590] Bael-4684-Prevent Cross-Site Scripting (XSS) in a Spring application-(new) (#10480) * #bael-4684: add main source code * #bael-4684: add test * #bael-4684: add required dependencies --- .../spring-5-security/pom.xml | 15 + .../java/com/baeldung/xss/Application.java | 14 + .../main/java/com/baeldung/xss/Person.java | 36 ++ .../com/baeldung/xss/PersonController.java | 31 + .../java/com/baeldung/xss/SecurityConf.java | 25 + .../main/java/com/baeldung/xss/XSSFilter.java | 44 ++ .../com/baeldung/xss/XSSRequestWrapper.java | 123 ++++ .../main/java/com/baeldung/xss/XSSUtils.java | 19 + .../src/main/resources/ESAPI.properties | 545 ++++++++++++++++++ .../xss/PersonControllerUnitTest.java | 64 ++ 10 files changed, 916 insertions(+) create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Application.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Person.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/PersonController.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/SecurityConf.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSFilter.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSRequestWrapper.java create mode 100644 spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSUtils.java create mode 100644 spring-security-modules/spring-5-security/src/main/resources/ESAPI.properties create mode 100644 spring-security-modules/spring-5-security/src/test/java/com/baeldung/xss/PersonControllerUnitTest.java diff --git a/spring-security-modules/spring-5-security/pom.xml b/spring-security-modules/spring-5-security/pom.xml index 09de91491c..f50b5ff7a9 100644 --- a/spring-security-modules/spring-5-security/pom.xml +++ b/spring-security-modules/spring-5-security/pom.xml @@ -46,6 +46,21 @@ spring-security-test test
    + + org.owasp.esapi + esapi + 2.2.2.0 + + + org.jsoup + jsoup + 1.13.1 + + + commons-io + commons-io + 2.8.0 + diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Application.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Application.java new file mode 100644 index 0000000000..b463a7adc3 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.xss; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@SpringBootApplication +@EnableWebSecurity +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Person.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Person.java new file mode 100644 index 0000000000..1e7c02bae8 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/Person.java @@ -0,0 +1,36 @@ +package com.baeldung.xss; + +public class Person { + private String firstName; + private String lastName; + private int age; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "Person {" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", age=" + age + '}'; + } +} diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/PersonController.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/PersonController.java new file mode 100644 index 0000000000..8486e04e48 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/PersonController.java @@ -0,0 +1,31 @@ +package com.baeldung.xss; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Map; + +@RestController +@RequestMapping("/personService") +public class PersonController { + + @PostMapping(value = "/person") + private ResponseEntity savePerson(@RequestHeader Map headers, + @RequestParam String param, @RequestBody Person body) { + ObjectNode response = JsonNodeFactory.instance.objectNode(); + headers.forEach((key, value) -> response.put(key, value)); + response.put("firstName", body.getFirstName()); + response.put("lastName", body.getLastName()); + response.put("age", body.getAge()); + response.put("param", param); + return new ResponseEntity(response.toString(), HttpStatus.OK); + } +} \ No newline at end of file diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/SecurityConf.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/SecurityConf.java new file mode 100644 index 0000000000..25d8026e4a --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/SecurityConf.java @@ -0,0 +1,25 @@ +package com.baeldung.xss; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +public class SecurityConf extends WebSecurityConfigurerAdapter { + + @Override + public void configure(WebSecurity web) { + // Ignoring here is only for this example. Normally people would apply their own authentication/authorization policies + web.ignoring().antMatchers("/**"); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .headers() + .xssProtection() + .and() + .contentSecurityPolicy("script-src 'self'"); + } +} diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSFilter.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSFilter.java new file mode 100644 index 0000000000..431ed4d120 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSFilter.java @@ -0,0 +1,44 @@ +package com.baeldung.xss; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import javax.servlet.Filter; +import javax.servlet.FilterConfig; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.ServletException; +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class XSSFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) { + } + + @Override + public void destroy() { + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + + XSSRequestWrapper wrappedRequest = new XSSRequestWrapper((HttpServletRequest) request); + + String body = IOUtils.toString(wrappedRequest.getReader()); + if (!StringUtils.isBlank(body)) { + body = XSSUtils.stripXSS(body); + wrappedRequest.resetInputStream(body.getBytes()); + } + + chain.doFilter(wrappedRequest, response); + } + +} \ No newline at end of file diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSRequestWrapper.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSRequestWrapper.java new file mode 100644 index 0000000000..8fe4e20b5c --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSRequestWrapper.java @@ -0,0 +1,123 @@ +package com.baeldung.xss; + +import org.apache.commons.codec.Charsets; +import org.apache.commons.io.IOUtils; +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +import static com.baeldung.xss.XSSUtils.stripXSS; + + +public class XSSRequestWrapper extends HttpServletRequestWrapper { + + private byte[] rawData; + private HttpServletRequest request; + private ResettableServletInputStream servletStream; + + public XSSRequestWrapper(HttpServletRequest request) { + super(request); + this.request = request; + this.servletStream = new ResettableServletInputStream(); + } + + public void resetInputStream(byte[] newRawData) { + rawData = newRawData; + servletStream.stream = new ByteArrayInputStream(newRawData); + } + + @Override + public ServletInputStream getInputStream() throws IOException { + if (rawData == null) { + rawData = IOUtils.toByteArray(this.request.getReader(), Charsets.UTF_8); + servletStream.stream = new ByteArrayInputStream(rawData); + } + return servletStream; + } + + @Override + public BufferedReader getReader() throws IOException { + if (rawData == null) { + rawData = IOUtils.toByteArray(this.request.getReader(), Charsets.UTF_8); + servletStream.stream = new ByteArrayInputStream(rawData); + } + return new BufferedReader(new InputStreamReader(servletStream)); + } + + private class ResettableServletInputStream extends ServletInputStream { + + private InputStream stream; + + @Override + public int read() throws IOException { + return stream.read(); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + + } + } + + @Override + public String[] getParameterValues(String parameter) { + String[] values = super.getParameterValues(parameter); + if (values == null) { + return null; + } + int count = values.length; + String[] encodedValues = new String[count]; + for (int i = 0; i < count; i++) { + encodedValues[i] = stripXSS(values[i]); + } + return encodedValues; + } + + @Override + public String getParameter(String parameter) { + String value = super.getParameter(parameter); + return stripXSS(value); + } + + @Override + public String getHeader(String name) { + String value = super.getHeader(name); + return stripXSS(value); + } + + @Override + public Enumeration getHeaders(String name) { + List result = new ArrayList<>(); + Enumeration headers = super.getHeaders(name); + while (headers.hasMoreElements()) { + String header = headers.nextElement(); + String[] tokens = header.split(","); + for (String token : tokens) { + result.add(stripXSS(token)); + } + } + return Collections.enumeration(result); + } + +} diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSUtils.java b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSUtils.java new file mode 100644 index 0000000000..51bcba8115 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/java/com/baeldung/xss/XSSUtils.java @@ -0,0 +1,19 @@ +package com.baeldung.xss; + +import org.jsoup.Jsoup; +import org.jsoup.safety.Whitelist; +import org.owasp.esapi.ESAPI; + +public class XSSUtils { + + public static String stripXSS(String value) { + if (value == null) { + return null; + } + value = ESAPI.encoder() + .canonicalize(value) + .replaceAll("\0", ""); + return Jsoup.clean(value, Whitelist.none()); + } + +} diff --git a/spring-security-modules/spring-5-security/src/main/resources/ESAPI.properties b/spring-security-modules/spring-5-security/src/main/resources/ESAPI.properties new file mode 100644 index 0000000000..a2746a4dbc --- /dev/null +++ b/spring-security-modules/spring-5-security/src/main/resources/ESAPI.properties @@ -0,0 +1,545 @@ +# +# OWASP Enterprise Security API (ESAPI) Properties file -- PRODUCTION Version +# +# This file is part of the Open Web Application Security Project (OWASP) +# Enterprise Security API (ESAPI) project. For details, please see +# https://owasp.org/www-project-enterprise-security-api/ +# +# Copyright (c) 2008,2009 - The OWASP Foundation +# +# DISCUSS: This may cause a major backwards compatibility issue, etc. but +# from a name space perspective, we probably should have prefaced +# all the property names with ESAPI or at least OWASP. Otherwise +# there could be problems is someone loads this properties file into +# the System properties. We could also put this file into the +# esapi.jar file (perhaps as a ResourceBundle) and then allow an external +# ESAPI properties be defined that would overwrite these defaults. +# That keeps the application's properties relatively simple as usually +# they will only want to override a few properties. If looks like we +# already support multiple override levels of this in the +# DefaultSecurityConfiguration class, but I'm suggesting placing the +# defaults in the esapi.jar itself. That way, if the jar is signed, +# we could detect if those properties had been tampered with. (The +# code to check the jar signatures is pretty simple... maybe 70-90 LOC, +# but off course there is an execution penalty (similar to the way +# that the separate sunjce.jar used to be when a class from it was +# first loaded). Thoughts? +############################################################################### +# +# WARNING: Operating system protection should be used to lock down the .esapi +# resources directory and all the files inside and all the directories all the +# way up to the root directory of the file system. Note that if you are using +# file-based implementations, that some files may need to be read-write as they +# get updated dynamically. +# +#=========================================================================== +# ESAPI Configuration +# +# If true, then print all the ESAPI properties set here when they are loaded. +# If false, they are not printed. Useful to reduce output when running JUnit tests. +# If you need to troubleshoot a properties related problem, turning this on may help. +# This is 'false' in the src/test/resources/.esapi version. It is 'true' by +# default for reasons of backward compatibility with earlier ESAPI versions. +ESAPI.printProperties=true + +# ESAPI is designed to be easily extensible. You can use the reference implementation +# or implement your own providers to take advantage of your enterprise's security +# infrastructure. The functions in ESAPI are referenced using the ESAPI locator, like: +# +# String ciphertext = +# ESAPI.encryptor().encrypt("Secret message"); // Deprecated in 2.0 +# CipherText cipherText = +# ESAPI.encryptor().encrypt(new PlainText("Secret message")); // Preferred +# +# Below you can specify the classname for the provider that you wish to use in your +# application. The only requirement is that it implement the appropriate ESAPI interface. +# This allows you to switch security implementations in the future without rewriting the +# entire application. +# +# ExperimentalAccessController requires ESAPI-AccessControlPolicy.xml in .esapi directory +ESAPI.AccessControl=org.owasp.esapi.reference.DefaultAccessController +# FileBasedAuthenticator requires users.txt file in .esapi directory +ESAPI.Authenticator=org.owasp.esapi.reference.FileBasedAuthenticator +ESAPI.Encoder=org.owasp.esapi.reference.DefaultEncoder +ESAPI.Encryptor=org.owasp.esapi.reference.crypto.JavaEncryptor + +ESAPI.Executor=org.owasp.esapi.reference.DefaultExecutor +ESAPI.HTTPUtilities=org.owasp.esapi.reference.DefaultHTTPUtilities +ESAPI.IntrusionDetector=org.owasp.esapi.reference.DefaultIntrusionDetector +# Log4JFactory Requires log4j.xml or log4j.properties in classpath - http://www.laliluna.de/log4j-tutorial.html +# Note that this is now considered deprecated! +ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory +#ESAPI.Logger=org.owasp.esapi.logging.log4j.Log4JLogFactory +#ESAPI.Logger=org.owasp.esapi.logging.java.JavaLogFactory +# To use the new SLF4J logger in ESAPI (see GitHub issue #129), set +# ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory +# and do whatever other normal SLF4J configuration that you normally would do for your application. +ESAPI.Randomizer=org.owasp.esapi.reference.DefaultRandomizer +ESAPI.Validator=org.owasp.esapi.reference.DefaultValidator + +#=========================================================================== +# ESAPI Authenticator +# +Authenticator.AllowedLoginAttempts=3 +Authenticator.MaxOldPasswordHashes=13 +Authenticator.UsernameParameterName=username +Authenticator.PasswordParameterName=password +# RememberTokenDuration (in days) +Authenticator.RememberTokenDuration=14 +# Session Timeouts (in minutes) +Authenticator.IdleTimeoutDuration=20 +Authenticator.AbsoluteTimeoutDuration=120 + +#=========================================================================== +# ESAPI Encoder +# +# ESAPI canonicalizes input before validation to prevent bypassing filters with encoded attacks. +# Failure to canonicalize input is a very common mistake when implementing validation schemes. +# Canonicalization is automatic when using the ESAPI Validator, but you can also use the +# following code to canonicalize data. +# +# ESAPI.Encoder().canonicalize( "%22hello world"" ); +# +# Multiple encoding is when a single encoding format is applied multiple times. Allowing +# multiple encoding is strongly discouraged. +Encoder.AllowMultipleEncoding=false + +# Mixed encoding is when multiple different encoding formats are applied, or when +# multiple formats are nested. Allowing multiple encoding is strongly discouraged. +Encoder.AllowMixedEncoding=false + +# The default list of codecs to apply when canonicalizing untrusted data. The list should include the codecs +# for all downstream interpreters or decoders. For example, if the data is likely to end up in a URL, HTML, or +# inside JavaScript, then the list of codecs below is appropriate. The order of the list is not terribly important. +Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec + + +#=========================================================================== +# ESAPI Encryption +# +# The ESAPI Encryptor provides basic cryptographic functions with a simplified API. +# To get started, generate a new key using java -classpath esapi.jar org.owasp.esapi.reference.crypto.JavaEncryptor +# There is not currently any support for key rotation, so be careful when changing your key and salt as it +# will invalidate all signed, encrypted, and hashed data. +# +# WARNING: Not all combinations of algorithms and key lengths are supported. +# If you choose to use a key length greater than 128, you MUST download the +# unlimited strength policy files and install in the lib directory of your JRE/JDK. +# See http://java.sun.com/javase/downloads/index.jsp for more information. +# +# ***** IMPORTANT: Do NOT forget to replace these with your own values! ***** +# To calculate these values, you can run: +# java -classpath esapi.jar org.owasp.esapi.reference.crypto.JavaEncryptor +# +#Encryptor.MasterKey= +#Encryptor.MasterSalt= + +# Provides the default JCE provider that ESAPI will "prefer" for its symmetric +# encryption and hashing. (That is it will look to this provider first, but it +# will defer to other providers if the requested algorithm is not implemented +# by this provider.) If left unset, ESAPI will just use your Java VM's current +# preferred JCE provider, which is generally set in the file +# "$JAVA_HOME/jre/lib/security/java.security". +# +# The main intent of this is to allow ESAPI symmetric encryption to be +# used with a FIPS 140-2 compliant crypto-module. For details, see the section +# "Using ESAPI Symmetric Encryption with FIPS 140-2 Cryptographic Modules" in +# the ESAPI 2.0 Symmetric Encryption User Guide, at: +# http://owasp-esapi-java.googlecode.com/svn/trunk/documentation/esapi4java-core-2.0-symmetric-crypto-user-guide.html +# However, this property also allows you to easily use an alternate JCE provider +# such as "Bouncy Castle" without having to make changes to "java.security". +# See Javadoc for SecurityProviderLoader for further details. If you wish to use +# a provider that is not known to SecurityProviderLoader, you may specify the +# fully-qualified class name of the JCE provider class that implements +# java.security.Provider. If the name contains a '.', this is interpreted as +# a fully-qualified class name that implements java.security.Provider. +# +# NOTE: Setting this property has the side-effect of changing it in your application +# as well, so if you are using JCE in your application directly rather than +# through ESAPI (you wouldn't do that, would you? ;-), it will change the +# preferred JCE provider there as well. +# +# Default: Keeps the JCE provider set to whatever JVM sets it to. +Encryptor.PreferredJCEProvider= + +# AES is the most widely used and strongest encryption algorithm. This +# should agree with your Encryptor.CipherTransformation property. +# Warning: This property does not control the default reference implementation for +# ESAPI 2.0 using JavaEncryptor. Also, this property will be dropped +# in the future. +# @deprecated +Encryptor.EncryptionAlgorithm=AES +# For ESAPI Java 2.0 - New encrypt / decrypt methods use this. +Encryptor.CipherTransformation=AES/CBC/PKCS5Padding + +# Applies to ESAPI 2.0 and later only! +# Comma-separated list of cipher modes that provide *BOTH* +# confidentiality *AND* message authenticity. (NIST refers to such cipher +# modes as "combined modes" so that's what we shall call them.) If any of these +# cipher modes are used then no MAC is calculated and stored +# in the CipherText upon encryption. Likewise, if one of these +# cipher modes is used with decryption, no attempt will be made +# to validate the MAC contained in the CipherText object regardless +# of whether it contains one or not. Since the expectation is that +# these cipher modes support support message authenticity already, +# injecting a MAC in the CipherText object would be at best redundant. +# +# Note that as of JDK 1.5, the SunJCE provider does not support *any* +# of these cipher modes. Of these listed, only GCM and CCM are currently +# NIST approved. YMMV for other JCE providers. E.g., Bouncy Castle supports +# GCM and CCM with "NoPadding" mode, but not with "PKCS5Padding" or other +# padding modes. +Encryptor.cipher_modes.combined_modes=GCM,CCM,IAPM,EAX,OCB,CWC + +# Applies to ESAPI 2.0 and later only! +# Additional cipher modes allowed for ESAPI 2.0 encryption. These +# cipher modes are in _addition_ to those specified by the property +# 'Encryptor.cipher_modes.combined_modes'. +# Note: We will add support for streaming modes like CFB & OFB once +# we add support for 'specified' to the property 'Encryptor.ChooseIVMethod' +# (probably in ESAPI 2.1). +# DISCUSS: Better name? +Encryptor.cipher_modes.additional_allowed=CBC + +# Default key size to use for cipher specified by Encryptor.EncryptionAlgorithm. +# Note that this MUST be a valid key size for the algorithm being used +# (as specified by Encryptor.EncryptionAlgorithm). So for example, if AES is used, +# it must be 128, 192, or 256. If DESede is chosen, then it must be either 112 or 168. +# +# Note that 128-bits is almost always sufficient and for AES it appears to be more +# somewhat more resistant to related key attacks than is 256-bit AES.) +# +# Defaults to 128-bits if left blank. +# +# NOTE: If you use a key size > 128-bits, then you MUST have the JCE Unlimited +# Strength Jurisdiction Policy files installed!!! +# +Encryptor.EncryptionKeyLength=128 + +# This is the _minimum_ key size (in bits) that we allow with ANY symmetric +# cipher for doing encryption. (There is no minimum for decryption.) +# +# Generally, if you only use one algorithm, this should be set the same as +# the Encryptor.EncryptionKeyLength property. +Encryptor.MinEncryptionKeyLength=128 + +# Because 2.x uses CBC mode by default, it requires an initialization vector (IV). +# (All cipher modes except ECB require an IV.) There are two choices: we can either +# use a fixed IV known to both parties or allow ESAPI to choose a random IV. While +# the IV does not need to be hidden from adversaries, it is important that the +# adversary not be allowed to choose it. Also, random IVs are generally much more +# secure than fixed IVs. (In fact, it is essential that feed-back cipher modes +# such as CFB and OFB use a different IV for each encryption with a given key so +# in such cases, random IVs are much preferred. By default, ESAPI 2.0 uses random +# IVs. If you wish to use 'fixed' IVs, set 'Encryptor.ChooseIVMethod=fixed' and +# uncomment the Encryptor.fixedIV. +# +# Valid values: random|fixed|specified 'specified' not yet implemented; planned for 2.3 +# 'fixed' is deprecated as of 2.2 +# and will be removed in 2.3. +Encryptor.ChooseIVMethod=random + + +# If you choose to use a fixed IV, then you must place a fixed IV here that +# is known to all others who are sharing your secret key. The format should +# be a hex string that is the same length as the cipher block size for the +# cipher algorithm that you are using. The following is an *example* for AES +# from an AES test vector for AES-128/CBC as described in: +# NIST Special Publication 800-38A (2001 Edition) +# "Recommendation for Block Cipher Modes of Operation". +# (Note that the block size for AES is 16 bytes == 128 bits.) +# +# @Deprecated -- fixed IVs are deprecated as of the 2.2 release and support +# will be removed in the next release (tentatively, 2.3). +# If you MUST use this, at least replace this IV with one +# that your legacy application was using. +Encryptor.fixedIV=0x000102030405060708090a0b0c0d0e0f + +# Whether or not CipherText should use a message authentication code (MAC) with it. +# This prevents an adversary from altering the IV as well as allowing a more +# fool-proof way of determining the decryption failed because of an incorrect +# key being supplied. This refers to the "separate" MAC calculated and stored +# in CipherText, not part of any MAC that is calculated as a result of a +# "combined mode" cipher mode. +# +# If you are using ESAPI with a FIPS 140-2 cryptographic module, you *must* also +# set this property to false. That is because ESAPI takes the master key and +# derives 2 keys from it--a key for the MAC and a key for encryption--and +# because ESAPI is not itself FIPS 140-2 verified such intermediary aterations +# to keys from FIPS approved sources would have the effect of making your FIPS +# approved key generation and thus your FIPS approved JCE provider unapproved! +# More details in +# documentation/esapi4java-core-2.0-readme-crypto-changes.html +# documentation/esapi4java-core-2.0-symmetric-crypto-user-guide.html +# You have been warned. +Encryptor.CipherText.useMAC=true + +# Whether or not the PlainText object may be overwritten and then marked +# eligible for garbage collection. If not set, this is still treated as 'true'. +Encryptor.PlainText.overwrite=true + +# Do not use DES except in a legacy situations. 56-bit is way too small key size. +#Encryptor.EncryptionKeyLength=56 +#Encryptor.MinEncryptionKeyLength=56 +#Encryptor.EncryptionAlgorithm=DES + +# TripleDES is considered strong enough for most purposes. +# Note: There is also a 112-bit version of DESede. Using the 168-bit version +# requires downloading the special jurisdiction policy from Sun. +#Encryptor.EncryptionKeyLength=168 +#Encryptor.MinEncryptionKeyLength=112 +#Encryptor.EncryptionAlgorithm=DESede + +Encryptor.HashAlgorithm=SHA-512 +Encryptor.HashIterations=1024 +Encryptor.DigitalSignatureAlgorithm=SHA1withDSA +Encryptor.DigitalSignatureKeyLength=1024 +Encryptor.RandomAlgorithm=SHA1PRNG +Encryptor.CharacterEncoding=UTF-8 + +# This is the Pseudo Random Function (PRF) that ESAPI's Key Derivation Function +# (KDF) normally uses. Note this is *only* the PRF used for ESAPI's KDF and +# *not* what is used for ESAPI's MAC. (Currently, HmacSHA1 is always used for +# the MAC, mostly to keep the overall size at a minimum.) +# +# Currently supported choices for JDK 1.5 and 1.6 are: +# HmacSHA1 (160 bits), HmacSHA256 (256 bits), HmacSHA384 (384 bits), and +# HmacSHA512 (512 bits). +# Note that HmacMD5 is *not* supported for the PRF used by the KDF even though +# the JDKs support it. See the ESAPI 2.0 Symmetric Encryption User Guide +# further details. +Encryptor.KDF.PRF=HmacSHA256 +#=========================================================================== +# ESAPI HttpUtilties +# +# The HttpUtilities provide basic protections to HTTP requests and responses. Primarily these methods +# protect against malicious data from attackers, such as unprintable characters, escaped characters, +# and other simple attacks. The HttpUtilities also provides utility methods for dealing with cookies, +# headers, and CSRF tokens. +# +# Default file upload location (remember to escape backslashes with \\) +HttpUtilities.UploadDir=C:\\ESAPI\\testUpload +HttpUtilities.UploadTempDir=C:\\temp +# Force flags on cookies, if you use HttpUtilities to set cookies +HttpUtilities.ForceHttpOnlySession=false +HttpUtilities.ForceSecureSession=false +HttpUtilities.ForceHttpOnlyCookies=true +HttpUtilities.ForceSecureCookies=true +# Maximum size of HTTP header key--the validator regex may have additional values. +HttpUtilities.MaxHeaderNameSize=256 +# Maximum size of HTTP header value--the validator regex may have additional values. +HttpUtilities.MaxHeaderValueSize=4096 +# Maximum size of JSESSIONID for the application--the validator regex may have additional values. +HttpUtilities.HTTPJSESSIONIDLENGTH=50 +# Maximum length of a URL (see https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers) +HttpUtilities.URILENGTH=2000 +# Maximum length of a redirect +HttpUtilities.maxRedirectLength=512 +# Maximum length for an http scheme +HttpUtilities.HTTPSCHEMELENGTH=10 +# Maximum length for an http host +HttpUtilities.HTTPHOSTLENGTH=100 +# Maximum length for an http path +HttpUtilities.HTTPPATHLENGTH=150 +#Maximum length for a context path +HttpUtilities.contextPathLength=150 +#Maximum length for an httpServletPath +HttpUtilities.HTTPSERVLETPATHLENGTH=100 +#Maximum length for an http query parameter name +HttpUtilities.httpQueryParamNameLength=100 +#Maximum length for an http query parameter -- old default was 2000, but that's the max length for a URL... +HttpUtilities.httpQueryParamValueLength=500 +# File upload configuration +HttpUtilities.ApprovedUploadExtensions=.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.rtf,.txt,.jpg,.png +HttpUtilities.MaxUploadFileBytes=500000000 +# Using UTF-8 throughout your stack is highly recommended. That includes your database driver, +# container, and any other technologies you may be using. Failure to do this may expose you +# to Unicode transcoding injection attacks. Use of UTF-8 does not hinder internationalization. +HttpUtilities.ResponseContentType=text/html; charset=UTF-8 +# This is the name of the cookie used to represent the HTTP session +# Typically this will be the default "JSESSIONID" +HttpUtilities.HttpSessionIdName=JSESSIONID +#Sets whether or not we will overwrite http status codes to 200. +HttpUtilities.OverwriteStatusCodes=true +#Sets the application's base character encoding. This is forked from the Java Encryptor property. +HttpUtilities.CharacterEncoding=UTF-8 + +#=========================================================================== +# ESAPI Executor +# CHECKME - This should be made OS independent. Don't use unsafe defaults. +# # Examples only -- do NOT blindly copy! +# For Windows: +# Executor.WorkingDirectory=C:\\Windows\\Temp +# Executor.ApprovedExecutables=C:\\Windows\\System32\\cmd.exe,C:\\Windows\\System32\\runas.exe +# For *nux, MacOS: +# Executor.WorkingDirectory=/tmp +# Executor.ApprovedExecutables=/bin/bash +Executor.WorkingDirectory= +Executor.ApprovedExecutables= + + +#=========================================================================== +# ESAPI Logging +# Set the application name if these logs are combined with other applications +Logger.ApplicationName=ExampleApplication +# If you use an HTML log viewer that does not properly HTML escape log data, you can set LogEncodingRequired to true +Logger.LogEncodingRequired=false +# Determines whether ESAPI should log the application name. This might be clutter in some single-server/single-app environments. +Logger.LogApplicationName=true +# Determines whether ESAPI should log the server IP and port. This might be clutter in some single-server environments. +Logger.LogServerIP=true +# LogFileName, the name of the logging file. Provide a full directory path (e.g., C:\\ESAPI\\ESAPI_logging_file) if you +# want to place it in a specific directory. +Logger.LogFileName=ESAPI_logging_file +# MaxLogFileSize, the max size (in bytes) of a single log file before it cuts over to a new one (default is 10,000,000) +Logger.MaxLogFileSize=10000000 +# Determines whether ESAPI should log the user info. +Logger.UserInfo=true +# Determines whether ESAPI should log the session id and client IP. +Logger.ClientInfo=true + +#=========================================================================== +# ESAPI Intrusion Detection +# +# Each event has a base to which .count, .interval, and .action are added +# The IntrusionException will fire if we receive "count" events within "interval" seconds +# The IntrusionDetector is configurable to take the following actions: log, logout, and disable +# (multiple actions separated by commas are allowed e.g. event.test.actions=log,disable +# +# Custom Events +# Names must start with "event." as the base +# Use IntrusionDetector.addEvent( "test" ) in your code to trigger "event.test" here +# You can also disable intrusion detection completely by changing +# the following parameter to true +# +IntrusionDetector.Disable=false +# +IntrusionDetector.event.test.count=2 +IntrusionDetector.event.test.interval=10 +IntrusionDetector.event.test.actions=disable,log + +# Exception Events +# All EnterpriseSecurityExceptions are registered automatically +# Call IntrusionDetector.getInstance().addException(e) for Exceptions that do not extend EnterpriseSecurityException +# Use the fully qualified classname of the exception as the base + +# any intrusion is an attack +IntrusionDetector.org.owasp.esapi.errors.IntrusionException.count=1 +IntrusionDetector.org.owasp.esapi.errors.IntrusionException.interval=1 +IntrusionDetector.org.owasp.esapi.errors.IntrusionException.actions=log,disable,logout + +# for test purposes +# CHECKME: Shouldn't there be something in the property name itself that designates +# that these are for testing??? +IntrusionDetector.org.owasp.esapi.errors.IntegrityException.count=10 +IntrusionDetector.org.owasp.esapi.errors.IntegrityException.interval=5 +IntrusionDetector.org.owasp.esapi.errors.IntegrityException.actions=log,disable,logout + +# rapid validation errors indicate scans or attacks in progress +# org.owasp.esapi.errors.ValidationException.count=10 +# org.owasp.esapi.errors.ValidationException.interval=10 +# org.owasp.esapi.errors.ValidationException.actions=log,logout + +# sessions jumping between hosts indicates session hijacking +IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.count=2 +IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.interval=10 +IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.actions=log,logout + + +#=========================================================================== +# ESAPI Validation +# +# The ESAPI Validator works on regular expressions with defined names. You can define names +# either here, or you may define application specific patterns in a separate file defined below. +# This allows enterprises to specify both organizational standards as well as application specific +# validation rules. +# +# Use '\p{L}' (without the quotes) within the character class to match +# any Unicode LETTER. You can also use a range, like: \u00C0-\u017F +# You can also use any of the regex flags as documented at +# https://docs.oracle.com/javase/tutorial/essential/regex/pattern.html, e.g. (?u) +# +Validator.ConfigurationFile=validation.properties + +# Validators used by ESAPI +Validator.AccountName=^[a-zA-Z0-9]{3,20}$ +Validator.SystemCommand=^[a-zA-Z\\-\\/]{1,64}$ +Validator.RoleName=^[a-z]{1,20}$ + +#the word TEST below should be changed to your application +#name - only relative URL's are supported +Validator.Redirect=^\\/test.*$ + +# Global HTTP Validation Rules +# Values with Base64 encoded data (e.g. encrypted state) will need at least [a-zA-Z0-9\/+=] +Validator.HTTPScheme=^(http|https)$ +Validator.HTTPServerName=^[a-zA-Z0-9_.\\-]*$ +Validator.HTTPCookieName=^[a-zA-Z0-9\\-_]{1,32}$ +Validator.HTTPCookieValue=^[a-zA-Z0-9\\-\\/+=_ ]*$ +# Note that headerName and Value length is also configured in the HTTPUtilities section +Validator.HTTPHeaderName=^[a-zA-Z0-9\\-_]{1,256}$ +Validator.HTTPHeaderValue=^[a-zA-Z0-9()\\-=\\*\\.\\?;,+\\/:&_ ]*$ +Validator.HTTPServletPath=^[a-zA-Z0-9.\\-\\/_]*$ +Validator.HTTPPath=^[a-zA-Z0-9.\\-_]*$ +Validator.HTTPURL=^.*$ +Validator.HTTPJSESSIONID=^[A-Z0-9]{10,32}$ + + +# Contributed by Fraenku@gmx.ch +# Github Issue 126 https://github.com/ESAPI/esapi-java-legacy/issues/126 +Validator.HTTPParameterName=^[a-zA-Z0-9_\\-]{1,32}$ +Validator.HTTPParameterValue=^[\\p{L}\\p{N}.\\-/+=_ !$*?@]{0,1000}$ +Validator.HTTPContextPath=^/[a-zA-Z0-9.\\-_]*$ +Validator.HTTPQueryString=^([a-zA-Z0-9_\\-]{1,32}=[\\p{L}\\p{N}.\\-/+=_ !$*?@%]*&?)*$ +Validator.HTTPURI=^/([a-zA-Z0-9.\\-_]*/?)*$ + + +# Validation of file related input +Validator.FileName=^[a-zA-Z0-9!@#$%^&{}\\[\\]()_+\\-=,.~'` ]{1,255}$ +Validator.DirectoryName=^[a-zA-Z0-9:/\\\\!@#$%^&{}\\[\\]()_+\\-=,.~'` ]{1,255}$ + +# Validation of dates. Controls whether or not 'lenient' dates are accepted. +# See DataFormat.setLenient(boolean flag) for further details. +Validator.AcceptLenientDates=false + +# ~~~~~ Important Note ~~~~~ +# This is a workaround to make sure that a commit to address GitHub issue #509 +# doesn't accidentally break someone's production code. So essentially what we +# are doing is to reverting back to the previous possibly buggy (by +# documentation intent at least), but, by now, expected legacy behavior. +# Prior to the code changes for issue #509, if invalid / malicious HTML input was +# observed, AntiSamy would simply attempt to sanitize (cleanse) it and it would +# only be logged. However, the code change made ESAPI comply with its +# documentation, which stated that a ValidationException should be thrown in +# such cases. Unfortunately, changing this behavior--especially when no one is +# 100% certain that the documentation was correct--could break existing code +# using ESAPI so after a lot of debate, issue #521 was created to restore the +# previous behavior, but still allow the documented behavior. (We did this +# because it wasn't really causing an security issues since AntiSamy would clean +# it up anyway and we value backward compatibility as long as it doesn't clearly +# present security vulnerabilities.) +# More defaults about this are written up under GitHub issue #521 and +# the pull request it references. Future major releases of ESAPI (e.g., ESAPI 3.x) +# will not support this previous behavior, but it will remain for ESAPI 2.x. +# Set this to 'throw' if you want the originally intended behavior of throwing +# that was fixed via issue #509. Set to 'clean' if you want want the HTML input +# sanitized instead. +# +# Possible values: +# clean -- Use the legacy behavior where unsafe HTML input is logged and the +# sanitized (i.e., clean) input as determined by AntiSamy and your +# AntiSamy rules is returned. This is the default behavior if this +# new property is not found. +# throw -- The new, presumably correct and originally intended behavior where +# a ValidationException is thrown when unsafe HTML input is +# encountered. +# +#Validator.HtmlValidationAction=clean +Validator.HtmlValidationAction=throw + +# With the fix for #310 to enable loading antisamy-esapi.xml from the classpath +# also an enhancement was made to be able to use a different filename for the configuration. +# You don't have to configure the filename here, but in that case the code will keep looking for antisamy-esapi.xml. +# This is the default behaviour of ESAPI. +# +#Validator.HtmlValidationConfigurationFile=antisamy-esapi.xml \ No newline at end of file diff --git a/spring-security-modules/spring-5-security/src/test/java/com/baeldung/xss/PersonControllerUnitTest.java b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/xss/PersonControllerUnitTest.java new file mode 100644 index 0000000000..4e278ebf16 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/test/java/com/baeldung/xss/PersonControllerUnitTest.java @@ -0,0 +1,64 @@ +package com.baeldung.xss; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.*; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; +import java.io.IOException; +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class PersonControllerUnitTest { + + @LocalServerPort + int randomServerPort; + + @Test + public void givenRequestIsSuspicious_whenRequestIsPost_thenResponseIsClean() + throws IOException { + // given + String createPersonUrl; + RestTemplate restTemplate; + HttpHeaders headers; + UriComponentsBuilder builder; + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode personJsonObject = JsonNodeFactory.instance.objectNode(); + createPersonUrl = "http://localhost:" + randomServerPort + "/personService/person"; + restTemplate = new RestTemplate(); + headers = new HttpHeaders(); + + // when + personJsonObject.put("id", 1); + personJsonObject.put("firstName", "baeldung "); + personJsonObject.put("lastName", "baeldung click me!"); + + builder = UriComponentsBuilder.fromHttpUrl(createPersonUrl) + .queryParam("param", ""); + headers.add("header_4", "

    Your search for 'flowers '"); + HttpEntity request = new HttpEntity<>(personJsonObject.toString(), headers); + + ResponseEntity personResultAsJsonStr = restTemplate.exchange(builder.toUriString(), + HttpMethod.POST, request, String.class); + JsonNode root = objectMapper.readTree(personResultAsJsonStr.getBody()); + + // then + assertThat(root.get("firstName").textValue()).isEqualTo("baeldung "); + assertThat(root.get("lastName").textValue()).isEqualTo("baeldung click me!"); + assertThat(root.get("param").textValue()).isEmpty(); + assertThat(root.get("header_1").textValue()).isEmpty(); + assertThat(root.get("header_2").textValue()).isEmpty(); + assertThat(root.get("header_3").textValue()).isEmpty(); + assertThat(root.get("header_4").textValue()).isEqualTo("Your search for 'flowers '"); + } +}