From 2982c91e7db4bd85e10d0fbccc240b1d0325f8f6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 9 Nov 2021 16:27:03 +0530 Subject: [PATCH 01/14] JAVA-8204: Fix formatting of POMs --- akka-http/pom.xml | 2 +- aws-lambda/lambda/pom.xml | 3 +- core-java-modules/core-java-10/pom.xml | 1 - core-java-modules/core-java-11-2/pom.xml | 1 - core-java-modules/core-java-11/pom.xml | 1 - core-java-modules/core-java-12/pom.xml | 1 - core-java-modules/core-java-13/pom.xml | 1 - core-java-modules/core-java-14/pom.xml | 1 - core-java-modules/core-java-16/pom.xml | 66 ++--- core-java-modules/core-java-17/pom.xml | 64 ++-- .../core-java-annotations/pom.xml | 6 +- .../pom.xml | 3 - .../core-java-collections-maps-4/pom.xml | 6 +- .../core-java-collections-set/pom.xml | 1 - .../core-java-date-operations-1/pom.xml | 1 - .../core-java-datetime-string/pom.xml | 1 - .../core-java-io-conversions-2/pom.xml | 1 - core-java-modules/core-java-io/pom.xml | 1 - core-java-modules/core-java-jvm/pom.xml | 1 - core-java-modules/core-java-os/pom.xml | 180 ++++++------ .../core-java-security-3/pom.xml | 1 - .../core-java-string-algorithms-3/pom.xml | 4 +- .../core-java-string-operations-3/pom.xml | 2 +- core-java-modules/core-java-sun/pom.xml | 1 - .../core-java-time-measurements/pom.xml | 1 - drools/pom.xml | 1 - feign/pom.xml | 1 - flyway-cdi-extension/pom.xml | 1 - guava-modules/guava-18/pom.xml | 1 - guava-modules/guava-19/pom.xml | 1 - guava-modules/guava-21/pom.xml | 1 - guava-modules/guava-collections-list/pom.xml | 1 - guava-modules/guava-collections-map/pom.xml | 1 - guava-modules/guava-collections-set/pom.xml | 1 - guava-modules/guava-collections/pom.xml | 1 - guava-modules/guava-core/pom.xml | 1 - guava-modules/guava-io/pom.xml | 1 - guava-modules/guava-utilities/pom.xml | 1 - libraries-2/pom.xml | 3 +- libraries-6/pom.xml | 2 +- logging-modules/flogger/pom.xml | 1 - logging-modules/log4j/pom.xml | 1 - logging-modules/log4j2/pom.xml | 1 - logging-modules/logback/pom.xml | 1 - logging-modules/pom.xml | 1 - maven-archetype/pom.xml | 1 - maven-modules/maven-generate-war/pom.xml | 126 ++++---- .../aggregator/module1/pom.xml | 2 +- .../aggregator/module2/module3/pom.xml | 2 +- .../aggregator/module2/pom.xml | 2 +- .../aggregator/pom.xml | 2 +- maven-modules/maven-printing-plugins/pom.xml | 6 +- maven-modules/maven-surefire-plugin/pom.xml | 2 +- maven-modules/pom.xml | 2 +- patterns/clean-architecture/pom.xml | 1 - persistence-modules/apache-derby/pom.xml | 13 +- persistence-modules/deltaspike/pom.xml | 4 +- .../spring-data-cassandra-2/pom.xml | 135 ++++----- .../spring-data-cassandra/pom.xml | 3 +- quarkus-vs-springboot/pom.xml | 16 +- quarkus-vs-springboot/quarkus-project/pom.xml | 277 +++++++++--------- quarkus-vs-springboot/spring-project/pom.xml | 33 ++- quarkus/pom.xml | 4 +- rule-engines/evrete/pom.xml | 9 +- spring-boot-modules/spring-boot-admin/pom.xml | 1 - .../spring-boot-admin-client/pom.xml | 1 - .../spring-boot-admin-server/pom.xml | 1 - .../spring-boot-angular/pom.xml | 1 - .../spring-boot-annotations/pom.xml | 1 - .../spring-boot-artifacts-2/pom.xml | 1 - .../spring-boot-artifacts/pom.xml | 1 - .../spring-boot-autoconfiguration/pom.xml | 1 - .../spring-boot-basic-customization-2/pom.xml | 1 - .../spring-boot-basic-customization/pom.xml | 1 - .../spring-boot-bootstrap/pom.xml | 1 - spring-boot-modules/spring-boot-ci-cd/pom.xml | 1 - .../spring-boot-client/pom.xml | 1 - .../spring-boot-config-jpa-error/pom.xml | 1 - spring-boot-modules/spring-boot-crud/pom.xml | 1 - .../spring-boot-ctx-fluent/pom.xml | 1 - .../greeter-spring-boot-sample-app/pom.xml | 1 - .../spring-boot-custom-starter/pom.xml | 1 - .../spring-boot-data-2/pom.xml | 1 - spring-boot-modules/spring-boot-data/pom.xml | 1 - .../spring-boot-deployment/pom.xml | 1 - spring-boot-modules/spring-boot-di/pom.xml | 1 - .../disabling-console-jul/pom.xml | 1 - .../disabling-console-log4j2/pom.xml | 1 - .../disabling-console-logback/pom.xml | 1 - .../spring-boot-disable-logging/pom.xml | 1 - .../spring-boot-environment/pom.xml | 1 - .../spring-boot-exceptions/pom.xml | 1 - .../spring-boot-flowable/pom.xml | 1 - .../spring-boot-jasypt/pom.xml | 1 - .../spring-boot-libraries/pom.xml | 1 - .../spring-boot-logging-log4j2/pom.xml | 4 +- spring-boot-modules/spring-boot-mvc-2/pom.xml | 1 - spring-boot-modules/spring-boot-mvc-3/pom.xml | 3 +- .../spring-boot-mvc-jersey/pom.xml | 1 - spring-boot-modules/spring-boot-mvc/pom.xml | 1 - .../spring-boot-nashorn/pom.xml | 1 - .../spring-boot-parent/pom.xml | 1 - .../spring-boot-with-custom-parent/pom.xml | 1 - .../spring-boot-with-starter-parent/pom.xml | 1 - .../spring-boot-performance/pom.xml | 1 - .../spring-boot-properties-2/pom.xml | 1 - .../spring-boot-properties-3/pom.xml | 1 - .../spring-boot-properties/pom.xml | 3 +- .../spring-boot-runtime-2/pom.xml | 3 +- .../spring-boot-runtime/pom.xml | 3 +- .../spring-boot-security/pom.xml | 3 +- .../spring-boot-springdoc/pom.xml | 3 +- .../spring-boot-swagger-jwt/pom.xml | 1 - .../spring-boot-swagger/pom.xml | 1 - .../spring-boot-testing/pom.xml | 3 +- spring-boot-modules/spring-boot-vue/pom.xml | 3 +- spring-boot-modules/spring-boot/pom.xml | 1 - spring-cloud-data-flow/pom.xml | 1 - spring-cloud/spring-cloud-aws/pom.xml | 4 +- .../order-service/order-client/pom.xml | 2 +- .../spring-cloud-connectors-heroku/pom.xml | 6 +- spring-cloud/spring-cloud-dapr/pom.xml | 2 +- .../docker-product-server/pom.xml | 2 +- spring-cloud/spring-cloud-docker/pom.xml | 2 +- .../rest-consumer/pom.xml | 1 - .../kubernetes-guide/client-service/pom.xml | 2 +- .../liveness-example/pom.xml | 2 +- .../twitterhdfs/pom.xml | 4 +- spring-ejb/pom.xml | 5 +- spring-quartz/pom.xml | 2 +- .../spring-5-security-oauth/pom.xml | 3 +- .../spring-security-web-boot-3/pom.xml | 4 +- .../spring-security-web-thymeleaf/pom.xml | 1 - testing-modules/assertion-libraries/pom.xml | 6 +- testing-modules/selenium-junit-testng/pom.xml | 4 +- 135 files changed, 533 insertions(+), 606 deletions(-) diff --git a/akka-http/pom.xml b/akka-http/pom.xml index 4b73fbc960..a64d7a80f6 100644 --- a/akka-http/pom.xml +++ b/akka-http/pom.xml @@ -41,4 +41,4 @@ 2.5.11 - + \ No newline at end of file diff --git a/aws-lambda/lambda/pom.xml b/aws-lambda/lambda/pom.xml index dea951d1b3..b2e5cc3b2d 100644 --- a/aws-lambda/lambda/pom.xml +++ b/aws-lambda/lambda/pom.xml @@ -63,7 +63,8 @@ json-simple ${json-simple.version} - + junit junit diff --git a/core-java-modules/core-java-10/pom.xml b/core-java-modules/core-java-10/pom.xml index b293110546..c3406751dc 100644 --- a/core-java-modules/core-java-10/pom.xml +++ b/core-java-modules/core-java-10/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml index 68e8b66d67..4c16ec7032 100644 --- a/core-java-modules/core-java-11-2/pom.xml +++ b/core-java-modules/core-java-11-2/pom.xml @@ -12,7 +12,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../.. diff --git a/core-java-modules/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml index def7ab43f7..d3ffb0a8f0 100644 --- a/core-java-modules/core-java-11/pom.xml +++ b/core-java-modules/core-java-11/pom.xml @@ -13,7 +13,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../.. diff --git a/core-java-modules/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml index 931fce820b..26b7d0c14d 100644 --- a/core-java-modules/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -13,7 +13,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../../ diff --git a/core-java-modules/core-java-13/pom.xml b/core-java-modules/core-java-13/pom.xml index 6369976580..d28618a21a 100644 --- a/core-java-modules/core-java-13/pom.xml +++ b/core-java-modules/core-java-13/pom.xml @@ -14,7 +14,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../../ diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml index a03332d8bc..4b0d030a34 100644 --- a/core-java-modules/core-java-14/pom.xml +++ b/core-java-modules/core-java-14/pom.xml @@ -12,7 +12,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../../ diff --git a/core-java-modules/core-java-16/pom.xml b/core-java-modules/core-java-16/pom.xml index 5d10325f03..d003ca9ae7 100644 --- a/core-java-modules/core-java-16/pom.xml +++ b/core-java-modules/core-java-16/pom.xml @@ -28,18 +28,18 @@ commons-lang3 3.12.0 - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter.version} - test - + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + test + @@ -50,37 +50,37 @@ ${maven-compiler-plugin.version} ${maven.compiler.release} - --enable-preview + --enable-preview ${maven.compiler.source.version} ${maven.compiler.target.version} - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.plugin.version} - - --enable-preview - 1 - - - - org.apache.maven.surefire - surefire-api - ${surefire.plugin.version} - - - + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + --enable-preview + 1 + + + + org.apache.maven.surefire + surefire-api + ${surefire.plugin.version} + + + 16 16 - 16 - 3.8.1 - 3.0.0-M5 - 3.17.2 + 16 + 3.8.1 + 3.0.0-M5 + 3.17.2 \ No newline at end of file diff --git a/core-java-modules/core-java-17/pom.xml b/core-java-modules/core-java-17/pom.xml index f9a7ec326b..7024705cc2 100644 --- a/core-java-modules/core-java-17/pom.xml +++ b/core-java-modules/core-java-17/pom.xml @@ -23,18 +23,18 @@ ${assertj.version} test - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter.version} - test - + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + test + @@ -50,32 +50,32 @@ ${maven.compiler.target.version} - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.plugin.version} - - --enable-preview - 1 - - - - org.apache.maven.surefire - surefire-api - ${surefire.plugin.version} - - - + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + --enable-preview + 1 + + + + org.apache.maven.surefire + surefire-api + ${surefire.plugin.version} + + + 17 17 - 17 - 3.8.1 - 3.0.0-M5 - 3.17.2 + 17 + 3.8.1 + 3.0.0-M5 + 3.17.2 \ No newline at end of file diff --git a/core-java-modules/core-java-annotations/pom.xml b/core-java-modules/core-java-annotations/pom.xml index a87baa6204..19d02aa2ac 100644 --- a/core-java-modules/core-java-annotations/pom.xml +++ b/core-java-modules/core-java-annotations/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 core-java-annotations 0.1.0-SNAPSHOT @@ -37,4 +37,4 @@ - + \ No newline at end of file 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 065f1930e2..d122e3330c 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -19,20 +19,17 @@ commons-lang3 ${commons-lang3.version} - org.assertj assertj-core ${assertj-core.version} test - org.openjdk.jmh jmh-core ${jmh.version} - org.openjdk.jmh jmh-generator-annprocess diff --git a/core-java-modules/core-java-collections-maps-4/pom.xml b/core-java-modules/core-java-collections-maps-4/pom.xml index 1835e3ceac..bfb91515fa 100644 --- a/core-java-modules/core-java-collections-maps-4/pom.xml +++ b/core-java-modules/core-java-collections-maps-4/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 core-java-collections-maps-4 0.1.0-SNAPSHOT @@ -31,4 +31,4 @@ - + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-set/pom.xml b/core-java-modules/core-java-collections-set/pom.xml index b8940f4a68..359c0fc86f 100644 --- a/core-java-modules/core-java-collections-set/pom.xml +++ b/core-java-modules/core-java-collections-set/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index 7b7c68d1b6..854d6ed916 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-datetime-string/pom.xml b/core-java-modules/core-java-datetime-string/pom.xml index f50eb2ae5e..8bc7b60126 100644 --- a/core-java-modules/core-java-datetime-string/pom.xml +++ b/core-java-modules/core-java-datetime-string/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-io-conversions-2/pom.xml b/core-java-modules/core-java-io-conversions-2/pom.xml index dcb9d494dc..24708ad967 100644 --- a/core-java-modules/core-java-io-conversions-2/pom.xml +++ b/core-java-modules/core-java-io-conversions-2/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 0cf6d6767e..a036818226 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index afbe0b0ee3..77d0aaf54b 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-os/pom.xml b/core-java-modules/core-java-os/pom.xml index b279e3d6cb..b163052ea2 100644 --- a/core-java-modules/core-java-os/pom.xml +++ b/core-java-modules/core-java-os/pom.xml @@ -1,99 +1,99 @@ - 4.0.0 - core-java-os - 0.1.0-SNAPSHOT - core-java-os - jar + 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-os + 0.1.0-SNAPSHOT + core-java-os + jar - - com.baeldung.core-java-modules - core-java-modules - 0.0.1-SNAPSHOT - ../ - + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + - - - org.junit.jupiter - junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-engine ${junit-jupiter.version} - test - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - commons-io - commons-io - ${commons-io.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - log4j - log4j - ${log4j.version} - - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.unix4j - unix4j-command - ${unix4j.version} - - - com.googlecode.grep4j - grep4j - ${grep4j.version} - - + test + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + log4j + log4j + ${log4j.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.unix4j + unix4j-command + ${unix4j.version} + + + com.googlecode.grep4j + grep4j + ${grep4j.version} + + - - core-java-os - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - + + core-java-os + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + - - - 4.1 - 4.01 - - 3.6.1 - 1.8.9 - 1.9 - 1.9 - 25.1-jre - 0.4 - 1.8.7 - + + + 4.1 + 4.01 + + 3.6.1 + 1.8.9 + 1.9 + 1.9 + 25.1-jre + 0.4 + 1.8.7 + \ No newline at end of file diff --git a/core-java-modules/core-java-security-3/pom.xml b/core-java-modules/core-java-security-3/pom.xml index 69d0ffb917..a0e73a1e29 100644 --- a/core-java-modules/core-java-security-3/pom.xml +++ b/core-java-modules/core-java-security-3/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ 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 6376bfa677..67a6443bc6 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -4,8 +4,8 @@ 4.0.0 core-java-string-algorithms-3 0.1.0-SNAPSHOT - jar core-java-string-algorithms-3 + jar com.baeldung.core-java-modules @@ -66,4 +66,4 @@ 1.7 - + \ No newline at end of file diff --git a/core-java-modules/core-java-string-operations-3/pom.xml b/core-java-modules/core-java-string-operations-3/pom.xml index 20e9bcb39a..2567f776b1 100644 --- a/core-java-modules/core-java-string-operations-3/pom.xml +++ b/core-java-modules/core-java-string-operations-3/pom.xml @@ -92,4 +92,4 @@ 3.1.0 - + \ No newline at end of file diff --git a/core-java-modules/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml index 347020a736..4c26b59168 100644 --- a/core-java-modules/core-java-sun/pom.xml +++ b/core-java-modules/core-java-sun/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml index 663cf6708b..69de5c04fa 100644 --- a/core-java-modules/core-java-time-measurements/pom.xml +++ b/core-java-modules/core-java-time-measurements/pom.xml @@ -13,7 +13,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ diff --git a/drools/pom.xml b/drools/pom.xml index cc96d9d032..daaf1fa8a7 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -19,7 +19,6 @@ httpcore ${http-component-version} - org.kie kie-ci diff --git a/feign/pom.xml b/feign/pom.xml index 56059d2a77..cf28890868 100644 --- a/feign/pom.xml +++ b/feign/pom.xml @@ -11,7 +11,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - .. diff --git a/flyway-cdi-extension/pom.xml b/flyway-cdi-extension/pom.xml index dbd21374e2..3d52ff0e36 100644 --- a/flyway-cdi-extension/pom.xml +++ b/flyway-cdi-extension/pom.xml @@ -11,7 +11,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - .. diff --git a/guava-modules/guava-18/pom.xml b/guava-modules/guava-18/pom.xml index ed295db2f4..8f5108bff1 100644 --- a/guava-modules/guava-18/pom.xml +++ b/guava-modules/guava-18/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-19/pom.xml b/guava-modules/guava-19/pom.xml index 3c29a2a59c..ba85fe0ae8 100644 --- a/guava-modules/guava-19/pom.xml +++ b/guava-modules/guava-19/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-21/pom.xml b/guava-modules/guava-21/pom.xml index 8b7c3cdcfd..9e791bfe23 100644 --- a/guava-modules/guava-21/pom.xml +++ b/guava-modules/guava-21/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-collections-list/pom.xml b/guava-modules/guava-collections-list/pom.xml index e57198ec40..b90f70764f 100644 --- a/guava-modules/guava-collections-list/pom.xml +++ b/guava-modules/guava-collections-list/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-collections-map/pom.xml b/guava-modules/guava-collections-map/pom.xml index 7f3e470fc3..e34d1a33a6 100644 --- a/guava-modules/guava-collections-map/pom.xml +++ b/guava-modules/guava-collections-map/pom.xml @@ -12,7 +12,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-collections-set/pom.xml b/guava-modules/guava-collections-set/pom.xml index 09e3f42e83..1953ade44f 100644 --- a/guava-modules/guava-collections-set/pom.xml +++ b/guava-modules/guava-collections-set/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-collections/pom.xml b/guava-modules/guava-collections/pom.xml index 6dc7510a1e..be75f93d29 100644 --- a/guava-modules/guava-collections/pom.xml +++ b/guava-modules/guava-collections/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-core/pom.xml b/guava-modules/guava-core/pom.xml index a15dfb5178..2540ac97a7 100644 --- a/guava-modules/guava-core/pom.xml +++ b/guava-modules/guava-core/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-io/pom.xml b/guava-modules/guava-io/pom.xml index 11a5d4ada6..de1ab926dc 100644 --- a/guava-modules/guava-io/pom.xml +++ b/guava-modules/guava-io/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/guava-modules/guava-utilities/pom.xml b/guava-modules/guava-utilities/pom.xml index 6049a62e85..deac03b406 100644 --- a/guava-modules/guava-utilities/pom.xml +++ b/guava-modules/guava-utilities/pom.xml @@ -11,7 +11,6 @@ com.baeldung guava-modules 0.0.1-SNAPSHOT - ../ diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index 700a0a02d4..0988ed454e 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -54,7 +54,8 @@ jbpm-test ${jbpm.version} - + junit junit diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index cecc9ca476..cf2c2c551d 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -157,4 +157,4 @@ 2.4.4 - + \ No newline at end of file diff --git a/logging-modules/flogger/pom.xml b/logging-modules/flogger/pom.xml index b96025f277..c814d31767 100644 --- a/logging-modules/flogger/pom.xml +++ b/logging-modules/flogger/pom.xml @@ -9,7 +9,6 @@ com.baeldung logging-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml index 864e2253b5..d3c7f8287e 100644 --- a/logging-modules/log4j/pom.xml +++ b/logging-modules/log4j/pom.xml @@ -11,7 +11,6 @@ com.baeldung logging-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index aaf60a4216..0b6fa9b902 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -10,7 +10,6 @@ com.baeldung logging-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml index 512dc9e5a3..48bb37b881 100644 --- a/logging-modules/logback/pom.xml +++ b/logging-modules/logback/pom.xml @@ -11,7 +11,6 @@ com.baeldung logging-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/logging-modules/pom.xml b/logging-modules/pom.xml index 7e358ae490..c7a770891d 100644 --- a/logging-modules/pom.xml +++ b/logging-modules/pom.xml @@ -11,7 +11,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/maven-archetype/pom.xml b/maven-archetype/pom.xml index 2eab8ac614..04247f622c 100644 --- a/maven-archetype/pom.xml +++ b/maven-archetype/pom.xml @@ -18,7 +18,6 @@ ${archetype-packaging.version} - diff --git a/maven-modules/maven-generate-war/pom.xml b/maven-modules/maven-generate-war/pom.xml index e5b42f5090..56256f58ea 100644 --- a/maven-modules/maven-generate-war/pom.xml +++ b/maven-modules/maven-generate-war/pom.xml @@ -1,62 +1,68 @@ - -4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.5.4 - - - -com.baeldung -maven-generate-war -0.0.1-SNAPSHOT -war -maven-generate-war -Spring boot project to demonstrate war file generation - - 11 - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - org.springframework.boot - spring-boot-starter-test - test - - - - maven-generate-war - - - maven-war-plugin - 3.3.1 - - - - additional_resources - - - - - true - - - - - - - + + 4.0.0 + com.baeldung + maven-generate-war + 0.0.1-SNAPSHOT + war + maven-generate-war + Spring boot project to demonstrate war file generation + + org.springframework.boot + spring-boot-starter-parent + 2.5.4 + + + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + + + maven-generate-war + + + maven-war-plugin + 3.3.1 + + + + additional_resources + + + + + true + + + + + + + + + 11 + + + \ No newline at end of file diff --git a/maven-modules/maven-parent-pom-resolution/aggregator/module1/pom.xml b/maven-modules/maven-parent-pom-resolution/aggregator/module1/pom.xml index e1f411db2f..67e60fb386 100644 --- a/maven-modules/maven-parent-pom-resolution/aggregator/module1/pom.xml +++ b/maven-modules/maven-parent-pom-resolution/aggregator/module1/pom.xml @@ -13,4 +13,4 @@ - + \ No newline at end of file diff --git a/maven-modules/maven-parent-pom-resolution/aggregator/module2/module3/pom.xml b/maven-modules/maven-parent-pom-resolution/aggregator/module2/module3/pom.xml index d983f35e3e..f4e3e81e7d 100644 --- a/maven-modules/maven-parent-pom-resolution/aggregator/module2/module3/pom.xml +++ b/maven-modules/maven-parent-pom-resolution/aggregator/module2/module3/pom.xml @@ -15,4 +15,4 @@ ../../pom.xml - + \ No newline at end of file diff --git a/maven-modules/maven-parent-pom-resolution/aggregator/module2/pom.xml b/maven-modules/maven-parent-pom-resolution/aggregator/module2/pom.xml index 48c1ebab9d..9b36ef37fb 100644 --- a/maven-modules/maven-parent-pom-resolution/aggregator/module2/pom.xml +++ b/maven-modules/maven-parent-pom-resolution/aggregator/module2/pom.xml @@ -18,4 +18,4 @@ module3 - + \ No newline at end of file diff --git a/maven-modules/maven-parent-pom-resolution/aggregator/pom.xml b/maven-modules/maven-parent-pom-resolution/aggregator/pom.xml index 8f6e3453a5..dde2c46370 100644 --- a/maven-modules/maven-parent-pom-resolution/aggregator/pom.xml +++ b/maven-modules/maven-parent-pom-resolution/aggregator/pom.xml @@ -19,4 +19,4 @@ module2 - + \ No newline at end of file diff --git a/maven-modules/maven-printing-plugins/pom.xml b/maven-modules/maven-printing-plugins/pom.xml index 07ddd8d1e8..aacc829b93 100644 --- a/maven-modules/maven-printing-plugins/pom.xml +++ b/maven-modules/maven-printing-plugins/pom.xml @@ -76,8 +76,10 @@ log.info('Test message: {}', 'Hello, World!') - log.info('Embed a line break {}', System.lineSeparator()) - log.info('ArtifactId is: ${project.artifactId}') + log.info('Embed a + line break {}', System.lineSeparator()) + log.info('ArtifactId is: + ${project.artifactId}') log.warn('Message only in debug mode') diff --git a/maven-modules/maven-surefire-plugin/pom.xml b/maven-modules/maven-surefire-plugin/pom.xml index 98decc69e1..840ffab077 100644 --- a/maven-modules/maven-surefire-plugin/pom.xml +++ b/maven-modules/maven-surefire-plugin/pom.xml @@ -14,4 +14,4 @@ 0.0.1-SNAPSHOT - + \ No newline at end of file diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 0aadb873e5..12fd44e739 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -37,7 +37,7 @@ plugin-management maven-surefire-plugin maven-parent-pom-resolution - maven-dependency + maven-dependency diff --git a/patterns/clean-architecture/pom.xml b/patterns/clean-architecture/pom.xml index c36f9b83af..71f50907fd 100644 --- a/patterns/clean-architecture/pom.xml +++ b/patterns/clean-architecture/pom.xml @@ -71,7 +71,6 @@ - org.springframework.boot spring-boot-maven-plugin diff --git a/persistence-modules/apache-derby/pom.xml b/persistence-modules/apache-derby/pom.xml index 7728bd4d8f..f7f5ca7503 100644 --- a/persistence-modules/apache-derby/pom.xml +++ b/persistence-modules/apache-derby/pom.xml @@ -1,15 +1,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 + apache-derby + persistence-modules com.baeldung 1.0.0-SNAPSHOT - 4.0.0 - - apache-derby @@ -18,15 +18,12 @@ derby 10.13.1.1 - org.apache.derby derbyclient 10.13.1.1 - - \ No newline at end of file diff --git a/persistence-modules/deltaspike/pom.xml b/persistence-modules/deltaspike/pom.xml index 5003ef9daf..f151255948 100644 --- a/persistence-modules/deltaspike/pom.xml +++ b/persistence-modules/deltaspike/pom.xml @@ -18,8 +18,8 @@ - + junit junit diff --git a/persistence-modules/spring-data-cassandra-2/pom.xml b/persistence-modules/spring-data-cassandra-2/pom.xml index 0e09448d0f..8202471d19 100644 --- a/persistence-modules/spring-data-cassandra-2/pom.xml +++ b/persistence-modules/spring-data-cassandra-2/pom.xml @@ -1,72 +1,73 @@ - - 4.0.0 - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - + + 4.0.0 + org.baeldung + spring-cassandra + 0.0.1-SNAPSHOT + spring-cassandra + Demo project for Spring Data Cassandra - org.baeldung - spring-cassandra - 0.0.1-SNAPSHOT - spring-cassandra - Demo project for Spring Data Cassandra + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + - - - org.springframework.boot - spring-boot-starter-data-cassandra - - - org.springframework.data - spring-data-cassandra - ${org.springframework.data.version} - - - uk.org.webcompere - system-stubs-core - ${system.stubs.version} - - - org.springframework.boot - spring-boot-starter-test - test - - - org.testcontainers - testcontainers - ${testcontainers.version} - test - - - org.testcontainers - cassandra - ${testcontainers.version} - test - - - org.testcontainers - junit-jupiter - ${testcontainers.version} - test - - - uk.org.webcompere - system-stubs-jupiter - ${system.stubs.version} - test - - + + + org.springframework.boot + spring-boot-starter-data-cassandra + + + org.springframework.data + spring-data-cassandra + ${org.springframework.data.version} + + + uk.org.webcompere + system-stubs-core + ${system.stubs.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.testcontainers + testcontainers + ${testcontainers.version} + test + + + org.testcontainers + cassandra + ${testcontainers.version} + test + + + org.testcontainers + junit-jupiter + ${testcontainers.version} + test + + + uk.org.webcompere + system-stubs-jupiter + ${system.stubs.version} + test + + - - 11 - 3.1.11 - 1.15.3 - 1.1.0 - 5.6.2 - + + 11 + 3.1.11 + 1.15.3 + 1.1.0 + 5.6.2 + - + \ No newline at end of file diff --git a/persistence-modules/spring-data-cassandra/pom.xml b/persistence-modules/spring-data-cassandra/pom.xml index 8092c05a40..925031b141 100644 --- a/persistence-modules/spring-data-cassandra/pom.xml +++ b/persistence-modules/spring-data-cassandra/pom.xml @@ -49,7 +49,8 @@ ${cassandra-unit-shaded.version} test - + junit junit diff --git a/quarkus-vs-springboot/pom.xml b/quarkus-vs-springboot/pom.xml index cf1cbb5d85..1726d076da 100644 --- a/quarkus-vs-springboot/pom.xml +++ b/quarkus-vs-springboot/pom.xml @@ -1,19 +1,19 @@ + 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 + quarkus-vs-springboot + 1.0-SNAPSHOT + quarkus-vs-springboot + pom + parent-modules com.baeldung 1.0.0-SNAPSHOT - 1.0-SNAPSHOT - quarkus-vs-springboot - quarkus-vs-springboot - pom - 4.0.0 - quarkus-project spring-project diff --git a/quarkus-vs-springboot/quarkus-project/pom.xml b/quarkus-vs-springboot/quarkus-project/pom.xml index 58d547f3b0..eeeb9d3256 100644 --- a/quarkus-vs-springboot/quarkus-project/pom.xml +++ b/quarkus-vs-springboot/quarkus-project/pom.xml @@ -1,143 +1,150 @@ - - 4.0.0 - - com.baeldung - quarkus-vs-springboot - 1.0-SNAPSHOT - - quarkus-project - 0.1-SNAPSHOT - - 3.8.1 - true - 11 - 11 - UTF-8 - UTF-8 - quarkus-bom - io.quarkus.platform - 2.2.2.Final - 3.0.0-M4 - - + 4.0.0 + quarkus-project + 0.1-SNAPSHOT + + + com.baeldung + quarkus-vs-springboot + 1.0-SNAPSHOT + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + - - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} - pom - import - + + io.quarkus + quarkus-hibernate-reactive-panache + + + io.quarkus + quarkus-resteasy-reactive + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-reactive-pg-client + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-container-image-docker + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + - - - - io.quarkus - quarkus-hibernate-reactive-panache - - - io.quarkus - quarkus-resteasy-reactive - - - io.quarkus - quarkus-resteasy-reactive-jackson - - - io.quarkus - quarkus-reactive-pg-client - - - io.quarkus - quarkus-arc - - - io.quarkus - quarkus-container-image-docker - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - - - - ${quarkus.platform.group-id} - quarkus-maven-plugin - ${quarkus.platform.version} - true - - - - build - generate-code - generate-code-tests - - - - - - maven-compiler-plugin - ${compiler-plugin.version} - - ${maven.compiler.parameters} - - - - maven-surefire-plugin - ${surefire-plugin.version} - - false - - org.jboss.logmanager.LogManager - - - - - - - - native - - - native - - - + + - - maven-failsafe-plugin - ${surefire-plugin.version} - - - - integration-test - verify - + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + + + + + + maven-compiler-plugin + ${compiler-plugin.version} - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - + ${maven.compiler.parameters} - - - + + + maven-surefire-plugin + ${surefire-plugin.version} + + false + + org.jboss.logmanager.LogManager + + + - - - -H:+AllowVMInspection - native - - - - + + + + native + + + native + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + + + + + + + + + -H:+AllowVMInspection + native + + + + + + 3.8.1 + true + 11 + 11 + UTF-8 + UTF-8 + quarkus-bom + io.quarkus.platform + 2.2.2.Final + 3.0.0-M4 + + + \ No newline at end of file diff --git a/quarkus-vs-springboot/spring-project/pom.xml b/quarkus-vs-springboot/spring-project/pom.xml index be5cc57765..128966c07e 100644 --- a/quarkus-vs-springboot/spring-project/pom.xml +++ b/quarkus-vs-springboot/spring-project/pom.xml @@ -1,25 +1,18 @@ - - - org.springframework.boot - spring-boot-starter-parent - 2.5.4 - - - + 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 spring-project com.baeldung 0.1-SNAPSHOT - - 11 - - 0.10.3 - + + org.springframework.boot + spring-boot-starter-parent + 2.5.4 + + @@ -161,11 +154,19 @@ org.apache.maven.plugins maven-surefire-plugin - -DspringAot=true -agentlib:native-image-agent=access-filter-file=src/test/resources/access-filter.json,config-merge-dir=target/classes/META-INF/native-image + -DspringAot=true + -agentlib:native-image-agent=access-filter-file=src/test/resources/access-filter.json,config-merge-dir=target/classes/META-INF/native-image + + + 11 + + 0.10.3 + + \ No newline at end of file diff --git a/quarkus/pom.xml b/quarkus/pom.xml index d826729ad7..22f5e0e991 100644 --- a/quarkus/pom.xml +++ b/quarkus/pom.xml @@ -16,8 +16,8 @@ - + junit junit diff --git a/rule-engines/evrete/pom.xml b/rule-engines/evrete/pom.xml index 819a912c43..cfcadcb2ea 100644 --- a/rule-engines/evrete/pom.xml +++ b/rule-engines/evrete/pom.xml @@ -8,10 +8,6 @@ 1.0 evrete - - 2.1.04 - - com.baeldung rule-engines @@ -32,4 +28,9 @@ ${evrete.version} + + + 2.1.04 + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-admin/pom.xml b/spring-boot-modules/spring-boot-admin/pom.xml index b995b6f02e..509abfa013 100644 --- a/spring-boot-modules/spring-boot-admin/pom.xml +++ b/spring-boot-modules/spring-boot-admin/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/pom.xml b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/pom.xml index eca92ff3a5..72f828b259 100644 --- a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/pom.xml +++ b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-admin 0.0.1-SNAPSHOT - ../ 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 a1daa3fa19..0ccd43e0b9 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 @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-admin 0.0.1-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-angular/pom.xml b/spring-boot-modules/spring-boot-angular/pom.xml index 89a8814d2f..d713510cff 100644 --- a/spring-boot-modules/spring-boot-angular/pom.xml +++ b/spring-boot-modules/spring-boot-angular/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-annotations/pom.xml b/spring-boot-modules/spring-boot-annotations/pom.xml index 22572e7492..618ae6024b 100644 --- a/spring-boot-modules/spring-boot-annotations/pom.xml +++ b/spring-boot-modules/spring-boot-annotations/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-artifacts-2/pom.xml b/spring-boot-modules/spring-boot-artifacts-2/pom.xml index 8cf78b79e0..3b9390e973 100644 --- a/spring-boot-modules/spring-boot-artifacts-2/pom.xml +++ b/spring-boot-modules/spring-boot-artifacts-2/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-artifacts/pom.xml b/spring-boot-modules/spring-boot-artifacts/pom.xml index 7ed91a6626..5b4f5a1dd1 100644 --- a/spring-boot-modules/spring-boot-artifacts/pom.xml +++ b/spring-boot-modules/spring-boot-artifacts/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml index bf8bcc5a87..b5e85bad59 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-basic-customization-2/pom.xml b/spring-boot-modules/spring-boot-basic-customization-2/pom.xml index 6f3cb48b81..7a086331ab 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization-2/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index 5ab747cff1..2782c3320e 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-bootstrap/pom.xml b/spring-boot-modules/spring-boot-bootstrap/pom.xml index f94ee9ca31..caa3f6c7fc 100644 --- a/spring-boot-modules/spring-boot-bootstrap/pom.xml +++ b/spring-boot-modules/spring-boot-bootstrap/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-ci-cd/pom.xml b/spring-boot-modules/spring-boot-ci-cd/pom.xml index fb1810c62e..68a9f21d20 100644 --- a/spring-boot-modules/spring-boot-ci-cd/pom.xml +++ b/spring-boot-modules/spring-boot-ci-cd/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-client/pom.xml b/spring-boot-modules/spring-boot-client/pom.xml index 7f54d0e541..8ae2cbee79 100644 --- a/spring-boot-modules/spring-boot-client/pom.xml +++ b/spring-boot-modules/spring-boot-client/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-config-jpa-error/pom.xml b/spring-boot-modules/spring-boot-config-jpa-error/pom.xml index b5207f8997..6291589e7a 100644 --- a/spring-boot-modules/spring-boot-config-jpa-error/pom.xml +++ b/spring-boot-modules/spring-boot-config-jpa-error/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-crud/pom.xml b/spring-boot-modules/spring-boot-crud/pom.xml index 79eccf2fba..0a8e57be17 100644 --- a/spring-boot-modules/spring-boot-crud/pom.xml +++ b/spring-boot-modules/spring-boot-crud/pom.xml @@ -10,7 +10,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-ctx-fluent/pom.xml b/spring-boot-modules/spring-boot-ctx-fluent/pom.xml index 8a7aca076e..deefefc87c 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/pom.xml +++ b/spring-boot-modules/spring-boot-ctx-fluent/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml index 815c3e8366..c4759af373 100644 --- a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml +++ b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-custom-starter 0.0.1-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-custom-starter/pom.xml b/spring-boot-modules/spring-boot-custom-starter/pom.xml index 27e3a03153..aee98b125e 100644 --- a/spring-boot-modules/spring-boot-custom-starter/pom.xml +++ b/spring-boot-modules/spring-boot-custom-starter/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-data-2/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml index b7006782c8..a3c2430497 100644 --- a/spring-boot-modules/spring-boot-data-2/pom.xml +++ b/spring-boot-modules/spring-boot-data-2/pom.xml @@ -9,7 +9,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-data/pom.xml b/spring-boot-modules/spring-boot-data/pom.xml index 447b730c02..c57dad49f4 100644 --- a/spring-boot-modules/spring-boot-data/pom.xml +++ b/spring-boot-modules/spring-boot-data/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-deployment/pom.xml b/spring-boot-modules/spring-boot-deployment/pom.xml index 7c78d20afc..c4d9fa7059 100644 --- a/spring-boot-modules/spring-boot-deployment/pom.xml +++ b/spring-boot-modules/spring-boot-deployment/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-di/pom.xml b/spring-boot-modules/spring-boot-di/pom.xml index 0e9fb49a95..af0dd7e4de 100644 --- a/spring-boot-modules/spring-boot-di/pom.xml +++ b/spring-boot-modules/spring-boot-di/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-disable-logging/disabling-console-jul/pom.xml b/spring-boot-modules/spring-boot-disable-logging/disabling-console-jul/pom.xml index deee4e435f..ace21410ea 100644 --- a/spring-boot-modules/spring-boot-disable-logging/disabling-console-jul/pom.xml +++ b/spring-boot-modules/spring-boot-disable-logging/disabling-console-jul/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-disable-logging 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-disable-logging/disabling-console-log4j2/pom.xml b/spring-boot-modules/spring-boot-disable-logging/disabling-console-log4j2/pom.xml index 0524f9d401..b71e1066e7 100644 --- a/spring-boot-modules/spring-boot-disable-logging/disabling-console-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-disable-logging/disabling-console-log4j2/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-disable-logging 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-disable-logging/disabling-console-logback/pom.xml b/spring-boot-modules/spring-boot-disable-logging/disabling-console-logback/pom.xml index 0990209ff9..37fad3ec53 100644 --- a/spring-boot-modules/spring-boot-disable-logging/disabling-console-logback/pom.xml +++ b/spring-boot-modules/spring-boot-disable-logging/disabling-console-logback/pom.xml @@ -10,7 +10,6 @@ com.baeldung.spring-boot-modules spring-boot-disable-logging 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-disable-logging/pom.xml b/spring-boot-modules/spring-boot-disable-logging/pom.xml index 65de521c63..31b02009b6 100644 --- a/spring-boot-modules/spring-boot-disable-logging/pom.xml +++ b/spring-boot-modules/spring-boot-disable-logging/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index d4b260ee3d..504a0e2539 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-exceptions/pom.xml b/spring-boot-modules/spring-boot-exceptions/pom.xml index cec1bab4ff..b1240957f6 100644 --- a/spring-boot-modules/spring-boot-exceptions/pom.xml +++ b/spring-boot-modules/spring-boot-exceptions/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-flowable/pom.xml b/spring-boot-modules/spring-boot-flowable/pom.xml index 320a684880..9d8daa022d 100644 --- a/spring-boot-modules/spring-boot-flowable/pom.xml +++ b/spring-boot-modules/spring-boot-flowable/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-jasypt/pom.xml b/spring-boot-modules/spring-boot-jasypt/pom.xml index 0a37c545ac..8595b9c639 100644 --- a/spring-boot-modules/spring-boot-jasypt/pom.xml +++ b/spring-boot-modules/spring-boot-jasypt/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index ad00629e14..eee469ea46 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml index dafbddb93f..8cf052deb3 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml @@ -18,8 +18,8 @@ - + junit junit diff --git a/spring-boot-modules/spring-boot-mvc-2/pom.xml b/spring-boot-modules/spring-boot-mvc-2/pom.xml index d347b36b3b..f303171df8 100644 --- a/spring-boot-modules/spring-boot-mvc-2/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-2/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml index a46837e315..dee217862d 100644 --- a/spring-boot-modules/spring-boot-mvc-3/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -4,15 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-mvc-3 - jar spring-boot-mvc-3 + jar Module For Spring Boot MVC Web com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-mvc-jersey/pom.xml b/spring-boot-modules/spring-boot-mvc-jersey/pom.xml index b6e2c62663..34b459d1dc 100644 --- a/spring-boot-modules/spring-boot-mvc-jersey/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-jersey/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc/pom.xml index 3e835691aa..6d3f722146 100644 --- a/spring-boot-modules/spring-boot-mvc/pom.xml +++ b/spring-boot-modules/spring-boot-mvc/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-nashorn/pom.xml b/spring-boot-modules/spring-boot-nashorn/pom.xml index 89b0b984bc..0ae108ffd0 100644 --- a/spring-boot-modules/spring-boot-nashorn/pom.xml +++ b/spring-boot-modules/spring-boot-nashorn/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-parent/pom.xml b/spring-boot-modules/spring-boot-parent/pom.xml index 28a940bcd0..d9c23b66ac 100644 --- a/spring-boot-modules/spring-boot-parent/pom.xml +++ b/spring-boot-modules/spring-boot-parent/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-parent/spring-boot-with-custom-parent/pom.xml b/spring-boot-modules/spring-boot-parent/spring-boot-with-custom-parent/pom.xml index a61a5fd057..18fa4c53d9 100644 --- a/spring-boot-modules/spring-boot-parent/spring-boot-with-custom-parent/pom.xml +++ b/spring-boot-modules/spring-boot-parent/spring-boot-with-custom-parent/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-parent 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-parent/spring-boot-with-starter-parent/pom.xml b/spring-boot-modules/spring-boot-parent/spring-boot-with-starter-parent/pom.xml index 2568714278..e65f590c9b 100644 --- a/spring-boot-modules/spring-boot-parent/spring-boot-with-starter-parent/pom.xml +++ b/spring-boot-modules/spring-boot-parent/spring-boot-with-starter-parent/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-parent 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-performance/pom.xml b/spring-boot-modules/spring-boot-performance/pom.xml index f1f9b52dc4..38f5758c1f 100644 --- a/spring-boot-modules/spring-boot-performance/pom.xml +++ b/spring-boot-modules/spring-boot-performance/pom.xml @@ -11,7 +11,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-properties-2/pom.xml b/spring-boot-modules/spring-boot-properties-2/pom.xml index 62f23da450..d5aaab54d3 100644 --- a/spring-boot-modules/spring-boot-properties-2/pom.xml +++ b/spring-boot-modules/spring-boot-properties-2/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-properties-3/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml index b5e6ef8701..d72c410d9b 100644 --- a/spring-boot-modules/spring-boot-properties-3/pom.xml +++ b/spring-boot-modules/spring-boot-properties-3/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index 0ef44e0546..8cbaccdac5 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -4,16 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-properties - jar 0.0.1-SNAPSHOT spring-boot-properties + jar Spring Boot Properties Module com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-runtime-2/pom.xml b/spring-boot-modules/spring-boot-runtime-2/pom.xml index c177529a41..e6483e9ec0 100644 --- a/spring-boot-modules/spring-boot-runtime-2/pom.xml +++ b/spring-boot-modules/spring-boot-runtime-2/pom.xml @@ -4,15 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-runtime-2 - jar spring-boot-runtime-2 + jar Demo project for Spring Boot com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-runtime/pom.xml b/spring-boot-modules/spring-boot-runtime/pom.xml index 92b1458cf6..d42ae303a7 100644 --- a/spring-boot-modules/spring-boot-runtime/pom.xml +++ b/spring-boot-modules/spring-boot-runtime/pom.xml @@ -4,15 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-runtime - jar spring-boot-runtime + jar Demo project for Spring Boot Runtime com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-security/pom.xml b/spring-boot-modules/spring-boot-security/pom.xml index 11e5a38eeb..41dbcff38d 100644 --- a/spring-boot-modules/spring-boot-security/pom.xml +++ b/spring-boot-modules/spring-boot-security/pom.xml @@ -4,15 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-security - jar spring-boot-security + jar Spring Boot Security Auto-Configuration com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml index 892fbfe4ca..10bd9a7534 100644 --- a/spring-boot-modules/spring-boot-springdoc/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/pom.xml @@ -5,15 +5,14 @@ 4.0.0 spring-boot-springdoc 0.0.1-SNAPSHOT - jar spring-boot-springdoc + jar Project for Springdoc integration com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-swagger-jwt/pom.xml b/spring-boot-modules/spring-boot-swagger-jwt/pom.xml index c296b06388..e0d96627cd 100644 --- a/spring-boot-modules/spring-boot-swagger-jwt/pom.xml +++ b/spring-boot-modules/spring-boot-swagger-jwt/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-swagger/pom.xml b/spring-boot-modules/spring-boot-swagger/pom.xml index a9d8a943e4..87ee5f04cb 100644 --- a/spring-boot-modules/spring-boot-swagger/pom.xml +++ b/spring-boot-modules/spring-boot-swagger/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index f70e77b31a..2f33c44d60 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -4,15 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-testing - war spring-boot-testing + war This is simple boot application for demonstrating testing features. com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot-vue/pom.xml b/spring-boot-modules/spring-boot-vue/pom.xml index 3d3d51797c..c552a9583f 100644 --- a/spring-boot-modules/spring-boot-vue/pom.xml +++ b/spring-boot-modules/spring-boot-vue/pom.xml @@ -5,15 +5,14 @@ 4.0.0 spring-boot-vue 0.0.1-SNAPSHOT - jar spring-boot-vue + jar Demo project for Spring Boot Vue project com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-boot-modules/spring-boot/pom.xml b/spring-boot-modules/spring-boot/pom.xml index 8df16a1f9c..58c4e39043 100644 --- a/spring-boot-modules/spring-boot/pom.xml +++ b/spring-boot-modules/spring-boot/pom.xml @@ -13,7 +13,6 @@ com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - ../ diff --git a/spring-cloud-data-flow/pom.xml b/spring-cloud-data-flow/pom.xml index f81daeeabc..49a5accb90 100644 --- a/spring-cloud-data-flow/pom.xml +++ b/spring-cloud-data-flow/pom.xml @@ -7,7 +7,6 @@ 0.0.1-SNAPSHOT spring-cloud-data-flow pom - com.baeldung parent-boot-2 diff --git a/spring-cloud/spring-cloud-aws/pom.xml b/spring-cloud/spring-cloud-aws/pom.xml index c9cd56bea6..c313e2026a 100644 --- a/spring-cloud/spring-cloud-aws/pom.xml +++ b/spring-cloud/spring-cloud-aws/pom.xml @@ -18,8 +18,8 @@ - + junit junit diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml index dc6e196325..5326e181e0 100644 --- a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml @@ -16,4 +16,4 @@ 1.0.0-SNAPSHOT - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index 967b1b3caf..b13c512cc0 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -28,7 +28,7 @@ - + org.springframework.boot spring-boot-starter-cloud-connectors ${spring-boot-starter-cloud-connectors.version} @@ -57,9 +57,9 @@ - 2.2.6.RELEASE + 2.2.6.RELEASE Hoxton.SR4 42.2.10 - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-dapr/pom.xml b/spring-cloud/spring-cloud-dapr/pom.xml index c2e9edaedc..436666b08e 100644 --- a/spring-cloud/spring-cloud-dapr/pom.xml +++ b/spring-cloud/spring-cloud-dapr/pom.xml @@ -17,4 +17,4 @@ greeting - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-docker/docker-product-server/pom.xml b/spring-cloud/spring-cloud-docker/docker-product-server/pom.xml index be65a6d7d3..cfea512399 100644 --- a/spring-cloud/spring-cloud-docker/docker-product-server/pom.xml +++ b/spring-cloud/spring-cloud-docker/docker-product-server/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 docker-product-server - docker-product-server 1.0.0 + docker-product-server com.baeldung.spring.cloud diff --git a/spring-cloud/spring-cloud-docker/pom.xml b/spring-cloud/spring-cloud-docker/pom.xml index 3e407df6a1..f0f6b84fb0 100644 --- a/spring-cloud/spring-cloud-docker/pom.xml +++ b/spring-cloud/spring-cloud-docker/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-docker - spring-cloud-docker 1.0.0-SNAPSHOT + spring-cloud-docker pom diff --git a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml index 73a0859785..741457529c 100644 --- a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml @@ -12,7 +12,6 @@ com.baeldung.spring.cloud spring-cloud-hystrix 1.0.0-SNAPSHOT - ../ diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-guide/client-service/pom.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-guide/client-service/pom.xml index e916f2bc3e..cedd46dfef 100644 --- a/spring-cloud/spring-cloud-kubernetes/kubernetes-guide/client-service/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-guide/client-service/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 client-service - client-service 1.0-SNAPSHOT + client-service com.baeldung.spring.cloud diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml index 725aa9cd3d..928f401405 100644 --- a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 liveness-example - liveness-example 1.0-SNAPSHOT + liveness-example com.baeldung.spring.cloud diff --git a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml index ba6cee1fce..1c8fa4e694 100644 --- a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml +++ b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml @@ -18,8 +18,8 @@ - + junit junit diff --git a/spring-ejb/pom.xml b/spring-ejb/pom.xml index 0b52fa52b1..003b428ff9 100755 --- a/spring-ejb/pom.xml +++ b/spring-ejb/pom.xml @@ -14,7 +14,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../ @@ -26,8 +25,8 @@ - + junit junit diff --git a/spring-quartz/pom.xml b/spring-quartz/pom.xml index 19ea302a1d..53b6962a60 100644 --- a/spring-quartz/pom.xml +++ b/spring-quartz/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-quartz - spring-quartz 0.0.1-SNAPSHOT + spring-quartz jar Demo project for Scheduling in Spring with Quartz diff --git a/spring-security-modules/spring-5-security-oauth/pom.xml b/spring-security-modules/spring-5-security-oauth/pom.xml index 194ace35b0..aa4958ae47 100644 --- a/spring-security-modules/spring-5-security-oauth/pom.xml +++ b/spring-security-modules/spring-5-security-oauth/pom.xml @@ -68,7 +68,8 @@ - + 2.5.2 com.baeldung.oauth2.SpringOAuthApplication diff --git a/spring-security-modules/spring-security-web-boot-3/pom.xml b/spring-security-modules/spring-security-web-boot-3/pom.xml index 9d09d60611..b26ca094be 100644 --- a/spring-security-modules/spring-security-web-boot-3/pom.xml +++ b/spring-security-modules/spring-security-web-boot-3/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 spring-security-web-boot-3 0.0.1-SNAPSHOT diff --git a/spring-security-modules/spring-security-web-thymeleaf/pom.xml b/spring-security-modules/spring-security-web-thymeleaf/pom.xml index 8e6e0856af..3a240f4129 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/pom.xml +++ b/spring-security-modules/spring-security-web-thymeleaf/pom.xml @@ -29,7 +29,6 @@ org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-starter-test diff --git a/testing-modules/assertion-libraries/pom.xml b/testing-modules/assertion-libraries/pom.xml index 14e0379a3c..57d38746ab 100644 --- a/testing-modules/assertion-libraries/pom.xml +++ b/testing-modules/assertion-libraries/pom.xml @@ -19,7 +19,8 @@ truth ${truth.version} - + junit junit @@ -54,7 +55,8 @@ ${jgotesting.version} test - + junit junit diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index 9f132c7562..ee4dcf8335 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/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 selenium-junit-testng 0.0.1-SNAPSHOT From 67a62f842c9deadbb345878515f098e56c852cb6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 9 Nov 2021 16:38:07 +0530 Subject: [PATCH 02/14] fix build --- maven-modules/maven-printing-plugins/pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maven-modules/maven-printing-plugins/pom.xml b/maven-modules/maven-printing-plugins/pom.xml index aacc829b93..07ddd8d1e8 100644 --- a/maven-modules/maven-printing-plugins/pom.xml +++ b/maven-modules/maven-printing-plugins/pom.xml @@ -76,10 +76,8 @@ log.info('Test message: {}', 'Hello, World!') - log.info('Embed a - line break {}', System.lineSeparator()) - log.info('ArtifactId is: - ${project.artifactId}') + log.info('Embed a line break {}', System.lineSeparator()) + log.info('ArtifactId is: ${project.artifactId}') log.warn('Message only in debug mode') From d7675ddc05ff5ac8d314f4e246eadc6f05e09233 Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Tue, 9 Nov 2021 22:12:33 +0530 Subject: [PATCH 03/14] JAVA-1673: removing junit and surefire configs from maven-modules --- .../maven-copy-files/copy-rename-maven-plugin/pom.xml | 2 +- maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml | 2 +- .../maven-copy-files/maven-resources-plugin/pom.xml | 2 +- maven-modules/maven-copy-files/pom.xml | 2 +- maven-modules/maven-integration-test/pom.xml | 7 +++---- maven-modules/maven-multi-source/pom.xml | 3 +-- maven-modules/maven-plugins/pom.xml | 5 ++--- maven-modules/pom.xml | 4 ---- 8 files changed, 10 insertions(+), 17 deletions(-) diff --git a/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml b/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml index 6feb8284e6..06a44ed4fb 100644 --- a/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml +++ b/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml @@ -54,7 +54,7 @@ maven-surefire-plugin - 2.22.1 + 2.22.2 maven-jar-plugin diff --git a/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml b/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml index 5168e0e965..b005f4b125 100644 --- a/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml +++ b/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml @@ -57,7 +57,7 @@ maven-surefire-plugin - 2.22.1 + 2.22.2 maven-jar-plugin diff --git a/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml b/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml index 6829898b45..a49095f528 100644 --- a/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml +++ b/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml @@ -54,7 +54,7 @@ maven-surefire-plugin - 2.22.1 + 2.22.2 maven-jar-plugin diff --git a/maven-modules/maven-copy-files/pom.xml b/maven-modules/maven-copy-files/pom.xml index 94bf952361..57d0ddf647 100644 --- a/maven-modules/maven-copy-files/pom.xml +++ b/maven-modules/maven-copy-files/pom.xml @@ -51,7 +51,7 @@ maven-surefire-plugin - 2.22.1 + 2.22.2 maven-jar-plugin diff --git a/maven-modules/maven-integration-test/pom.xml b/maven-modules/maven-integration-test/pom.xml index 01be0ad1a4..56c243e3c5 100644 --- a/maven-modules/maven-integration-test/pom.xml +++ b/maven-modules/maven-integration-test/pom.xml @@ -86,8 +86,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} DataTest.java @@ -171,8 +171,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} DataTest.java @@ -217,8 +217,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} integration-test @@ -269,7 +269,6 @@ 3.0.2 3.8.0 - 2.22.0 2.22.0 1.1 3.0.0 diff --git a/maven-modules/maven-multi-source/pom.xml b/maven-modules/maven-multi-source/pom.xml index 65e00419af..d9863b31a9 100644 --- a/maven-modules/maven-multi-source/pom.xml +++ b/maven-modules/maven-multi-source/pom.xml @@ -54,8 +54,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} integration-test @@ -81,7 +81,6 @@ 3.0.2 3.8.0 - 2.22.0 2.22.0 1.1 3.0.0 diff --git a/maven-modules/maven-plugins/pom.xml b/maven-modules/maven-plugins/pom.xml index 29b3b550ea..4aa295c8a8 100644 --- a/maven-modules/maven-plugins/pom.xml +++ b/maven-modules/maven-plugins/pom.xml @@ -84,8 +84,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} DataTest.java @@ -105,8 +105,8 @@ + org.apache.maven.plugins maven-surefire-plugin - ${maven.surefire.version} integration-test @@ -132,7 +132,6 @@ 3.0.2 3.8.0 - 2.22.0 2.22.0 1.1 3.0.0 diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 0aadb873e5..3bd2c8b9ec 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -57,8 +57,4 @@ - - 5.8.1 - - \ No newline at end of file From 5c70fa24436a5270db69c7e8f8719607be6a2226 Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Wed, 10 Nov 2021 09:36:41 +0530 Subject: [PATCH 04/14] JAVA-1673: updating surefire plugin in xml module --- xml/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xml/pom.xml b/xml/pom.xml index f88f0f89b0..d8aa77583b 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -178,8 +178,8 @@ ${maven-compiler-plugin.version} + org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} @@ -242,7 +242,6 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} CustomerTest.java From 605bb8a3c16096e06f4ccc52fd6f1b7ed6859182 Mon Sep 17 00:00:00 2001 From: freelansam <79205526+freelansam@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:39:01 +0530 Subject: [PATCH 05/14] correction to core-java-os --- core-java-modules/core-java-os/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java-modules/core-java-os/pom.xml b/core-java-modules/core-java-os/pom.xml index 8265e47192..c0eac46db8 100644 --- a/core-java-modules/core-java-os/pom.xml +++ b/core-java-modules/core-java-os/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ @@ -90,4 +89,4 @@ 1.8.7 - \ No newline at end of file + From 7d4dd1896396c04946ae48aa84bd7add9d860eda Mon Sep 17 00:00:00 2001 From: ioanadinuit <83220826+ioanadinuit@users.noreply.github.com> Date: Thu, 11 Nov 2021 20:22:13 +0200 Subject: [PATCH 06/14] BAEL-5080 (#11436) * BAEL-5080 Custom validation with Swagger Codegen Add tutorial code * BAEL-5080 Custom validation with Swagger Codegen Formatting * BAEL-5080 Custom validation with Swagger Codegen Swagger doc update * remove Licence file --- .../README.md | 1 + .../pom.xml | 103 ++++++++++++ .../openapi/petstore/PetstoreApplication.java | 13 ++ .../petstore/controller/PetController.java | 17 ++ .../controller/PetControllerAdvice.java | 20 +++ .../petstore/validation/Camelcase.java | 22 +++ .../validation/CamelcaseValidator.java | 35 ++++ .../src/main/resources/application.properties | 1 + .../resources/openapi/templates/api.mustache | 150 ++++++++++++++++++ .../templates/beanValidationCore.mustache | 26 +++ .../openapi/templates/cookieParams.mustache | 1 + .../resources/openapi/templates/enum.mustache | 31 ++++ .../openapi/templates/model.mustache | 42 +++++ .../openapi/templates/modelEnum.mustache | 68 ++++++++ .../src/main/resources/petstore.yml | 65 ++++++++ 15 files changed, 595 insertions(+) create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/README.md create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/PetstoreApplication.java create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetController.java create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetControllerAdvice.java create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/Camelcase.java create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/CamelcaseValidator.java create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/application.properties create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/api.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/beanValidationCore.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/cookieParams.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/enum.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/model.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/modelEnum.mustache create mode 100644 spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/petstore.yml diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/README.md b/spring-swagger-codegen/custom-validations-opeanpi-codegen/README.md new file mode 100644 index 0000000000..83eec25c03 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/README.md @@ -0,0 +1 @@ +# This is a sample on how we can merge the OpenApi code generation with the a custom annotation using ConstraintValidator diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml new file mode 100644 index 0000000000..53e5006bf4 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.4 + + + com.example + petstore + 0.0.1-SNAPSHOT + petstore + Demo project for Swagger Custom Validations Codegen + + 11 + 3.0.0 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.hibernate + hibernate-validator + 6.0.10.Final + + + javax.validation + validation-api + 2.0.1.Final + + + org.openapitools + openapi-generator + 3.3.4 + + + io.springfox + springfox-oas + ${springfox-version} + + + io.springfox + springfox-swagger-ui + ${springfox-version} + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0.pr3 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.openapitools + openapi-generator-maven-plugin + 5.1.0 + + + + generate + + + + ${project.basedir}/src/main/resources/petstore.yml + + spring + com.baeldung.openapi.api + com.baeldung.openapi.model + + ApiUtil.java + + + false + java8-localdatetime + + + src/main/resources/openapi/templates + + + + + + + + + + diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/PetstoreApplication.java b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/PetstoreApplication.java new file mode 100644 index 0000000000..5a6372ba22 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/PetstoreApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.openapi.petstore; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PetstoreApplication { + + public static void main(String[] args) { + SpringApplication.run(PetstoreApplication.class, args); + } + +} diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetController.java b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetController.java new file mode 100644 index 0000000000..081d0cb6f9 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetController.java @@ -0,0 +1,17 @@ +package com.baeldung.openapi.petstore.controller; + +import com.baeldung.openapi.api.PetsApi; +import com.baeldung.openapi.model.Pet; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; + +import java.util.Arrays; +import java.util.List; + +@Controller +public class PetController implements PetsApi { + + public ResponseEntity> findPetsByName(String name) { + return ResponseEntity.ok(Arrays.asList(new Pet().id(1L).name(name))); + } +} diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetControllerAdvice.java b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetControllerAdvice.java new file mode 100644 index 0000000000..cf243dbb46 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/controller/PetControllerAdvice.java @@ -0,0 +1,20 @@ +package com.baeldung.openapi.petstore.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.validation.ConstraintViolationException; + +@ControllerAdvice +public class PetControllerAdvice { + + @ResponseBody + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(ConstraintViolationException.class) + public void handleConstraintViolationException() { + + } +} diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/Camelcase.java b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/Camelcase.java new file mode 100644 index 0000000000..b0b0b739e2 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/Camelcase.java @@ -0,0 +1,22 @@ +package com.baeldung.openapi.petstore.validation; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = {CamelcaseValidator.class}) +@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Camelcase { + + String message() default "Name should be uppercase."; + + boolean required() default true; + + Class[] groups() default {}; + + Class[] payload() default {}; + + String[] values() default {}; +} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/CamelcaseValidator.java b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/CamelcaseValidator.java new file mode 100644 index 0000000000..2b08e3dd2a --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/java/com/baeldung/openapi/petstore/validation/CamelcaseValidator.java @@ -0,0 +1,35 @@ +package com.baeldung.openapi.petstore.validation; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.Objects; + +public class CamelcaseValidator implements ConstraintValidator { + + private Camelcase uppercaseAnnotation; + + public void initialize(Camelcase constraintAnnotation) { + this.uppercaseAnnotation = constraintAnnotation; + } + + @Override + public boolean isValid(String nameField, ConstraintValidatorContext context) { + String correctName = buildCorrectName(nameField); + if (uppercaseAnnotation.required() + && (Objects.isNull(nameField) || nameField.isBlank() + || !correctName.equals(nameField))) { + context = context + .buildConstraintViolationWithTemplate(this.uppercaseAnnotation.message()) + .addConstraintViolation(); + context.disableDefaultConstraintViolation(); + return false; + } + return true; + } + + private String buildCorrectName(String nameField) { + String upCase = String.valueOf(nameField.charAt(0)).toUpperCase(); + String lowCase = nameField.substring(1).toLowerCase(); + return upCase.concat(lowCase); + } +} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/application.properties b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/application.properties new file mode 100644 index 0000000000..d5e4d42eb8 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/application.properties @@ -0,0 +1 @@ +openapi.petStore.base-path=/ diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/api.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/api.mustache new file mode 100644 index 0000000000..a7a35d43b5 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/api.mustache @@ -0,0 +1,150 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://com.baeldung.openapi-generator.tech) ({{{generatorVersion}}}). + * https://com.baeldung.openapi-generator.tech + * Do not edit the class manually. + */ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +import io.swagger.annotations.*; +import com.baeldung.openapi.petstore.validation.Camelcase; +{{#jdk8-no-delegate}} +{{#virtualService}} +import io.virtualan.annotation.ApiVirtual; +import io.virtualan.annotation.VirtualService; +{{/virtualService}} +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +{{/jdk8-no-delegate}} +import org.springframework.http.ResponseEntity; +{{#useBeanValidation}} +import org.springframework.validation.annotation.Validated; +{{/useBeanValidation}} +{{#vendorExtensions.x-spring-paginated}} +import org.springframework.data.domain.Pageable; +{{/vendorExtensions.x-spring-paginated}} +import org.springframework.web.bind.annotation.*; +{{#jdk8-no-delegate}} + {{^reactive}} +import org.springframework.web.context.request.NativeWebRequest; + {{/reactive}} +{{/jdk8-no-delegate}} +import org.springframework.web.multipart.MultipartFile; +{{#reactive}} +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import org.springframework.http.codec.multipart.Part; +{{/reactive}} +import springfox.documentation.annotations.ApiIgnore; + +{{#useBeanValidation}} +import javax.validation.Valid; +import javax.validation.constraints.*; +{{/useBeanValidation}} +import java.util.List; +import java.util.Map; +{{#jdk8-no-delegate}} +import java.util.Optional; +{{/jdk8-no-delegate}} +{{^jdk8-no-delegate}} + {{#useOptional}} +import java.util.Optional; + {{/useOptional}} +{{/jdk8-no-delegate}} +{{#async}} +import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}}; +{{/async}} +{{>generatedAnnotation}} +{{#useBeanValidation}} +@Validated +{{/useBeanValidation}} +@Api(value = "{{{baseName}}}", tags = "All") +{{#operations}} +{{#virtualService}} +@VirtualService +{{/virtualService}} +public interface {{classname}} { +{{#jdk8-default-interface}} + {{^isDelegate}} + {{^reactive}} + + default Optional getRequest() { + return Optional.empty(); + } + {{/reactive}} + {{/isDelegate}} + {{#isDelegate}} + + default {{classname}}Delegate getDelegate() { + return new {{classname}}Delegate() {}; + } + {{/isDelegate}} +{{/jdk8-default-interface}} +{{#operation}} + + /** + * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}} + {{#notes}} + * {{.}} + {{/notes}} + * + {{#allParams}} + * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} + {{/allParams}} + * @return {{#responses}}{{message}} (status code {{code}}){{^-last}} + * or {{/-last}}{{/responses}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + */ + {{#virtualService}} + @ApiVirtual + {{/virtualService}} + @ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}{{#isOAuth}}@Authorization(value = "{{name}}", scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, + {{/-last}}{{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}} + {{^isOAuth}}@Authorization(value = "{{name}}"){{^-last}},{{/-last}} + {{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} }) + {{#implicitHeaders}} + @ApiImplicitParams({ + {{#headerParams}} + {{>implicitHeader}} + {{/headerParams}} + }) + {{/implicitHeaders}} + @RequestMapping( + method = RequestMethod.{{httpMethod}}, + value = "{{{path}}}"{{#singleContentTypes}}{{#hasProduces}}, + produces = "{{{vendorExtensions.x-accepts}}}"{{/hasProduces}}{{#hasConsumes}}, + consumes = "{{{vendorExtensions.x-contentType}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, + produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}}, + consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}} + ) + {{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},{{/-last}}{{#-last}}{{#reactive}}, {{/reactive}}{{/-last}}{{/allParams}}{{#reactive}}@ApiIgnore final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, @ApiIgnore final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}}{{#unhandledException}} throws Exception{{/unhandledException}} { + {{#delegate-method}} + return {{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); + } + + // Override this method + {{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}@ApiIgnore final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, @ApiIgnore final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} { + {{/delegate-method}} + {{^isDelegate}} + {{>methodBody}} + {{/isDelegate}} + {{#isDelegate}} + return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); + {{/isDelegate}} + }{{/jdk8-default-interface}} + +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/beanValidationCore.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/beanValidationCore.mustache new file mode 100644 index 0000000000..e3c19c6474 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/beanValidationCore.mustache @@ -0,0 +1,26 @@ +{{{ vendorExtensions.x-constraints }}} +{{#errorMessage}}@Mandatory(errorMessage="{{{pattern}}}") {{/errorMessage}} +{{#pattern}}@Pattern(regexp="{{{pattern}}}") {{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}}@Size(min={{minLength}},max={{maxLength}}) {{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}}@Size(min={{minLength}}) {{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}}@Size(max={{maxLength}}) {{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}}@Size(min={{minItems}},max={{maxItems}}) {{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}}@Size(min={{minItems}}) {{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}}@Size(max={{maxItems}}) {{/maxItems}}{{/minItems}}{{! +@Email: useBeanValidation set && isEmail && java8 set +}}{{#useBeanValidation}}{{#isEmail}}{{#java8}}@javax.validation.constraints.Email{{/java8}}{{/isEmail}}{{/useBeanValidation}}{{! +@Email: performBeanValidation set && isEmail && not java8 set +}}{{#performBeanValidation}}{{#isEmail}}{{^java8}}@org.hibernate.validator.constraints.Email{{/java8}}{{/isEmail}}{{/performBeanValidation}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#isInteger}}{{#minimum}}@Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}) {{/maximum}}{{/isInteger}}{{! +isLong set +}}{{#isLong}}{{#minimum}}@Min({{minimum}}L){{/minimum}}{{#maximum}} @Max({{maximum}}L) {{/maximum}}{{/isLong}}{{! +Not Integer, not Long => we have a decimal value! +}}{{^isInteger}}{{^isLong}}{{#minimum}}@DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{/minimum}}{{#maximum}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}) {{/maximum}}{{/isLong}}{{/isInteger}} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/cookieParams.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/cookieParams.mustache new file mode 100644 index 0000000000..e21bd9ff4b --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/cookieParams.mustache @@ -0,0 +1 @@ +{{#isCookieParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues = "{{#enumVars}}{{#lambdaEscapeDoubleQuote}}{{{value}}}{{/lambdaEscapeDoubleQuote}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/enumVars}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}{{/isContainer}}) @CookieValue("{{baseName}}") {{>optionalDataType}} {{paramName}}{{/isCookieParam}} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/enum.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/enum.mustache new file mode 100644 index 0000000000..3cdae7f3cc --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/enum.mustache @@ -0,0 +1,31 @@ +class {{classname}} { + /// The underlying value of this enum member. + {{dataType}} value; + + {{classname}}._internal(this.value); + {{ vendorExtensions.x-enum-varnames }} + {{ vendorExtensions.x-enum-descriptions }} + {{#allowableValues}} + {{#enumVars}} + {{#description}} + /// {{description}} + {{/description}} + static {{classname}} {{name}} = {{classname}}._internal({{{value}}}); + {{/enumVars}} + {{/allowableValues}} + + {{classname}}.fromJson(dynamic data) { + switch (data) { + {{#allowableValues}} + {{#enumVars}} + case {{{value}}}: value = data; break; + {{/enumVars}} + {{/allowableValues}} + default: throw('Unknown enum value to decode: $data'); + } + } + + static dynamic encode({{classname}} data) { + return data.value; + } +} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/model.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/model.mustache new file mode 100644 index 0000000000..d9329b40d3 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/model.mustache @@ -0,0 +1,42 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} +import com.fasterxml.jackson.databind.annotation.*; +import com.fasterxml.jackson.annotation.*; +import com.baeldung.openapi.petstore.validation.Camelcase; +{{^supportJava6}} +import java.util.Objects; +import java.util.Arrays; +{{/supportJava6}} +{{#supportJava6}} +import org.apache.commons.lang3.ObjectUtils; +{{/supportJava6}} +{{#imports}} +import {{import}}; +{{/imports}} +{{#serializableModel}} +import java.io.Serializable; +{{/serializableModel}} +{{#jackson}} +{{#withXml}} +import com.fasterxml.jackson.dataformat.xml.annotation.*; +{{/withXml}} +{{/jackson}} +{{#withXml}} +import javax.xml.bind.annotation.*; +{{/withXml}} +{{#parcelableModel}} +import android.os.Parcelable; +import android.os.Parcel; +{{/parcelableModel}} +{{#useBeanValidation}} +import javax.validation.constraints.*; +import javax.validation.Valid; +{{/useBeanValidation}} + +{{#models}} +{{#model}} +{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/modelEnum.mustache b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/modelEnum.mustache new file mode 100644 index 0000000000..29f27bd851 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/openapi/templates/modelEnum.mustache @@ -0,0 +1,68 @@ +{{#jackson}} +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +{{/jackson}} +{{#gson}} +import java.io.IOException; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +{{/gson}} + +/** + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} + */ +{{#gson}} +@JsonAdapter({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Adapter.class) +{{/gson}} +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { + {{#allowableValues}}{{#enumVars}} + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} + + private {{{dataType}}} value; + + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) { + this.value = value; + } + +{{#jackson}} + @JsonValue +{{/jackson}} + public {{{dataType}}} getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + +{{#jackson}} + @JsonCreator +{{/jackson}} + public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue{{#jackson}}({{{dataType}}} value){{/jackson}}{{^jackson}}(String text){{/jackson}} { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if ({{#jackson}}b.value.equals(value){{/jackson}}{{^jackson}}String.valueOf(b.value).equals(text){{/jackson}}) { + return b; + } + } + throw new UlpValidationException(UlpBundleKey.{{vendorExtensions.x-enum-invalidtag}}); + } +{{#gson}} + + public static class Adapter extends TypeAdapter<{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> { + @Override + public void write(final JsonWriter jsonWriter, final {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} enumeration) throws IOException { + jsonWriter.value(enumeration.getValue()); + } + + @Override + public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException { + {{#isNumber}}BigDecimal value = new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}{{#isInteger}}Integer value {{/isInteger}}{{^isInteger}}String value {{/isInteger}}= jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}nextString(){{/isInteger}}{{/isNumber}}; + return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue({{#jackson}}value{{/jackson}}{{^jackson}}String.valueOf(value){{/jackson}}); + } + } +{{/gson}} +} \ No newline at end of file diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/petstore.yml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/petstore.yml new file mode 100644 index 0000000000..c9884c01e8 --- /dev/null +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/src/main/resources/petstore.yml @@ -0,0 +1,65 @@ +openapi: 3.0.1 +info: + version: "1.0" + title: PetStore +paths: + /pets: + post: + tags: + - pet + summary: Add a new pet to the store + description: Add a new pet to the store + operationId: addPet + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + responses: + '201': + description: default response, returning the new pet id + content: + application/json: + schema: + type: integer + '400': + description: Invalid input + get: + tags: + - pet + summary: Finds Pets by name + description: 'Find pets by name' + operationId: findPetsByName + parameters: + - name: name + in: query + schema: + type: string + description: Tags to filter by + x-constraints: "@Camelcase(required = true)" + responses: + '200': + description: default response + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid name value +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + x-constraints: "@Camelcase(required = true)" \ No newline at end of file From 41c8af76d2c9474104bb634b550cc329690a7549 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Thu, 11 Nov 2021 23:19:32 +0100 Subject: [PATCH 07/14] BAEL-5194 rm html tags (#11404) --- xml/pom.xml | 19 ++++++ .../delhtmltags/RemoveHtmlTagsLiveTest.java | 61 +++++++++++++++++++ .../xmlhtml/delhtmltags/example1.html | 15 +++++ .../xmlhtml/delhtmltags/example2.html | 22 +++++++ 4 files changed, 117 insertions(+) create mode 100644 xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java create mode 100644 xml/src/test/resources/xmlhtml/delhtmltags/example1.html create mode 100644 xml/src/test/resources/xmlhtml/delhtmltags/example2.html diff --git a/xml/pom.xml b/xml/pom.xml index d8aa77583b..d05f2401e3 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -14,6 +14,22 @@ + + org.jsoup + jsoup + ${jsoup.version} + + + net.sourceforge.htmlcleaner + htmlcleaner + ${htmlcleaner.version} + + + net.htmlparser.jericho + jericho-html + ${jericho.version} + + org.dom4j @@ -361,6 +377,9 @@ 1.3.1 3.8.0 + 1.14.3 + 2.25 + 3.4 \ No newline at end of file diff --git a/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java b/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java new file mode 100644 index 0000000000..b05123cbdc --- /dev/null +++ b/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java @@ -0,0 +1,61 @@ +package com.baeldung.xmlhtml.delhtmltags; + +import net.htmlparser.jericho.Renderer; +import net.htmlparser.jericho.Segment; +import net.htmlparser.jericho.Source; +import org.htmlcleaner.CleanerProperties; +import org.htmlcleaner.HtmlCleaner; +import org.jsoup.Jsoup; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; + +class RemoveHtmlTagsLiveTest { + + @Test + void givenHtml1_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException { + String html = new String(Files.readAllBytes( + (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example1.html").toURI())))); + String result = html.replaceAll("<[^>]*>", "") + .replaceAll("(?m)^\\s*$", ""); // remove empty and blank lines + System.out.println(result); + } + + @Test + void givenHtml2_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException { + String html = new String(Files.readAllBytes( + (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI())))); + String result = html.replaceAll("<[^>]*>", ""); + System.out.println(result); + } + + @Test + void givenHtml2_whenRemoveTagsByJsoup_thenPrintText() throws IOException, URISyntaxException { + String html = new String(Files.readAllBytes( + (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI())))); + System.out.println(Jsoup.parse(html).text()); + } + + @Test + void givenHtml2_whenRemoveTagsByHtmlCleaner_thenPrintText() throws IOException, URISyntaxException { + String html = new String(Files.readAllBytes( + (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI())))); + CleanerProperties props = new CleanerProperties(); + props.setPruneTags("script"); + String result = new HtmlCleaner(props).clean(html).getText().toString(); + System.out.println(result); + } + + @Test + void givenHtml2_whenRemoveTagsByJericho_thenPrintText() throws IOException, URISyntaxException { + String html = new String(Files.readAllBytes( + (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI())))); + Source htmlSource = new Source(html); + Segment segment = new Segment(htmlSource, 0, htmlSource.length()); + Renderer htmlRender = new Renderer(segment).setIncludeHyperlinkURLs(true); + System.out.println(htmlRender); + } +} diff --git a/xml/src/test/resources/xmlhtml/delhtmltags/example1.html b/xml/src/test/resources/xmlhtml/delhtmltags/example1.html new file mode 100644 index 0000000000..43f3a22ef4 --- /dev/null +++ b/xml/src/test/resources/xmlhtml/delhtmltags/example1.html @@ -0,0 +1,15 @@ + + + + This is the page title + + +

+ If the application X doesn't start, the possible causes could be:
+ 1. Maven is not installed.
+ 2. Not enough disk space.
+ 3. Not enough memory. +

+ + \ No newline at end of file diff --git a/xml/src/test/resources/xmlhtml/delhtmltags/example2.html b/xml/src/test/resources/xmlhtml/delhtmltags/example2.html new file mode 100644 index 0000000000..532eadc101 --- /dev/null +++ b/xml/src/test/resources/xmlhtml/delhtmltags/example2.html @@ -0,0 +1,22 @@ + + + + This is the page title + + + +

+ If the application X doesn't start, the possible causes could be:
+ 1. + Maven + is not installed.
+ 2. Not enough (<1G) disk space.
+ 3. Not enough (<64MB) memory.
+

+ + \ No newline at end of file From 28562bcd749da7ce8beb19beccabb5af44a06902 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 12 Nov 2021 20:20:11 +0530 Subject: [PATCH 08/14] JAVA-8395: Delete module simplehexagonalexample --- patterns/simplehexagonalexample/pom.xml | 32 ----- .../simplehexagonalex/DailyQuoteMain.java | 32 ----- .../controller/QuoteCliController.java | 24 ---- .../controller/QuoteRestController.java | 24 ---- .../domain/QuoteOfTheDay.java | 56 --------- .../repository/QuoteOfTheDayFromProvider.java | 8 -- .../domain/service/QuoteAggregator.java | 22 ---- .../domain/service/QuoteService.java | 8 -- .../primary/quoteadapter/ProviderQuote.java | 109 ------------------ .../quoteadapter/ProviderQuoteAdapter.java | 54 --------- .../quoteadapter/ProviderQuoteEnvelope.java | 68 ----------- .../mock/quoteadapter/MockQuoteAdapter.java | 20 ---- .../src/main/resources/application.properties | 1 - .../MockAccessProviderUnitTest.java | 22 ---- .../PrimaryAccessProviderIntegrationTest.java | 28 ----- .../QuoteRequestIntegrationTest.java | 36 ------ .../src/test/resources/application.properties | 1 - 17 files changed, 545 deletions(-) delete mode 100644 patterns/simplehexagonalexample/pom.xml delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java delete mode 100644 patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java delete mode 100644 patterns/simplehexagonalexample/src/main/resources/application.properties delete mode 100644 patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java delete mode 100644 patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java delete mode 100644 patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java delete mode 100644 patterns/simplehexagonalexample/src/test/resources/application.properties diff --git a/patterns/simplehexagonalexample/pom.xml b/patterns/simplehexagonalexample/pom.xml deleted file mode 100644 index 31e829b7dc..0000000000 --- a/patterns/simplehexagonalexample/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - 4.0.0 - 1.0.0-SNAPSHOT - simple-hexagonal-example - simple-hexagonal-example - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java deleted file mode 100644 index de8b2f4793..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.simplehexagonalex; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -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.simplehexagonalex.controller.QuoteCliController; -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -@SpringBootApplication -public class DailyQuoteMain implements CommandLineRunner { - - private static final Logger LOG = LoggerFactory.getLogger(DailyQuoteMain.class); - @Autowired - private QuoteCliController quoteCliController; - - public static void main(final String[] args) { - - SpringApplication.run(DailyQuoteMain.class, args); - } - - @Override - public void run(String... args) throws Exception { - - QuoteOfTheDay quoteOfTheDay = quoteCliController.getQuote("cliController"); - - LOG.info(quoteOfTheDay.toString()); - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java deleted file mode 100644 index 9ecb2bf822..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.simplehexagonalex.controller; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.service.QuoteService; - -@Component -public class QuoteCliController { - - private static final Logger LOG = LoggerFactory.getLogger(QuoteCliController.class); - - @Autowired - private QuoteService quoteService; - - public QuoteOfTheDay getQuote(String userId) { - - LOG.info("Getting quote"); - return quoteService.getQuote(userId); - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java deleted file mode 100644 index 061cff8cec..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.simplehexagonalex.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.service.QuoteService; - -@RestController -@RequestMapping("/quote") -public class QuoteRestController { - - @Autowired - private QuoteService quoteService; - - @GetMapping(path = "/{userId}") - public QuoteOfTheDay getEmployee(@PathVariable("userId") String userId) { - return quoteService.getQuote(userId); - } - -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java deleted file mode 100644 index c74c224c70..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.simplehexagonalex.domain; - -import java.util.Objects; - -public class QuoteOfTheDay { - - private String userName; - private String quote; - private String provider; - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getQuote() { - return quote; - } - - public void setQuote(String quote) { - this.quote = quote; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - @Override - public int hashCode() { - return Objects.hash(provider, quote, userName); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - QuoteOfTheDay other = (QuoteOfTheDay) obj; - return Objects.equals(provider, other.provider) && Objects.equals(quote, other.quote) && Objects.equals(userName, other.userName); - } - - @Override - public String toString() { - return "QuoteOfTheDay [userName=" + userName + ", quote=" + quote + ", provider=" + provider + "]"; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java deleted file mode 100644 index 7e70cebd12..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.repository; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -public interface QuoteOfTheDayFromProvider { - - QuoteOfTheDay getQuote(); -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java deleted file mode 100644 index 16f7015ace..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.service; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@Service -public class QuoteAggregator implements QuoteService { - - @Autowired - private QuoteOfTheDayFromProvider quoteOfTheDayFromProvider; - - @Override - public QuoteOfTheDay getQuote(String userName) { - - QuoteOfTheDay quoteOfTheDay = quoteOfTheDayFromProvider.getQuote(); - quoteOfTheDay.setUserName(userName); - return quoteOfTheDay; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java deleted file mode 100644 index 300387a41d..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -public interface QuoteService { - - QuoteOfTheDay getQuote(String userName); -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java deleted file mode 100644 index 0cbbc60726..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.util.List; -import java.util.Objects; - -public class ProviderQuote { - - private String quote; - private String length; - private String author; - private List tags; - private String category; - private String language; - private String date; - private String permalink; - private String id; - private String background; - private String title; - - public ProviderQuote() { - - } - - public ProviderQuote(String quote, String length, String author, List tags, String category, String language, String date, String permalink, String id, String background, String title) { - super(); - this.quote = quote; - this.length = length; - this.author = author; - this.tags = tags; - this.category = category; - this.language = language; - this.date = date; - this.permalink = permalink; - this.id = id; - this.background = background; - this.title = title; - } - - public String getQuote() { - return quote; - } - - public String getLength() { - return length; - } - - public String getAuthor() { - return author; - } - - public List getTags() { - return tags; - } - - public String getCategory() { - return category; - } - - public String getLanguage() { - return language; - } - - public String getDate() { - return date; - } - - public String getPermalink() { - return permalink; - } - - public String getId() { - return id; - } - - public String getBackground() { - return background; - } - - public String getTitle() { - return title; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ProviderQuote other = (ProviderQuote) obj; - return Objects.equals(id, other.id); - } - - @Override - public String toString() { - return "TheysaysoQuote [quote=" + quote + ", length=" + length + ", " + "author=" + author + ", tags=" + tags + ", category=" + category + ", language=" + language + ", date=" + date + ", permalink=" + permalink + ", id=" + id + ", background=" - + background + ", title=" + title + "]"; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java deleted file mode 100644 index ded08f7b18..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.net.URI; - -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Service("providerQuoteAdapter") -@Primary -public class ProviderQuoteAdapter implements QuoteOfTheDayFromProvider { - - @Autowired - private Environment env; - - @Override - public QuoteOfTheDay getQuote() { - - QuoteOfTheDay quoteOfTheDay = new QuoteOfTheDay(); - ProviderQuoteEnvelope providerQuote; - try { - providerQuote = getProviderQuote(); - quoteOfTheDay.setQuote(providerQuote.getContents() - .getQuotes() - .get(0) - .getQuote()); - quoteOfTheDay.setProvider(providerQuote.getCopyright() - .getUrl()); - } catch (Exception e) { - quoteOfTheDay.setQuote("Unable to get the quote"); - quoteOfTheDay.setProvider("none"); - } - return quoteOfTheDay; - } - - private ProviderQuoteEnvelope getProviderQuote() throws Exception { - - HttpGet request = new HttpGet(URI.create(env.getProperty("theysayso.quote.provider.url"))); - CloseableHttpClient client = HttpClients.createDefault(); - CloseableHttpResponse response = client.execute(request); - ProviderQuoteEnvelope providersQuote = new ObjectMapper().readValue(response.getEntity() - .getContent(), ProviderQuoteEnvelope.class); - return providersQuote; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java deleted file mode 100644 index 611549f23d..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.util.List; - -public class ProviderQuoteEnvelope { - - private Success success; - private Contents contents; - private String baseurl; - private Copyright copyright; - - public ProviderQuoteEnvelope() { - - } - - public ProviderQuoteEnvelope(Success success, Contents contents, String baseurl, Copyright copyright) { - super(); - this.success = success; - this.contents = contents; - this.baseurl = baseurl; - this.copyright = copyright; - } - - public Success getSuccess() { - return success; - } - - public Contents getContents() { - return contents; - } - - public String getBaseurl() { - return baseurl; - } - - public Copyright getCopyright() { - return copyright; - } - - public class Contents { - private List quotes; - - public List getQuotes() { - return quotes; - } - } - - public class Copyright { - private int year; - private String url; - - public int getYear() { - return year; - } - - public String getUrl() { - return url; - } - } - - public class Success { - private int total; - - public int getTotal() { - return total; - } - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java deleted file mode 100644 index 54c28fc94e..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.simplehexagonalex.reposity.mock.quoteadapter; - -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@Service -public class MockQuoteAdapter implements QuoteOfTheDayFromProvider { - - @Override - public QuoteOfTheDay getQuote() { - - QuoteOfTheDay quoteOfTheDay = new QuoteOfTheDay(); - quoteOfTheDay.setQuote("Mock quote of the day"); - quoteOfTheDay.setProvider("Mock Provider"); - - return quoteOfTheDay; - } -} diff --git a/patterns/simplehexagonalexample/src/main/resources/application.properties b/patterns/simplehexagonalexample/src/main/resources/application.properties deleted file mode 100644 index dd9413bfd5..0000000000 --- a/patterns/simplehexagonalexample/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -theysayso.quote.provider.url=https://quotes.rest/qod?language=en \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java deleted file mode 100644 index 602f7ea5d4..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.reposity.mock.quoteadapter.MockQuoteAdapter; - -public class MockAccessProviderUnitTest { - - @Test - public void givenProvider_whenConnect_thenResponse() throws Exception { - - MockQuoteAdapter provider = new MockQuoteAdapter(); - QuoteOfTheDay quote = provider.getQuote(); - assertNotNull(quote); - assertEquals("Mock quote of the day", quote.getQuote()); - assertEquals("Mock Provider", quote.getProvider()); - } -} diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java deleted file mode 100644 index 47e1dde136..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@SpringBootTest -public class PrimaryAccessProviderIntegrationTest { - - @Autowired - @Qualifier("providerQuoteAdapter") - QuoteOfTheDayFromProvider provider; - - @Test - public void whenQuoteProvider_thenResponse() throws Exception { - - QuoteOfTheDay quote = provider.getQuote(); - assertNotNull(quote); - assertThat(quote.getProvider()).contains("theysaidso"); - } -} diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java deleted file mode 100644 index 552b5d51c2..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -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.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; - -@SpringBootTest -@AutoConfigureMockMvc -public class QuoteRequestIntegrationTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void whenRestQuoteRequest_thenResponse() throws Exception { - - MvcResult result = this.mockMvc.perform(get("/quote/tester")) - .andDo(print()) - .andExpect(status().isOk()) - .andReturn(); - - String content = result.getResponse() - .getContentAsString(); - - assertThat(content).contains("tester"); - assertThat(content).contains("theysaidso"); - } -} \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/test/resources/application.properties b/patterns/simplehexagonalexample/src/test/resources/application.properties deleted file mode 100644 index dd9413bfd5..0000000000 --- a/patterns/simplehexagonalexample/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -theysayso.quote.provider.url=https://quotes.rest/qod?language=en \ No newline at end of file From b13dae54452b69b97e42aa4998ce8c1c7f2ad0af Mon Sep 17 00:00:00 2001 From: nishitgoyal17 Date: Sat, 13 Nov 2021 22:07:03 +0530 Subject: [PATCH 09/14] BAEL-4243:Once per request filter (#11239) * executing junit via command line * incorporating review comments * incorporating review comments * OncePerReqFilter * Delete FirstUnitTest.java * Delete SecondUnitTest.java * Delete pom.xml * Reverting * Update pom.xml * OncePerReqFilter * Update MyFilter.java * OncePerReqFilter * OncePerReqFilter * Update pom.xml * Update pom.xml * Update pom.xml * fixing extra changes * OncePerReqFilter * Reverting * Update MyOncePerRequestFilter.java * Update HelloController.java * fromatting changes * fromatting changes * formatting * Apply suggestions from code review Co-authored-by: KevinGilmore * OncePerRequest changes * OncePerRequest changes * OncePerRequest changes * OncePerRequest changes * OncePerRequest changes Co-authored-by: KevinGilmore --- .../AuthenticationFilter.java | 34 ++++++++++++++++ .../onceperrequestfilter/HelloController.java | 40 +++++++++++++++++++ .../MyOncePerRequestFilter.java | 29 ++++++++++++++ .../OncePerRequestFilterApp.java | 12 ++++++ 4 files changed, 115 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/AuthenticationFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/HelloController.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/MyOncePerRequestFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/OncePerRequestFilterApp.java diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/AuthenticationFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/AuthenticationFilter.java new file mode 100644 index 0000000000..7ddcde7dc8 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/AuthenticationFilter.java @@ -0,0 +1,34 @@ +package com.baeldung.onceperrequestfilter; + +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class AuthenticationFilter extends OncePerRequestFilter { + + @Override + protected void doFilterInternal( + HttpServletRequest request, + HttpServletResponse response, + FilterChain filterChain) throws + ServletException, IOException { + String usrName = request.getHeader("userName"); + logger.info("Successfully authenticated user " + + usrName); + filterChain.doFilter(request, response); + } + @Override + protected boolean shouldNotFilterAsyncDispatch() { + return false; + } + @Override + protected boolean shouldNotFilterErrorDispatch() { + return false; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/HelloController.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/HelloController.java new file mode 100644 index 0000000000..0a354c91ac --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/HelloController.java @@ -0,0 +1,40 @@ +package com.baeldung.onceperrequestfilter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.context.request.async.DeferredResult; + +import javax.servlet.http.HttpServletResponse; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +@Controller +public class HelloController implements AutoCloseable { + + private final ExecutorService executorService = Executors.newCachedThreadPool(); + + private Logger logger = LoggerFactory.getLogger(HelloController.class); + + @GetMapping(path = "/greeting") + public DeferredResult hello(HttpServletResponse response) throws Exception { + DeferredResult deferredResult = new DeferredResult<>(); + executorService.submit(() -> perform(deferredResult)); + return deferredResult; + } + + private void perform(DeferredResult dr) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + dr.setResult("OK"); + } + + @Override + public void close() throws Exception { + executorService.shutdownNow(); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/MyOncePerRequestFilter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/MyOncePerRequestFilter.java new file mode 100644 index 0000000000..3fd304f86b --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/MyOncePerRequestFilter.java @@ -0,0 +1,29 @@ +package com.baeldung.onceperrequestfilter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class MyOncePerRequestFilter extends OncePerRequestFilter { + private Logger logger = LoggerFactory.getLogger(MyOncePerRequestFilter.class); + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + logger.info("Inside Once Per Request Filter originated by request {}", request.getRequestURI()); + filterChain.doFilter(request, response); + } + + @Override + protected boolean shouldNotFilterAsyncDispatch() { + return true; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/OncePerRequestFilterApp.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/OncePerRequestFilterApp.java new file mode 100644 index 0000000000..ed7be518a3 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/onceperrequestfilter/OncePerRequestFilterApp.java @@ -0,0 +1,12 @@ +package com.baeldung.onceperrequestfilter; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication(scanBasePackages = "com.baeldung.onceperrequestfilter") +public class OncePerRequestFilterApp { + public static void main(String[] args) { + SpringApplication.run(OncePerRequestFilterApp.class, args); + } +} \ No newline at end of file From 5f9698161de3b9ae90396e8e6f460592f70ed891 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 14 Nov 2021 11:05:34 +0530 Subject: [PATCH 10/14] JAVA-8282: Moved 5 articles from core-java-security-2 module to new module core-java-security-algorithms --- .../core-java-security-2/README.md | 5 - .../main/java/com/baeldung/aes/AESUtil.java | 156 ------------------ .../main/java/com/baeldung/aes/Student.java | 40 ----- .../com/baeldung/aes/AESUtilUnitTest.java | 101 ------------ .../cipher/AvailableCiphersUnitTest.java | 35 ---- .../com/baeldung/des/TripleDESUnitTest.java | 90 ---------- .../java/com/baeldung/rsa/RsaUnitTest.java | 92 ----------- .../core-java-security-algorithms/README.md | 11 ++ .../src/test/resources/baeldung.txt | 0 9 files changed, 11 insertions(+), 519 deletions(-) delete mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java delete mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java delete mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java delete mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java delete mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/des/TripleDESUnitTest.java delete mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java create mode 100644 core-java-modules/core-java-security-algorithms/README.md rename core-java-modules/{core-java-security-2 => core-java-security-algorithms}/src/test/resources/baeldung.txt (100%) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index 680a7de925..31404d24a5 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -10,12 +10,7 @@ This module contains articles about core Java Security - [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) - [Checksums in Java](https://www.baeldung.com/java-checksums) - [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) -- [Java AES Encryption and Decryption](https://www.baeldung.com/java-aes-encryption-decryption) -- [InvalidAlgorithmParameterException: Wrong IV Length](https://www.baeldung.com/java-invalidalgorithmparameter-exception) - [The java.security.egd JVM Option](https://www.baeldung.com/java-security-egd) -- [RSA in Java](https://www.baeldung.com/java-rsa) -- [3DES in Java](https://www.baeldung.com/java-3des) - More articles: [[<-- prev]](/core-java-modules/core-java-security) 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 deleted file mode 100644 index 2952eef625..0000000000 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.baeldung.aes; - -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.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; -import java.security.SecureRandom; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; -import java.util.Base64; - -public class AESUtil { - - 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) - 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 { - 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, 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); - } - } - byte[] outputBytes = cipher.doFinal(); - if (outputBytes != null) { - outputStream.write(outputBytes); - } - inputStream.close(); - outputStream.close(); - } - - 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); - } - } - byte[] output = cipher.doFinal(); - if (output != null) { - outputStream.write(output); - } - inputStream.close(); - outputStream.close(); - } - - 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 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 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))); - } - -} 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 deleted file mode 100644 index 13cd1c5e9d..0000000000 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.aes; - -import java.io.Serializable; -import java.util.Objects; - -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; - } - - @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); - } -} 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 deleted file mode 100644 index 531c20ca79..0000000000 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.baeldung.aes; - -import org.assertj.core.api.WithAssertions; -import org.junit.jupiter.api.Assertions; -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, IllegalBlockSizeException, InvalidKeyException, - BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { - // 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, IllegalBlockSizeException, InvalidKeyException, - BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { - // 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); - encryptedFile.delete(); - decryptedFile.delete(); - } - - @Test - 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); - 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).isEqualTo(object); - } - - @Test - void givenPassword_whenEncrypt_thenSuccess() - throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, - InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { - // 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); - } -} diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java deleted file mode 100644 index fa38aca272..0000000000 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.cipher; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.security.Provider; -import java.security.Security; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class AvailableCiphersUnitTest { - private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class); - - @Test - public void whenGetServices_thenGetAllCipherAlgorithms() { - for (Provider provider : Security.getProviders()) { - for (Provider.Service service : provider.getServices()) { - logger.info(service.getAlgorithm()); - } - } - } - - @Test - public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() { - List algorithms = Arrays.stream(Security.getProviders()) - .flatMap(provider -> provider.getServices().stream()) - .filter(service -> "Cipher".equals(service.getType())) - .map(Provider.Service::getAlgorithm) - .collect(Collectors.toList()); - - algorithms.forEach(logger::info); - } -} diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/des/TripleDESUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/des/TripleDESUnitTest.java deleted file mode 100644 index 6e5df8e619..0000000000 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/des/TripleDESUnitTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung.des; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import javax.crypto.Cipher; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; - -public class TripleDESUnitTest { - - @Test - public void given3DesKey_whenEncryptAndDecryptString_thenCompareResults() throws Exception { - byte[] secretKey = "9mng65v8jf4lxn93nabf981m".getBytes(); - byte[] iv = "a76nb5h9".getBytes(); - - String secretMessage = "Baeldung secret message"; - - SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, "DESede"); - IvParameterSpec ivSpec = new IvParameterSpec(iv); - Cipher encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); - encryptCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec); - byte[] secretMessagesBytes = secretMessage.getBytes(StandardCharsets.UTF_8); - byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessagesBytes); - - Cipher decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); - decryptCipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); - byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes); - String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8); - - Assertions.assertEquals(secretMessage, decryptedMessage); - } - - @Test - public void given3DesKey_whenEncryptAndDecryptFile_thenCompareResults() throws Exception { - byte[] secretKey = "9mng65v8jf4lxn93nabf981m".getBytes(); - byte[] iv = "a76nb5h9".getBytes(); - - SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, "DESede"); - IvParameterSpec ivSpec = new IvParameterSpec(iv); - - String originalContent = "some secret message"; - Path tempFile = Files.createTempFile("temp", "txt"); - writeString(tempFile, originalContent); - - byte[] fileBytes = Files.readAllBytes(tempFile); - Cipher encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); - encryptCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec); - byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes); - try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { - stream.write(encryptedFileBytes); - } - - encryptedFileBytes = Files.readAllBytes(tempFile); - Cipher decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); - decryptCipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); - byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes); - try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { - stream.write(decryptedFileBytes); - } - - String fileContent = readString(tempFile); - - Assertions.assertEquals(originalContent, fileContent); - } - - private void writeString(Path path, String content) throws Exception { - try (BufferedWriter writer = Files.newBufferedWriter(path)) { - writer.write(content); - } - } - - private String readString(Path path) throws Exception { - StringBuilder resultStringBuilder = new StringBuilder(); - try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) { - String line; - while ((line = br.readLine()) != null) { - resultStringBuilder.append(line); - } - } - return resultStringBuilder.toString(); - } -} diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java deleted file mode 100644 index ac93f71125..0000000000 --- a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.baeldung.cipher; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import javax.crypto.Cipher; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.PrivateKey; -import java.security.PublicKey; - -public class RsaUnitTest { - - @Test - public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception { - KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); - generator.initialize(2048); - KeyPair pair = generator.generateKeyPair(); - PrivateKey privateKey = pair.getPrivate(); - PublicKey publicKey = pair.getPublic(); - - String secretMessage = "Baeldung secret message"; - Cipher encryptCipher = Cipher.getInstance("RSA"); - encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8); - byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes); - - Cipher decryptCipher = Cipher.getInstance("RSA"); - decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes); - String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8); - - Assertions.assertEquals(secretMessage, decryptedMessage); - } - - @Test - public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception { - KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); - generator.initialize(2048); - KeyPair pair = generator.generateKeyPair(); - PrivateKey privateKey = pair.getPrivate(); - PublicKey publicKey = pair.getPublic(); - - String originalContent = "some secret message"; - Path tempFile = Files.createTempFile("temp", "txt"); - writeString(tempFile, originalContent); - - byte[] fileBytes = Files.readAllBytes(tempFile); - Cipher encryptCipher = Cipher.getInstance("RSA"); - encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes); - try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { - stream.write(encryptedFileBytes); - } - - encryptedFileBytes = Files.readAllBytes(tempFile); - Cipher decryptCipher = Cipher.getInstance("RSA"); - decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes); - try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { - stream.write(decryptedFileBytes); - } - - String fileContent = readString(tempFile); - - Assertions.assertEquals(originalContent, fileContent); - } - - private void writeString(Path path, String content) throws Exception { - try (BufferedWriter writer = Files.newBufferedWriter(path)) { - writer.write(content); - } - } - - private String readString(Path path) throws Exception { - StringBuilder resultStringBuilder = new StringBuilder(); - try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) { - String line; - while ((line = br.readLine()) != null) { - resultStringBuilder.append(line); - } - } - return resultStringBuilder.toString(); - } -} diff --git a/core-java-modules/core-java-security-algorithms/README.md b/core-java-modules/core-java-security-algorithms/README.md new file mode 100644 index 0000000000..a1ce244ab8 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/README.md @@ -0,0 +1,11 @@ +## Core Java Security Algorithms + +This module contains articles about core Java Security Algorithms such as AES, DES, RSA, etc + +### Relevant Articles: + +- [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms) +- [Java AES Encryption and Decryption](https://www.baeldung.com/java-aes-encryption-decryption) +- [InvalidAlgorithmParameterException: Wrong IV Length](https://www.baeldung.com/java-invalidalgorithmparameter-exception) +- [RSA in Java](https://www.baeldung.com/java-rsa) +- [3DES in Java](https://www.baeldung.com/java-3des) diff --git a/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt b/core-java-modules/core-java-security-algorithms/src/test/resources/baeldung.txt similarity index 100% rename from core-java-modules/core-java-security-2/src/test/resources/baeldung.txt rename to core-java-modules/core-java-security-algorithms/src/test/resources/baeldung.txt From 6f49cc9a9b5ccbc35881ae136f20e153548d8c90 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 14 Nov 2021 11:07:22 +0530 Subject: [PATCH 11/14] JAVA-8282: Moved 5 articles from core-java-security-2 module to new module core-java-security-algorithms --- .../core-java-security-algorithms/pom.xml | 52 ++++++ .../main/java/com/baeldung/aes/AESUtil.java | 156 ++++++++++++++++++ .../main/java/com/baeldung/aes/Student.java | 40 +++++ .../com/baeldung/aes/AESUtilUnitTest.java | 101 ++++++++++++ .../cipher/AvailableCiphersUnitTest.java | 35 ++++ .../com/baeldung/des/TripleDESUnitTest.java | 90 ++++++++++ .../java/com/baeldung/rsa/RsaUnitTest.java | 92 +++++++++++ 7 files changed, 566 insertions(+) create mode 100644 core-java-modules/core-java-security-algorithms/pom.xml create mode 100644 core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/AESUtil.java create mode 100644 core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/Student.java create mode 100644 core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/aes/AESUtilUnitTest.java create mode 100644 core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java create mode 100644 core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/des/TripleDESUnitTest.java create mode 100644 core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/rsa/RsaUnitTest.java diff --git a/core-java-modules/core-java-security-algorithms/pom.xml b/core-java-modules/core-java-security-algorithms/pom.xml new file mode 100644 index 0000000000..db1bf09ead --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + core-java-security-algorithms + 0.1.0-SNAPSHOT + core-java-security-algorithms + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + commons-codec + commons-codec + ${commons-codec.version} + + + org.bouncycastle + bcprov-jdk15on + ${bouncycastle.version} + + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + + javax.xml.bind + jaxb-api + ${jaxb-api.version} + + + + + + 1.60 + 1.11 + + 3.18.0 + 2.3.1 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/AESUtil.java new file mode 100644 index 0000000000..2952eef625 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/AESUtil.java @@ -0,0 +1,156 @@ +package com.baeldung.aes; + +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.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; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.util.Base64; + +public class AESUtil { + + 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) + 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 { + 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, 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); + } + } + byte[] outputBytes = cipher.doFinal(); + if (outputBytes != null) { + outputStream.write(outputBytes); + } + inputStream.close(); + outputStream.close(); + } + + 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); + } + } + byte[] output = cipher.doFinal(); + if (output != null) { + outputStream.write(output); + } + inputStream.close(); + outputStream.close(); + } + + 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 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 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))); + } + +} diff --git a/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/Student.java b/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/Student.java new file mode 100644 index 0000000000..13cd1c5e9d --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/main/java/com/baeldung/aes/Student.java @@ -0,0 +1,40 @@ +package com.baeldung.aes; + +import java.io.Serializable; +import java.util.Objects; + +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; + } + + @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); + } +} diff --git a/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/aes/AESUtilUnitTest.java new file mode 100644 index 0000000000..531c20ca79 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/aes/AESUtilUnitTest.java @@ -0,0 +1,101 @@ +package com.baeldung.aes; + +import org.assertj.core.api.WithAssertions; +import org.junit.jupiter.api.Assertions; +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, IllegalBlockSizeException, InvalidKeyException, + BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { + // 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, IllegalBlockSizeException, InvalidKeyException, + BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { + // 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); + encryptedFile.delete(); + decryptedFile.delete(); + } + + @Test + 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); + 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).isEqualTo(object); + } + + @Test + void givenPassword_whenEncrypt_thenSuccess() + throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { + // 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); + } +} diff --git a/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java new file mode 100644 index 0000000000..fa38aca272 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.cipher; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.security.Provider; +import java.security.Security; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class AvailableCiphersUnitTest { + private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class); + + @Test + public void whenGetServices_thenGetAllCipherAlgorithms() { + for (Provider provider : Security.getProviders()) { + for (Provider.Service service : provider.getServices()) { + logger.info(service.getAlgorithm()); + } + } + } + + @Test + public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() { + List algorithms = Arrays.stream(Security.getProviders()) + .flatMap(provider -> provider.getServices().stream()) + .filter(service -> "Cipher".equals(service.getType())) + .map(Provider.Service::getAlgorithm) + .collect(Collectors.toList()); + + algorithms.forEach(logger::info); + } +} diff --git a/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/des/TripleDESUnitTest.java b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/des/TripleDESUnitTest.java new file mode 100644 index 0000000000..6e5df8e619 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/des/TripleDESUnitTest.java @@ -0,0 +1,90 @@ +package com.baeldung.des; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +public class TripleDESUnitTest { + + @Test + public void given3DesKey_whenEncryptAndDecryptString_thenCompareResults() throws Exception { + byte[] secretKey = "9mng65v8jf4lxn93nabf981m".getBytes(); + byte[] iv = "a76nb5h9".getBytes(); + + String secretMessage = "Baeldung secret message"; + + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, "DESede"); + IvParameterSpec ivSpec = new IvParameterSpec(iv); + Cipher encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + encryptCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec); + byte[] secretMessagesBytes = secretMessage.getBytes(StandardCharsets.UTF_8); + byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessagesBytes); + + Cipher decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + decryptCipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); + byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes); + String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8); + + Assertions.assertEquals(secretMessage, decryptedMessage); + } + + @Test + public void given3DesKey_whenEncryptAndDecryptFile_thenCompareResults() throws Exception { + byte[] secretKey = "9mng65v8jf4lxn93nabf981m".getBytes(); + byte[] iv = "a76nb5h9".getBytes(); + + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, "DESede"); + IvParameterSpec ivSpec = new IvParameterSpec(iv); + + String originalContent = "some secret message"; + Path tempFile = Files.createTempFile("temp", "txt"); + writeString(tempFile, originalContent); + + byte[] fileBytes = Files.readAllBytes(tempFile); + Cipher encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + encryptCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec); + byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(encryptedFileBytes); + } + + encryptedFileBytes = Files.readAllBytes(tempFile); + Cipher decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + decryptCipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); + byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(decryptedFileBytes); + } + + String fileContent = readString(tempFile); + + Assertions.assertEquals(originalContent, fileContent); + } + + private void writeString(Path path, String content) throws Exception { + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + writer.write(content); + } + } + + private String readString(Path path) throws Exception { + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line); + } + } + return resultStringBuilder.toString(); + } +} diff --git a/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/rsa/RsaUnitTest.java b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/rsa/RsaUnitTest.java new file mode 100644 index 0000000000..9659fd8871 --- /dev/null +++ b/core-java-modules/core-java-security-algorithms/src/test/java/com/baeldung/rsa/RsaUnitTest.java @@ -0,0 +1,92 @@ +package com.baeldung.rsa; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.crypto.Cipher; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.security.PublicKey; + +public class RsaUnitTest { + + @Test + public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception { + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + KeyPair pair = generator.generateKeyPair(); + PrivateKey privateKey = pair.getPrivate(); + PublicKey publicKey = pair.getPublic(); + + String secretMessage = "Baeldung secret message"; + Cipher encryptCipher = Cipher.getInstance("RSA"); + encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); + byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8); + byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes); + + Cipher decryptCipher = Cipher.getInstance("RSA"); + decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); + byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes); + String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8); + + Assertions.assertEquals(secretMessage, decryptedMessage); + } + + @Test + public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception { + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + KeyPair pair = generator.generateKeyPair(); + PrivateKey privateKey = pair.getPrivate(); + PublicKey publicKey = pair.getPublic(); + + String originalContent = "some secret message"; + Path tempFile = Files.createTempFile("temp", "txt"); + writeString(tempFile, originalContent); + + byte[] fileBytes = Files.readAllBytes(tempFile); + Cipher encryptCipher = Cipher.getInstance("RSA"); + encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); + byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(encryptedFileBytes); + } + + encryptedFileBytes = Files.readAllBytes(tempFile); + Cipher decryptCipher = Cipher.getInstance("RSA"); + decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); + byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(decryptedFileBytes); + } + + String fileContent = readString(tempFile); + + Assertions.assertEquals(originalContent, fileContent); + } + + private void writeString(Path path, String content) throws Exception { + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + writer.write(content); + } + } + + private String readString(Path path) throws Exception { + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line); + } + } + return resultStringBuilder.toString(); + } +} From fc6c46b6f767ca8ed48d13e21a7e47c7f46d1eef Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 14 Nov 2021 11:08:05 +0530 Subject: [PATCH 12/14] JAVA-8282: added new module core-java-security-algorithms 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 c3d17e7637..5df65bd93f 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -100,6 +100,7 @@ core-java-security core-java-security-2 core-java-security-3 + core-java-security-algorithms core-java-streams core-java-streams-2 core-java-streams-3 From ee6ea3d612c8f7acafb112664d11d236fcdb227f Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 14 Nov 2021 13:20:22 +0530 Subject: [PATCH 13/14] JAVA-8365: Split or move core-java-io-conversions module --- .../core-java-io-conversions-2/README.md | 1 + .../JavaXToInputStreamUnitTest.java | 44 +++++++++++++++++++ .../core-java-io-conversions/README.md | 1 - .../JavaXToInputStreamUnitTest.java | 41 +++++------------ 4 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/stringtoinputstream/JavaXToInputStreamUnitTest.java diff --git a/core-java-modules/core-java-io-conversions-2/README.md b/core-java-modules/core-java-io-conversions-2/README.md index b2153b3669..9abb539066 100644 --- a/core-java-modules/core-java-io-conversions-2/README.md +++ b/core-java-modules/core-java-io-conversions-2/README.md @@ -4,6 +4,7 @@ This module contains articles about core Java input/output(IO) conversions. ### Relevant Articles: - [Java InputStream to String](https://www.baeldung.com/convert-input-stream-to-string) +- [Java String to InputStream](https://www.baeldung.com/convert-string-to-input-stream) - [Java – Write an InputStream to a File](https://www.baeldung.com/convert-input-stream-to-a-file) - [Converting a BufferedReader to a JSONObject](https://www.baeldung.com/java-bufferedreader-to-jsonobject) - [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array) diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/stringtoinputstream/JavaXToInputStreamUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/stringtoinputstream/JavaXToInputStreamUnitTest.java new file mode 100644 index 0000000000..7e7c79f764 --- /dev/null +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/stringtoinputstream/JavaXToInputStreamUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.stringtoinputstream; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.io.CharSource; + +public class JavaXToInputStreamUnitTest { + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + // tests - String - InputStream + + @Test + public final void givenUsingPlainJava_whenConvertingStringToInputStream_thenCorrect() throws IOException { + final String initialString = "text"; + final InputStream targetStream = new ByteArrayInputStream(initialString.getBytes()); + + IOUtils.closeQuietly(targetStream); + } + + @Test + public final void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException { + final String initialString = "text"; + final InputStream targetStream = CharSource.wrap(initialString).asByteSource(StandardCharsets.UTF_8).openStream(); + + IOUtils.closeQuietly(targetStream); + } + + @Test + public final void givenUsingCommonsIO_whenConvertingStringToInputStream_thenCorrect() throws IOException { + final String initialString = "text"; + final InputStream targetStream = IOUtils.toInputStream(initialString); + + IOUtils.closeQuietly(targetStream); + } + +} diff --git a/core-java-modules/core-java-io-conversions/README.md b/core-java-modules/core-java-io-conversions/README.md index 52f5222040..1f12c87241 100644 --- a/core-java-modules/core-java-io-conversions/README.md +++ b/core-java-modules/core-java-io-conversions/README.md @@ -13,5 +13,4 @@ This module contains articles about core Java input/output(IO) conversions. - [Java – Write a Reader to File](https://www.baeldung.com/java-write-reader-to-file) - [Java – Reader to Byte Array](https://www.baeldung.com/java-convert-reader-to-byte-array) - [Java – Reader to InputStream](https://www.baeldung.com/java-convert-reader-to-inputstream) -- [Java String to InputStream](https://www.baeldung.com/convert-string-to-input-stream) - More articles: [[next -->]](/core-java-modules/core-java-io-conversions-2) diff --git a/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java b/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java index c20752639f..9d061307ce 100644 --- a/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java +++ b/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java @@ -1,46 +1,25 @@ package com.baeldung.filetoinputstream; -import com.google.common.io.ByteSource; -import com.google.common.io.CharSource; -import com.google.common.io.Files; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.SequenceInputStream; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; -import java.nio.charset.StandardCharsets; +import com.google.common.io.ByteSource; +import com.google.common.io.Files; public class JavaXToInputStreamUnitTest { protected final Logger logger = LoggerFactory.getLogger(getClass()); - // tests - String - InputStream - - @Test - public final void givenUsingPlainJava_whenConvertingStringToInputStream_thenCorrect() throws IOException { - final String initialString = "text"; - final InputStream targetStream = new ByteArrayInputStream(initialString.getBytes()); - - IOUtils.closeQuietly(targetStream); - } - - @Test - public final void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException { - final String initialString = "text"; - final InputStream targetStream = CharSource.wrap(initialString).asByteSource(StandardCharsets.UTF_8).openStream(); - - IOUtils.closeQuietly(targetStream); - } - - @Test - public final void givenUsingCommonsIO_whenConvertingStringToInputStream_thenCorrect() throws IOException { - final String initialString = "text"; - final InputStream targetStream = IOUtils.toInputStream(initialString); - - IOUtils.closeQuietly(targetStream); - } - // byte array - InputStream @Test From 4ca8e7ef235f9e0c6deb1113e6f5f89c2fd5d046 Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Sun, 14 Nov 2021 11:09:48 +0100 Subject: [PATCH 14/14] [BAEL-5211] - How to test a Java Optional (#11417) * feat: add how to test an optional * fix: review comments * fix: static final naming convention * fix: optional equals assertion --- .../baeldung/optional/OptionalUnitTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java new file mode 100644 index 0000000000..351b3dd3e0 --- /dev/null +++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.optional; + +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class OptionalUnitTest { + + private static final String OPTIONAL_RETURN_VALUE = "optionalReturnValue"; + + @Test + public void givenOptionalWithValue_whenAssertThatIsNotEmpty_thenOk() { + assertThat(Optional.of(OPTIONAL_RETURN_VALUE)).isNotEmpty(); + } + + @Test + public void givenOptionalWithValue_whenAssertThatHasValue_thenOk() { + assertThat(Optional.of(OPTIONAL_RETURN_VALUE)).hasValue(OPTIONAL_RETURN_VALUE); + } + + @Test + public void givenOptionalWithValue_whenAssertEqualsOptionalObject_thenOk() { + Optional expected = Optional.of(OPTIONAL_RETURN_VALUE); + Optional actual = Optional.of(OPTIONAL_RETURN_VALUE); + assertEquals(expected, actual); + } + + @Test + public void givenOptionalWithValue_whenAssertEqualsGet_thenOk() { + Optional optional = Optional.of(OPTIONAL_RETURN_VALUE); + assertEquals(OPTIONAL_RETURN_VALUE, optional.get()); + } + + @Test + public void givenOptionalWithValue_whenIsPresentAndGetSplit_thenOk() { + Optional optional = Optional.of(OPTIONAL_RETURN_VALUE); + + assertTrue(optional.isPresent()); + assertEquals(OPTIONAL_RETURN_VALUE, optional.get()); + } + + @Test + public void givenEmptyOptional_whenAssertThatIsEmpty_thenOk() { + Optional emptyOptional = Optional.empty(); + assertThat(emptyOptional).isEmpty(); + } + + @Test + public void givenEmptyOptional_whenAssertIsNotPresent_thenOk() { + Optional emptyOptional = Optional.empty(); + assertFalse(emptyOptional.isPresent()); + } +}