diff --git a/httpclient-2/.gitignore b/apache-httpclient-2/.gitignore similarity index 100% rename from httpclient-2/.gitignore rename to apache-httpclient-2/.gitignore diff --git a/httpclient-2/README.md b/apache-httpclient-2/README.md similarity index 85% rename from httpclient-2/README.md rename to apache-httpclient-2/README.md index 2e101a0609..45f1e41637 100644 --- a/httpclient-2/README.md +++ b/apache-httpclient-2/README.md @@ -1,6 +1,6 @@ -## HttpClient 4.x +## Apache HttpClient -This module contains articles about HttpClient 4.x +This module contains articles about Apache HttpClient ### The Course @@ -14,4 +14,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Enabling Logging for Apache HttpClient](https://www.baeldung.com/apache-httpclient-enable-logging) - [Expand Shortened URLs with Apache HttpClient](https://www.baeldung.com/apache-httpclient-expand-url) - [Apache HttpClient vs. CloseableHttpClient](https://www.baeldung.com/apache-httpclient-vs-closeablehttpclient) -- More articles: [[<-- prev]](../httpclient) +- More articles: [[<-- prev]](../apache-httpclient) diff --git a/httpclient-2/pom.xml b/apache-httpclient-2/pom.xml similarity index 96% rename from httpclient-2/pom.xml rename to apache-httpclient-2/pom.xml index f2da238494..c5b8195472 100644 --- a/httpclient-2/pom.xml +++ b/apache-httpclient-2/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - httpclient-2 + apache-httpclient-2 0.1-SNAPSHOT - httpclient-2 + apache-httpclient-2 com.baeldung @@ -74,7 +74,7 @@ - httpclient-2 + apache-httpclient-2 src/main/resources diff --git a/httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java b/apache-httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java similarity index 100% rename from httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java rename to apache-httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java diff --git a/httpclient-2/src/test/resources/logback.xml b/apache-httpclient-2/src/test/resources/logback.xml similarity index 100% rename from httpclient-2/src/test/resources/logback.xml rename to apache-httpclient-2/src/test/resources/logback.xml diff --git a/httpclient/.gitignore b/apache-httpclient/.gitignore similarity index 100% rename from httpclient/.gitignore rename to apache-httpclient/.gitignore diff --git a/httpclient/README.md b/apache-httpclient/README.md similarity index 80% rename from httpclient/README.md rename to apache-httpclient/README.md index ea3bc28572..338b416df1 100644 --- a/httpclient/README.md +++ b/apache-httpclient/README.md @@ -1,6 +1,6 @@ -## HttpClient 4.x +## Apache HttpClient -This module contains articles about HttpClient 4.x +This module contains articles about Apache HttpClient ### The Course @@ -13,8 +13,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Multipart Upload with Apache HttpClient](https://www.baeldung.com/httpclient-multipart-upload) - [Apache HttpAsyncClient Tutorial](https://www.baeldung.com/httpasyncclient-tutorial) - [Apache HttpClient Tutorial](https://www.baeldung.com/httpclient-guide) -- [Advanced HttpClient Configuration](https://www.baeldung.com/httpclient-advanced-config) +- [Advanced Apache HttpClient Configuration](https://www.baeldung.com/httpclient-advanced-config) - [Apache HttpClient – Do Not Follow Redirects](https://www.baeldung.com/httpclient-stop-follow-redirect) - [Custom User-Agent in Apache HttpClient](https://www.baeldung.com/httpclient-user-agent-header) - [Apache HttpClient Connection Management](https://www.baeldung.com/httpclient-connection-management) -- More articles: [[next -->]](../httpclient-2) +- More articles: [[next -->]](../apache-httpclient-2) diff --git a/httpclient/pom.xml b/apache-httpclient/pom.xml similarity index 95% rename from httpclient/pom.xml rename to apache-httpclient/pom.xml index b69981fb13..26eb319ac0 100644 --- a/httpclient/pom.xml +++ b/apache-httpclient/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - httpclient + apache-httpclient 0.1-SNAPSHOT - httpclient + apache-httpclient com.baeldung @@ -63,7 +63,7 @@ - httpclient + apache-httpclient src/main/resources diff --git a/httpclient/src/main/resources/logback.xml b/apache-httpclient/src/main/resources/logback.xml similarity index 100% rename from httpclient/src/main/resources/logback.xml rename to apache-httpclient/src/main/resources/logback.xml diff --git a/httpclient/src/main/resources/temp.txt b/apache-httpclient/src/main/resources/temp.txt similarity index 100% rename from httpclient/src/main/resources/temp.txt rename to apache-httpclient/src/main/resources/temp.txt diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java diff --git a/httpclient/src/test/resources/.gitignore b/apache-httpclient/src/test/resources/.gitignore similarity index 100% rename from httpclient/src/test/resources/.gitignore rename to apache-httpclient/src/test/resources/.gitignore diff --git a/httpclient/src/test/resources/test.in b/apache-httpclient/src/test/resources/test.in similarity index 100% rename from httpclient/src/test/resources/test.in rename to apache-httpclient/src/test/resources/test.in diff --git a/httpclient/src/test/resources/uploads/image.jpg b/apache-httpclient/src/test/resources/uploads/image.jpg similarity index 100% rename from httpclient/src/test/resources/uploads/image.jpg rename to apache-httpclient/src/test/resources/uploads/image.jpg diff --git a/httpclient/src/test/resources/uploads/sandbox.txt b/apache-httpclient/src/test/resources/uploads/sandbox.txt similarity index 100% rename from httpclient/src/test/resources/uploads/sandbox.txt rename to apache-httpclient/src/test/resources/uploads/sandbox.txt diff --git a/httpclient/src/test/resources/uploads/temp.txt b/apache-httpclient/src/test/resources/uploads/temp.txt similarity index 100% rename from httpclient/src/test/resources/uploads/temp.txt rename to apache-httpclient/src/test/resources/uploads/temp.txt diff --git a/httpclient/src/test/resources/uploads/zipFile.zip b/apache-httpclient/src/test/resources/uploads/zipFile.zip similarity index 100% rename from httpclient/src/test/resources/uploads/zipFile.zip rename to apache-httpclient/src/test/resources/uploads/zipFile.zip diff --git a/aws-app-sync/README.md b/aws-modules/aws-app-sync/README.md similarity index 100% rename from aws-app-sync/README.md rename to aws-modules/aws-app-sync/README.md diff --git a/aws-app-sync/pom.xml b/aws-modules/aws-app-sync/pom.xml similarity index 96% rename from aws-app-sync/pom.xml rename to aws-modules/aws-app-sync/pom.xml index b759de4a72..8d7d90e631 100644 --- a/aws-app-sync/pom.xml +++ b/aws-modules/aws-app-sync/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java b/aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java similarity index 100% rename from aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java rename to aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java diff --git a/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java b/aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java similarity index 100% rename from aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java rename to aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java diff --git a/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java b/aws-modules/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java similarity index 100% rename from aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java rename to aws-modules/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java diff --git a/aws-lambda/.gitignore b/aws-modules/aws-lambda/.gitignore similarity index 100% rename from aws-lambda/.gitignore rename to aws-modules/aws-lambda/.gitignore diff --git a/aws-lambda/README.md b/aws-modules/aws-lambda/README.md similarity index 73% rename from aws-lambda/README.md rename to aws-modules/aws-lambda/README.md index 0ae188fc97..a845c5835e 100644 --- a/aws-lambda/README.md +++ b/aws-modules/aws-lambda/README.md @@ -3,7 +3,9 @@ This module contains articles about AWS Lambda ### Relevant Articles: +- [A Basic AWS Lambda Example With Java](https://www.baeldung.com/java-aws-lambda) - [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway) - [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless) - [How to Implement Hibernate in an AWS Lambda Function in Java](https://www.baeldung.com/java-aws-lambda-hibernate) - [Writing an Enterprise-Grade AWS Lambda in Java](https://www.baeldung.com/java-enterprise-aws-lambda) +- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java) diff --git a/aws-lambda/lambda/pom.xml b/aws-modules/aws-lambda/lambda/pom.xml similarity index 100% rename from aws-lambda/lambda/pom.xml rename to aws-modules/aws-lambda/lambda/pom.xml diff --git a/aws-lambda/lambda/sam-templates/template-implicit.yaml b/aws-modules/aws-lambda/lambda/sam-templates/template-implicit.yaml similarity index 100% rename from aws-lambda/lambda/sam-templates/template-implicit.yaml rename to aws-modules/aws-lambda/lambda/sam-templates/template-implicit.yaml diff --git a/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml b/aws-modules/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml similarity index 100% rename from aws-lambda/lambda/sam-templates/template-inline-swagger.yaml rename to aws-modules/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java diff --git a/aws-lambda/lambda/src/main/resources/logback.xml b/aws-modules/aws-lambda/lambda/src/main/resources/logback.xml similarity index 100% rename from aws-lambda/lambda/src/main/resources/logback.xml rename to aws-modules/aws-lambda/lambda/src/main/resources/logback.xml diff --git a/aws-lambda/pom.xml b/aws-modules/aws-lambda/pom.xml similarity index 93% rename from aws-lambda/pom.xml rename to aws-modules/aws-lambda/pom.xml index fc655f282d..bdd295c007 100644 --- a/aws-lambda/pom.xml +++ b/aws-modules/aws-lambda/pom.xml @@ -9,7 +9,7 @@ com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT diff --git a/aws-lambda/shipping-tracker/.gitignore b/aws-modules/aws-lambda/shipping-tracker/.gitignore similarity index 100% rename from aws-lambda/shipping-tracker/.gitignore rename to aws-modules/aws-lambda/shipping-tracker/.gitignore diff --git a/aws-lambda/shipping-tracker/ShippingFunction/pom.xml b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/pom.xml similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/pom.xml rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/pom.xml diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java diff --git a/aws-lambda/shipping-tracker/template.yaml b/aws-modules/aws-lambda/shipping-tracker/template.yaml similarity index 100% rename from aws-lambda/shipping-tracker/template.yaml rename to aws-modules/aws-lambda/shipping-tracker/template.yaml diff --git a/aws-lambda/todo-reminder/ToDoFunction/pom.xml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/pom.xml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/pom.xml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/pom.xml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java diff --git a/aws-lambda/todo-reminder/template.yaml b/aws-modules/aws-lambda/todo-reminder/template.yaml similarity index 100% rename from aws-lambda/todo-reminder/template.yaml rename to aws-modules/aws-lambda/todo-reminder/template.yaml diff --git a/aws/.gitignore b/aws-modules/aws-miscellaneous/.gitignore similarity index 100% rename from aws/.gitignore rename to aws-modules/aws-miscellaneous/.gitignore diff --git a/aws-modules/aws-miscellaneous/README.md b/aws-modules/aws-miscellaneous/README.md new file mode 100644 index 0000000000..5be8e6a3f2 --- /dev/null +++ b/aws-modules/aws-miscellaneous/README.md @@ -0,0 +1,10 @@ +## AWS Miscellaneous + +This module contains articles about various Amazon Web Services (AWS) such as EC2, DynamoDB, SQS, RDS + +### Relevant articles + +- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java) +- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests) +- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java) +- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java) diff --git a/aws/pom.xml b/aws-modules/aws-miscellaneous/pom.xml similarity index 88% rename from aws/pom.xml rename to aws-modules/aws-miscellaneous/pom.xml index a57dd6690e..f05764f10a 100644 --- a/aws/pom.xml +++ b/aws-modules/aws-miscellaneous/pom.xml @@ -3,14 +3,14 @@ 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 - aws + aws-miscellaneous 0.1.0-SNAPSHOT - aws + aws-miscellaneous jar com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT @@ -58,17 +58,6 @@ ${dynamodblocal.version} test - - - org.lucee - jets3t - ${jets3t-version} - - - org.lucee - commons-codec - ${commons-codec-version} - diff --git a/aws/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java diff --git a/aws/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java diff --git a/aws/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java diff --git a/aws/src/main/java/com/baeldung/ec2/EC2Application.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/ec2/EC2Application.java similarity index 100% rename from aws/src/main/java/com/baeldung/ec2/EC2Application.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/ec2/EC2Application.java diff --git a/aws/src/main/java/com/baeldung/rds/AWSRDSService.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/rds/AWSRDSService.java similarity index 100% rename from aws/src/main/java/com/baeldung/rds/AWSRDSService.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/rds/AWSRDSService.java diff --git a/aws/src/main/java/com/baeldung/sqs/SQSApplication.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/sqs/SQSApplication.java similarity index 100% rename from aws/src/main/java/com/baeldung/sqs/SQSApplication.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/sqs/SQSApplication.java diff --git a/aws/src/main/resources/db.properties b/aws-modules/aws-miscellaneous/src/main/resources/db.properties similarity index 100% rename from aws/src/main/resources/db.properties rename to aws-modules/aws-miscellaneous/src/main/resources/db.properties diff --git a/aws/src/main/resources/logback.xml b/aws-modules/aws-miscellaneous/src/main/resources/logback.xml similarity index 100% rename from aws/src/main/resources/logback.xml rename to aws-modules/aws-miscellaneous/src/main/resources/logback.xml diff --git a/aws/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java b/aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java rename to aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java diff --git a/aws/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java b/aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java similarity index 100% rename from aws/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java rename to aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java diff --git a/aws/src/test/resources/test.properties b/aws-modules/aws-miscellaneous/src/test/resources/test.properties similarity index 100% rename from aws/src/test/resources/test.properties rename to aws-modules/aws-miscellaneous/src/test/resources/test.properties diff --git a/aws-reactive/README.md b/aws-modules/aws-reactive/README.md similarity index 58% rename from aws-reactive/README.md rename to aws-modules/aws-reactive/README.md index 1abf987b52..9164bd0ea6 100644 --- a/aws-reactive/README.md +++ b/aws-modules/aws-reactive/README.md @@ -1,3 +1,7 @@ +## AWS Reactive + +This module contains articles about reactive support with AWS + ### Relevant Articles: - [AWS S3 with Java – Reactive Support](https://www.baeldung.com/java-aws-s3-reactive) diff --git a/aws-reactive/images/rective-upload.png b/aws-modules/aws-reactive/images/rective-upload.png similarity index 100% rename from aws-reactive/images/rective-upload.png rename to aws-modules/aws-reactive/images/rective-upload.png diff --git a/aws-reactive/images/rective-upload.txt b/aws-modules/aws-reactive/images/rective-upload.txt similarity index 100% rename from aws-reactive/images/rective-upload.txt rename to aws-modules/aws-reactive/images/rective-upload.txt diff --git a/aws-reactive/images/thread-per-client.png b/aws-modules/aws-reactive/images/thread-per-client.png similarity index 100% rename from aws-reactive/images/thread-per-client.png rename to aws-modules/aws-reactive/images/thread-per-client.png diff --git a/aws-reactive/images/thread-per-client.txt b/aws-modules/aws-reactive/images/thread-per-client.txt similarity index 100% rename from aws-reactive/images/thread-per-client.txt rename to aws-modules/aws-reactive/images/thread-per-client.txt diff --git a/aws-reactive/pom.xml b/aws-modules/aws-reactive/pom.xml similarity index 98% rename from aws-reactive/pom.xml rename to aws-modules/aws-reactive/pom.xml index 923e1361ab..7a9cefb9d1 100644 --- a/aws-reactive/pom.xml +++ b/aws-modules/aws-reactive/pom.xml @@ -10,7 +10,7 @@ com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java diff --git a/aws-reactive/src/main/resources/application-minio.yml b/aws-modules/aws-reactive/src/main/resources/application-minio.yml similarity index 100% rename from aws-reactive/src/main/resources/application-minio.yml rename to aws-modules/aws-reactive/src/main/resources/application-minio.yml diff --git a/aws-reactive/src/main/resources/application.yml b/aws-modules/aws-reactive/src/main/resources/application.yml similarity index 100% rename from aws-reactive/src/main/resources/application.yml rename to aws-modules/aws-reactive/src/main/resources/application.yml diff --git a/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java b/aws-modules/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java similarity index 100% rename from aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java rename to aws-modules/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java diff --git a/aws-reactive/src/test/resources/testimage1.png b/aws-modules/aws-reactive/src/test/resources/testimage1.png similarity index 100% rename from aws-reactive/src/test/resources/testimage1.png rename to aws-modules/aws-reactive/src/test/resources/testimage1.png diff --git a/aws-reactive/src/test/resources/testimage2.png b/aws-modules/aws-reactive/src/test/resources/testimage2.png similarity index 100% rename from aws-reactive/src/test/resources/testimage2.png rename to aws-modules/aws-reactive/src/test/resources/testimage2.png diff --git a/aws-modules/aws-s3/.gitignore b/aws-modules/aws-s3/.gitignore new file mode 100644 index 0000000000..bf11a4cc38 --- /dev/null +++ b/aws-modules/aws-s3/.gitignore @@ -0,0 +1,2 @@ +/target/ +.idea/ \ No newline at end of file diff --git a/aws-modules/aws-s3/README.md b/aws-modules/aws-s3/README.md new file mode 100644 index 0000000000..efebf7d933 --- /dev/null +++ b/aws-modules/aws-s3/README.md @@ -0,0 +1,9 @@ +## AWS S3 + +This module contains articles about Simple Storage Service (S3) on AWS + +### Relevant articles + +- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java) +- [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload) +- [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3) \ No newline at end of file diff --git a/aws-modules/aws-s3/pom.xml b/aws-modules/aws-s3/pom.xml new file mode 100644 index 0000000000..65ad6f27f8 --- /dev/null +++ b/aws-modules/aws-s3/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + aws-s3 + 0.1.0-SNAPSHOT + aws-s3 + jar + + + com.baeldung + aws-modules + 1.0.0-SNAPSHOT + + + + + com.amazonaws + aws-java-sdk + ${aws-java-sdk.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + org.lucee + jets3t + ${jets3t-version} + + + org.lucee + commons-codec + ${commons-codec-version} + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + false + + + + package + + shade + + + + + + + + + 1.11.290 + 1.10.L001 + 0.9.4.0006L + 3.0.0 + + + \ No newline at end of file diff --git a/aws/src/main/java/com/baeldung/s3/AWSS3Service.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/AWSS3Service.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/AWSS3Service.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/AWSS3Service.java diff --git a/aws/src/main/java/com/baeldung/s3/MultipartUpload.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/MultipartUpload.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/MultipartUpload.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/MultipartUpload.java diff --git a/aws/src/main/java/com/baeldung/s3/S3Application.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/S3Application.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/S3Application.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/S3Application.java diff --git a/spring-boot-modules/spring-boot/src/main/resources/logback.xml b/aws-modules/aws-s3/src/main/resources/logback.xml similarity index 57% rename from spring-boot-modules/spring-boot/src/main/resources/logback.xml rename to aws-modules/aws-s3/src/main/resources/logback.xml index 56af2d397e..7d900d8ea8 100644 --- a/spring-boot-modules/spring-boot/src/main/resources/logback.xml +++ b/aws-modules/aws-s3/src/main/resources/logback.xml @@ -7,12 +7,6 @@ - - - - - - diff --git a/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java diff --git a/aws/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java diff --git a/aws/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java diff --git a/aws-modules/pom.xml b/aws-modules/pom.xml new file mode 100644 index 0000000000..4bdffa789a --- /dev/null +++ b/aws-modules/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + aws-modules + aws-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + aws-app-sync + aws-lambda + aws-miscellaneous + aws-reactive + aws-s3 + + + \ No newline at end of file diff --git a/aws/README.md b/aws/README.md deleted file mode 100644 index 9006c2d190..0000000000 --- a/aws/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## AWS - -This module contains articles about Amazon Web Services (AWS) - -### Relevant articles - -- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java) -- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java) -- [A Basic AWS Lambda Example With Java](https://www.baeldung.com/java-aws-lambda) -- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java) -- [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload) -- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests) -- [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3) -- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java) -- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java) diff --git a/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so b/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so deleted file mode 100644 index 884615789b..0000000000 Binary files a/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so and /dev/null differ diff --git a/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so b/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so deleted file mode 100644 index 15e7469e38..0000000000 Binary files a/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so and /dev/null differ diff --git a/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll b/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll deleted file mode 100644 index 70d258f29b..0000000000 Binary files a/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll and /dev/null differ diff --git a/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll b/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll deleted file mode 100644 index c988e5a697..0000000000 Binary files a/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll and /dev/null differ diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/httpclient/basicauthentication/HttpClientBasicAuthentication.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/httpclient/basicauthentication/HttpClientBasicAuthentication.java new file mode 100644 index 0000000000..3ade3bd553 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/httpclient/basicauthentication/HttpClientBasicAuthentication.java @@ -0,0 +1,67 @@ +package com.baeldung.httpclient.basicauthentication; + +import java.io.IOException; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.util.Base64; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HttpClientBasicAuthentication { + + private static final Logger logger = LoggerFactory.getLogger(HttpClientBasicAuthentication.class); + + public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { + useClientWithAuthenticator(); + useClientWithHeaders(); + } + + private static void useClientWithAuthenticator() throws URISyntaxException, IOException, InterruptedException { + HttpClient client = HttpClient.newBuilder() + .authenticator(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication("postman", "password".toCharArray()); + } + }) + .build(); + + HttpRequest request = HttpRequest.newBuilder() + .GET() + .uri(new URI("https://postman-echo.com/basic-auth")) + .build(); + + HttpResponse response = client.send(request, BodyHandlers.ofString()); + + logger.info("Status using authenticator {}", response.statusCode()); + } + + private static void useClientWithHeaders() throws IOException, InterruptedException, URISyntaxException { + HttpClient client = HttpClient.newBuilder() + .build(); + + HttpRequest request = HttpRequest.newBuilder() + .GET() + .uri(new URI("https://postman-echo.com/basic-auth")) + .header("Authorization", getBasicAuthenticationHeader("postman", "password")) + .build(); + + HttpResponse response = client.send(request, BodyHandlers.ofString()); + + logger.info("Status using headers: {}", response.statusCode()); + } + + private static final String getBasicAuthenticationHeader(String username, String password) { + String valueToEncode = username + ":" + password; + return "Basic " + Base64.getEncoder() + .encodeToString(valueToEncode.getBytes()); + } + +} diff --git a/core-java-modules/core-java-collections-list-3/README.md b/core-java-modules/core-java-collections-list-3/README.md index 967e148a99..bcc8b3f3ed 100644 --- a/core-java-modules/core-java-collections-list-3/README.md +++ b/core-java-modules/core-java-collections-list-3/README.md @@ -11,4 +11,5 @@ This module contains articles about the Java List collection - [Filtering a Java Collection by a List](https://www.baeldung.com/java-filter-collection-by-list) - [How to Count Duplicate Elements in Arraylist](https://www.baeldung.com/java-count-duplicate-elements-arraylist) - [Finding the Differences Between Two Lists in Java](https://www.baeldung.com/java-lists-difference) +- [List vs. ArrayList in Java](https://www.baeldung.com/java-list-vs-arraylist) - [[<-- Prev]](/core-java-modules/core-java-collections-list-2) diff --git a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ArrayListDemo.java b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ArrayListDemo.java new file mode 100644 index 0000000000..f425f19189 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ArrayListDemo.java @@ -0,0 +1,51 @@ +package com.baeldung.list.listvsarraylist; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Locale; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ArrayListDemo { + + private ArrayList passengers = new ArrayList<>(20); +// private LinkedList passengers = new LinkedList<>(); // compile time error + + public ArrayList addPassenger(Passenger passenger) { + passengers.add(passenger); + return passengers; + } + + public ArrayList removePassenger(Passenger passenger) { + passengers.remove(passenger); + return passengers; + } + + public ArrayList getPassengersBySource(String source) { + return new ArrayList(passengers.stream() + .filter(it -> it.getSource().equals(source)) + .collect(Collectors.toList())); + } + + public ArrayList getPassengersByDestination(String destination) { + return new ArrayList (passengers.stream() + .filter(it -> it.getDestination().equals(destination)) + .collect(Collectors.toList())); + } + + public long getKidsCount(ArrayList passengerList) { + return passengerList.stream() + .filter(it -> (it.getAge() <= 10)) + .count(); + } + + public ArrayList getFinalPassengersList() { + return new ArrayList (Collections.unmodifiableList(passengers)); + } + + public ArrayList getServicedCountries() { + return new ArrayList (Stream.of(Locale.getISOCountries()) + .collect(Collectors.toList())); + } + +} diff --git a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ListDemo.java b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ListDemo.java new file mode 100644 index 0000000000..a9a182d21e --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/ListDemo.java @@ -0,0 +1,53 @@ +package com.baeldung.list.listvsarraylist; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ListDemo { + + private List passengers = new ArrayList<>(20); +// private List passengers = new LinkedList<>(); // No compile time error + + public List addPassenger(Passenger passenger) { + passengers.add(passenger); + return passengers; + } + + public List removePassenger(Passenger passenger) { + passengers.remove(passenger); + return passengers; + } + + public List getPassengersBySource(String source) { + return passengers.stream() + .filter(it -> it.getSource().equals(source)) + .collect(Collectors.toList()); + } + + public List getPassengersByDestination(String destination) { + return passengers.stream() + .filter(it -> it.getDestination().equals(destination)) + .collect(Collectors.toList()); + } + + public long getKidsCount(List passengerList) { + return passengerList.stream() + .filter(it -> (it.getAge() <= 10)) + .count(); + } + + public List getFinalPassengersList() { + return Collections.unmodifiableList(passengers); + } + + public List getServicedCountries() { + return Stream.of(Locale.getISOCountries()) + .collect(Collectors.toList()); + } + +} diff --git a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/Passenger.java b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/Passenger.java new file mode 100644 index 0000000000..9c61b70aa6 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/listvsarraylist/Passenger.java @@ -0,0 +1,49 @@ +package com.baeldung.list.listvsarraylist; + +public class Passenger { + + private String name; + private int age; + private String source; + private String destination; + + public Passenger(String name, int age, String source, String destination) { + this.name = name; + this.age = age; + this.source = source; + this.destination = destination; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getDestination() { + return destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + +} diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listOfHashMaps/ListOfHashMapsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listOfHashMaps/ListOfHashMapsUnitTest.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java new file mode 100644 index 0000000000..321fa475f6 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.list.listoflists; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +public class ListOfListsUnitTest { + + private List> getListOfListsFromCsv() throws URISyntaxException, IOException { + + List lines = Files.readAllLines(Paths.get(getClass().getResource("/listoflists/example.csv") + .toURI())); + List> listOfLists = new ArrayList<>(); + + lines.forEach(line -> { + List innerList = new ArrayList<>(Arrays.asList(line.split(", "))); + listOfLists.add(innerList); + }); + return listOfLists; + } + + private void printListOfLists(List> listOfLists) { + System.out.println("\n List of Lists "); + System.out.println("-------------------------------------"); + listOfLists.forEach(innerList -> { + String line = String.join(", ", innerList); + System.out.println(line); + }); + } + + @Test + void givenCsv_whenInitListOfLists_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + assertThat(listOfLists).hasSize(3); + assertThat(listOfLists.stream() + .map(List::size) + .collect(Collectors.toSet())).hasSize(1) + .containsExactly(4); + printListOfLists(listOfLists); + } + + @Test + void givenListOfLists_whenRemoveElementFromInnerLists_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + + listOfLists.forEach(innerList -> innerList.remove("Delete Me")); + assertThat(listOfLists.stream() + .map(List::size) + .collect(Collectors.toSet())).hasSize(1) + .containsExactly(3); + + printListOfLists(listOfLists); + } + + @Test + void givenListOfLists_whenAddNewInnerList_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + List newList = new ArrayList<>(Arrays.asList("Slack", "Zoom", "Microsoft Teams", "Telegram")); + listOfLists.add(2, newList); + + assertThat(listOfLists).hasSize(4); + assertThat(listOfLists.get(2)).containsExactly("Slack", "Zoom", "Microsoft Teams", "Telegram"); + printListOfLists(listOfLists); + } +} diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ArrayListDemoUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ArrayListDemoUnitTest.java new file mode 100644 index 0000000000..59094ab562 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ArrayListDemoUnitTest.java @@ -0,0 +1,91 @@ +package com.baeldung.list.listvsarraylist; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Locale; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ArrayListDemoUnitTest { + + ArrayListDemo application = new ArrayListDemo(); + + Passenger passenger1; + Passenger passenger2; + Passenger passenger3; + + @BeforeEach + protected void setUp() { + passenger1 = new Passenger("Anna", 25, "London", "New York"); + passenger2 = new Passenger("Binny", 35, "New York", "London"); + passenger3 = new Passenger("Chandra", 8, "Paris", "New Delhi"); + application.addPassenger(passenger1); + application.addPassenger(passenger2); + application.addPassenger(passenger3); + } + + @Test + public void givenEmptyList_whenAddedPassenger_thenReturnCurrentPassengerList() { + ArrayList list = application.addPassenger(new Passenger("David", 54, "Milan", "Paris")); + + assertNotNull(list); + assertThat(list).hasSize(4); + } + + @Test + public void givenPassengerList_whenRemovedPassenger_thenReturnCurrentPassengerList() { + ArrayList list = application.removePassenger(passenger3); + + assertNotNull(list); + assertThat(list).hasSize(2); + } + + @Test + public void givenPassengerList_whenPassedWithSourceCity_thenReturnMatchingPassengerList() { + ArrayList list = application.getPassengersBySource("Singapore"); + ArrayList list2 = application.getPassengersBySource("London"); + + assertThat(list).isEmpty(); + assertThat(list2.get(0)).isEqualTo(passenger1); + } + + @Test + public void givenPassengerList_whenPassedWithDestinationCity_thenReturnMatchingPassengerList() { + ArrayList list = application.getPassengersByDestination("Singapore"); + ArrayList list2 = application.getPassengersByDestination("London"); + + assertThat(list).isEmpty(); + assertThat(list2.get(0)).isEqualTo(passenger2); + } + + @Test + public void givenPassengerList_whenFindKidsByAge_thenReturnKidsList() { + ArrayList list = new ArrayList<>(); + list.add(passenger1); + list.add(passenger2); + list.add(passenger3); + long count = application.getKidsCount(list); + + assertThat(count).isEqualTo(1); + } + + @Test + public void givenPassengerList_whenCalledWithCollectionsFunction_thenReturnsListType() { + ArrayList list = application.getFinalPassengersList(); + + assertNotNull(list); + assertThat(list).hasSize(3); + } + + @Test + public void givenCurrentLocale_whenUsingStreams_thenReturnsListType() { + ArrayList servicedCountries = application.getServicedCountries(); + + assertNotNull(servicedCountries); + assertThat(servicedCountries).hasSize(Locale.getISOCountries().length); + } + +} diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ListDemoUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ListDemoUnitTest.java new file mode 100644 index 0000000000..cf239a79ce --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listvsarraylist/ListDemoUnitTest.java @@ -0,0 +1,92 @@ +package com.baeldung.list.listvsarraylist; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListDemoUnitTest { + + ListDemo application = new ListDemo(); + + Passenger passenger1; + Passenger passenger2; + Passenger passenger3; + + @BeforeEach + protected void setUp() { + passenger1 = new Passenger("Anna", 25, "London", "New York"); + passenger2 = new Passenger("Binny", 35, "New York", "London"); + passenger3 = new Passenger("Chandra", 8, "Paris", "New Delhi"); + application.addPassenger(passenger1); + application.addPassenger(passenger2); + application.addPassenger(passenger3); + } + + @Test + public void givenEmptyList_whenAddedPassenger_thenReturnCurrentPassengerList() { + List list = application.addPassenger(new Passenger("David", 54, "Milan", "Paris")); + + assertNotNull(list); + assertThat(list).hasSize(4); + } + + @Test + public void givenPresentList_whenRemovedPassenger_thenReturnCurrentPassengerList() { + List list = application.removePassenger(passenger3); + + assertNotNull(list); + assertThat(list).hasSize(2); + } + + @Test + public void givenPresentList_whenPassedWithSourceCity_thenReturnMatchingPassengerList() { + List list = application.getPassengersBySource("Singapore"); + List list2 = application.getPassengersBySource("London"); + + assertThat(list).isEmpty(); + assertThat(list2.get(0)).isEqualTo(passenger1); + } + + @Test + public void givenPresentList_whenPassedWithDestinationCity_thenReturnMatchingPassengerList() { + List list = application.getPassengersByDestination("Singapore"); + List list2 = application.getPassengersByDestination("London"); + + assertThat(list).isEmpty(); + assertThat(list2.get(0)).isEqualTo(passenger2); + } + + @Test + public void givenPassengerList_whenFindKidsByAge_thenReturnKidsList() { + List list = new ArrayList<>(); + list.add(passenger1); + list.add(passenger2); + list.add(passenger3); + long count = application.getKidsCount(list); + + assertThat(count).isEqualTo(1); + } + + @Test + public void givenPresentList_whenCalledWithCollectionsFunction_thenReturnsListType() { + List list = application.getFinalPassengersList(); + + assertNotNull(list); + assertThat(list).hasSize(3); + } + + @Test + public void givenCurrentLocale_whenUsingStreams_thenReturnsListType() { + List servicedCountries = application.getServicedCountries(); + + assertNotNull(servicedCountries); + assertThat(servicedCountries).hasSize(Locale.getISOCountries().length); + } + +} diff --git a/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv b/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv new file mode 100644 index 0000000000..e275848e19 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv @@ -0,0 +1,3 @@ +Linux, Microsoft Windows, Mac OS, Delete Me +Kotlin, Delete Me, Java, Python +Delete Me, Mercurial, Git, Subversion \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java new file mode 100644 index 0000000000..9ac20d73dd --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java @@ -0,0 +1,28 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +public class FixedTimeTask implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(FixedTimeTask.class); + + final int fixedTime; // milliseconds + + public FixedTimeTask(int fixedTime) { + this.fixedTime = fixedTime; + } + + @Override + public void run() { + LOG.info(fixedTime + " milliseconds running task"); + try { + TimeUnit.MILLISECONDS.sleep(fixedTime); + } catch (InterruptedException e) { + LOG.info("interrupted"); + } + LOG.info("finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java new file mode 100644 index 0000000000..7167859308 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java @@ -0,0 +1,21 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LongRunningTask implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(LongRunningTask.class); + + @Override + public void run() { + LOG.info("running"); + for (int i = 0; i < Long.MAX_VALUE; i++) { + if (Thread.interrupted()) { + LOG.info("stopping"); + return; + } + } + LOG.info("finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java new file mode 100644 index 0000000000..d6d8c8c036 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java @@ -0,0 +1,23 @@ +package com.baeldung.concurrent.stopexecution; + +import java.util.Random; + +public class Step { + + private static int MAX = Integer.MAX_VALUE / 2; + int number; + + public Step(int number) { + this.number = number; + } + + public void perform() throws InterruptedException { + Random rnd = new Random(); + int target = rnd.nextInt(MAX); + while (rnd.nextInt(MAX) != target) { + if (Thread.interrupted()) { + throw new InterruptedException(); + } + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java new file mode 100644 index 0000000000..5b2b0c445a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java @@ -0,0 +1,31 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class SteppedTask implements Runnable { + private static final Logger LOG = LoggerFactory.getLogger(SteppedTask.class); + + private List steps; + + public SteppedTask(List steps) { + this.steps = steps; + } + + @Override + public void run() { + LOG.info("running stepped process"); + for (Step step : steps) { + LOG.info("running step " + step.number); + try { + step.perform(); + } catch (InterruptedException e) { + LOG.info("interrupting task"); + return; + } + } + LOG.info("stepped process finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java new file mode 100644 index 0000000000..ac4af8adc4 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java @@ -0,0 +1,95 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Timer; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class StoppingExecution { + + private static final Logger LOG = LoggerFactory.getLogger(StoppingExecution.class); + + public static void main(String[] args) { + StoppingExecution.testUsingLoop(); + StoppingExecution.testUsingTimer(); + StoppingExecution.testUsingFuture(); + StoppingExecution.testScheduledExecutor(); + StoppingExecution.testSteppedProcess(); + } + + public static void testUsingLoop() { + LOG.info("using loop started"); + long start = System.currentTimeMillis(); + long end = start + 30 * 1000; // 30 seconds + while (System.currentTimeMillis() < end) { + LOG.info("running task"); + new FixedTimeTask(7 * 1000).run(); // 7 seconds + } + LOG.info("using loop ended"); + } + + public static void testUsingTimer() { + LOG.info("using timer started"); + Thread thread = new Thread(new LongRunningTask()); + thread.start(); + + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + + LOG.info("scheduling timeout in 3 seconds"); + timer.schedule(timeOutTask, 3000); + LOG.info("using timer ended"); + } + + public static void testUsingFuture() { + LOG.info("using future started"); + ExecutorService executor = Executors.newSingleThreadExecutor(); + Future future = executor.submit(new LongRunningTask()); + try { + LOG.info("future get with 7 seconds timeout"); + future.get(7, TimeUnit.SECONDS); + } catch (TimeoutException e) { + LOG.info("future timeout"); + future.cancel(true); + } catch (Exception e) { + LOG.info("future exception", e); + } finally { + executor.shutdownNow(); + } + LOG.info("using future ended"); + } + + public static void testScheduledExecutor() { + LOG.info("using future schedule executor started"); + + ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); + Future future = executor.submit(new LongRunningTask()); + Runnable cancelTask = () -> future.cancel(true); + + LOG.info("cancel task in 3 seconds"); + executor.schedule(cancelTask, 3000, TimeUnit.MILLISECONDS); + executor.shutdown(); + LOG.info("using future schedule executor ended"); + } + + public static void testSteppedProcess() { + List steps = Stream.of(new Step(1), new Step(2), new Step(3), new Step(4)).collect(Collectors.toList()); + + LOG.info("stepped process started"); + Thread thread = new Thread(new SteppedTask(steps)); + thread.start(); + + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + timer.schedule(timeOutTask, 10000); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java new file mode 100644 index 0000000000..e27e64476e --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java @@ -0,0 +1,22 @@ +package com.baeldung.concurrent.stopexecution; + +import java.util.Timer; +import java.util.TimerTask; + +public class TimeOutTask extends TimerTask { + private Thread thread; + private Timer timer; + + public TimeOutTask(Thread thread, Timer timer) { + this.thread = thread; + this.timer = timer; + } + + @Override + public void run() { + if (thread != null && thread.isAlive()) { + thread.interrupt(); + timer.cancel(); + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java new file mode 100644 index 0000000000..bbb8d0571a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class FixedTimeTaskUnitTest { + + @Test + public void run() throws InterruptedException { + long start = System.currentTimeMillis(); + Thread thread = new Thread(new FixedTimeTask(10)); + thread.start(); + thread.join(); + long end = System.currentTimeMillis(); + assertTrue(end - start >= 10); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java new file mode 100644 index 0000000000..c9bcb75e6d --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LongRunningTaskUnitTest { + + @Test + public void run() { + Thread thread = new Thread(new LongRunningTask()); + thread.start(); + assertTrue(thread.isAlive()); + + thread.interrupt(); + assertTrue(thread.isInterrupted()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java new file mode 100644 index 0000000000..ab9ac2732a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.*; + +public class SteppedTaskUnitTest { + + @Test + public void run() throws InterruptedException { + List steps = Stream.of( + new Step(1), + new Step(2), + new Step(3)) + .collect(Collectors.toList()); + + Thread thread = new Thread(new SteppedTask(steps)); + thread.start(); + thread.interrupt(); + thread.join(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java new file mode 100644 index 0000000000..39ec9f7d26 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import java.util.Timer; + +import static org.junit.Assert.assertTrue; + +public class TimeOutTaskUnitTest { + + @Test + public void run() { + Thread thread = new Thread(new LongRunningTask()); + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + thread.start(); + timeOutTask.run(); + assertTrue(thread.isInterrupted()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/subtractdays/SubtractDaysFromDateUnitTest.java b/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/subtractdays/SubtractDaysFromDateUnitTest.java index 9afb6e8db0..91cd29cd54 100644 --- a/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/subtractdays/SubtractDaysFromDateUnitTest.java +++ b/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/subtractdays/SubtractDaysFromDateUnitTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -15,7 +16,7 @@ public class SubtractDaysFromDateUnitTest { @Test public void givenLocalDateTime_whenSubtractingFiveDays_dateIsChangedCorrectly() { - LocalDate localDateTime = LocalDate.of(2022, 4, 20); + LocalDateTime localDateTime = LocalDateTime.of(2022, 4, 20, 0, 0); localDateTime = localDateTime.minusDays(5); diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java new file mode 100644 index 0000000000..f11f3d032d --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung.scanner; + +import org.junit.Test; + +import java.util.*; +import java.util.regex.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ScannerUnitTest { + @Test public void scannerSkipUsingPattern() { + String str = "Java scanner skip tutorial"; + // Instantiates Scanner + Scanner sc = new Scanner(str); + // By using skip(Pattern) method is to skip that meets the given pattern + sc.skip(Pattern.compile(".ava")); + assertEquals(sc.nextLine(), " scanner skip tutorial"); + // Scanner closed + sc.close(); + } + + @Test public void scannerSkipUsingStringPattern() { + String str = "Java scanner skip tutorial"; + // Instantiates Scanner + Scanner sc = new Scanner(str); + // By using skip(String) method is to skip that meets the given + // pattern constructed from the given String + sc.skip("Java"); + assertEquals(sc.nextLine(), " scanner skip tutorial"); + + // Scanner closed + sc.close(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-4/README.md b/core-java-modules/core-java-lang-4/README.md index a145633d2b..befef0b6eb 100644 --- a/core-java-modules/core-java-lang-4/README.md +++ b/core-java-modules/core-java-lang-4/README.md @@ -11,3 +11,4 @@ This module contains articles about core features in the Java language - [Fixing the “Declared package does not match the expected package” Error](https://www.baeldung.com/java-declared-expected-package-error) - [Chaining Constructors in Java](https://www.baeldung.com/java-chain-constructors) - [Difference Between POJO, JavaBeans, DTO and VO](https://www.baeldung.com/java-pojo-javabeans-dto-vo) +- [Implements vs. Extends in Java](https://www.baeldung.com/java-implements-vs-extends) diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java index 8e9d3afdde..90335b4aba 100644 --- a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java +++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java @@ -125,6 +125,8 @@ public class StringPerformance { stringSplit.add(longString.substring(pos, end)); pos = end + 1; } + //Add last token of string + stringSplit.add(longString.substring(pos)); return stringSplit; } diff --git a/graphql/graphql-error-handling/pom.xml b/graphql/graphql-error-handling/pom.xml new file mode 100644 index 0000000000..0cd00df3b9 --- /dev/null +++ b/graphql/graphql-error-handling/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + com.baeldung.graphql + graphql-error-handling + 1.0 + jar + graphql-error-handling + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + 1.8 + 1.18.18 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-web + + + + com.graphql-java + graphql-spring-boot-starter + 5.0.2 + + + + com.graphql-java + graphql-java-tools + 5.2.4 + + + + org.projectlombok + lombok + ${lombok.version} + + + + com.h2database + h2 + ${h2.version} + + + + org.springframework.boot + spring-boot-test + test + 2.6.4 + + + + com.graphql-java + graphql-spring-boot-starter-test + test + 5.0.2 + + + + org.assertj + assertj-core + 3.22.0 + test + + + + org.skyscreamer + jsonassert + 1.5.0 + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplication.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplication.java new file mode 100644 index 0000000000..565c9e0a15 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplication.java @@ -0,0 +1,46 @@ +package com.baeldung.graphql.error.handling; + +import com.baeldung.graphql.error.handling.exception.GraphQLErrorAdapter; +import graphql.ExceptionWhileDataFetching; +import graphql.GraphQLError; +import graphql.servlet.GraphQLErrorHandler; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@SpringBootApplication +public class GraphQLErrorHandlerApplication { + public static void main(String[] args) { + SpringApplication.run(GraphQLErrorHandlerApplication.class, args); + } + + @Bean + public GraphQLErrorHandler errorHandler() { + return new GraphQLErrorHandler() { + @Override + public List processErrors(List errors) { + List clientErrors = errors.stream() + .filter(this::isClientError) + .collect(Collectors.toList()); + + List serverErrors = errors.stream() + .filter(e -> !isClientError(e)) + .map(GraphQLErrorAdapter::new) + .collect(Collectors.toList()); + + List e = new ArrayList<>(); + e.addAll(clientErrors); + e.addAll(serverErrors); + return e; + } + + private boolean isClientError(GraphQLError error) { + return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable); + } + }; + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Location.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Location.java new file mode 100644 index 0000000000..815bf3a26a --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Location.java @@ -0,0 +1,29 @@ +package com.baeldung.graphql.error.handling.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.List; + +@Data +@Entity +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Location { + @Id + private String zipcode; + + private String city; + private String state; + + @OneToMany(mappedBy = "location", fetch = FetchType.EAGER) + private List vehicles = new ArrayList<>(); +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Vehicle.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Vehicle.java new file mode 100644 index 0000000000..e206bdb009 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/domain/Vehicle.java @@ -0,0 +1,26 @@ +package com.baeldung.graphql.error.handling.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Data +@Entity +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Vehicle { + @Id + private String vin; + private Integer year; + private String make; + private String model; + private String trim; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "fk_location") + private Location location; +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/AbstractGraphQLException.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/AbstractGraphQLException.java new file mode 100644 index 0000000000..4e7be50ae4 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/AbstractGraphQLException.java @@ -0,0 +1,44 @@ +package com.baeldung.graphql.error.handling.exception; + +import graphql.ErrorType; +import graphql.GraphQLError; +import graphql.language.SourceLocation; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class AbstractGraphQLException extends RuntimeException implements GraphQLError { + private Map parameters = new HashMap(); + + public AbstractGraphQLException(String message) { + super(message); + } + + public AbstractGraphQLException(String message, Map additionParams) { + this(message); + if (additionParams != null) { + parameters = additionParams; + } + } + + @Override + public String getMessage() { + return super.getMessage(); + } + + @Override + public List getLocations() { + return null; + } + + @Override + public ErrorType getErrorType() { + return null; + } + + @Override + public Map getExtensions() { + return this.parameters; + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/GraphQLErrorAdapter.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/GraphQLErrorAdapter.java new file mode 100644 index 0000000000..d982f98db3 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/GraphQLErrorAdapter.java @@ -0,0 +1,48 @@ +package com.baeldung.graphql.error.handling.exception; + +import graphql.ErrorType; +import graphql.ExceptionWhileDataFetching; +import graphql.GraphQLError; +import graphql.language.SourceLocation; + +import java.util.List; +import java.util.Map; + +public class GraphQLErrorAdapter implements GraphQLError { + + private GraphQLError error; + + public GraphQLErrorAdapter(GraphQLError error) { + this.error = error; + } + + @Override + public Map getExtensions() { + return error.getExtensions(); + } + + @Override + public List getLocations() { + return error.getLocations(); + } + + @Override + public ErrorType getErrorType() { + return error.getErrorType(); + } + + @Override + public List getPath() { + return error.getPath(); + } + + @Override + public Map toSpecification() { + return error.toSpecification(); + } + + @Override + public String getMessage() { + return (error instanceof ExceptionWhileDataFetching) ? ((ExceptionWhileDataFetching) error).getException().getMessage() : error.getMessage(); + } +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/InvalidInputException.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/InvalidInputException.java new file mode 100644 index 0000000000..78c8e83e27 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/InvalidInputException.java @@ -0,0 +1,7 @@ +package com.baeldung.graphql.error.handling.exception; + +public class InvalidInputException extends RuntimeException { + public InvalidInputException(String message) { + super(message); + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleAlreadyPresentException.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleAlreadyPresentException.java new file mode 100644 index 0000000000..8f6f0ce615 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleAlreadyPresentException.java @@ -0,0 +1,14 @@ +package com.baeldung.graphql.error.handling.exception; + +import java.util.Map; + +public class VehicleAlreadyPresentException extends AbstractGraphQLException { + + public VehicleAlreadyPresentException(String message) { + super(message); + } + + public VehicleAlreadyPresentException(String message, Map additionParams) { + super(message, additionParams); + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleNotFoundException.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleNotFoundException.java new file mode 100644 index 0000000000..0d2ad8c597 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/exception/VehicleNotFoundException.java @@ -0,0 +1,14 @@ +package com.baeldung.graphql.error.handling.exception; + +import java.util.Map; + +public class VehicleNotFoundException extends AbstractGraphQLException { + + public VehicleNotFoundException(String message) { + super(message); + } + + public VehicleNotFoundException(String message, Map params) { + super(message, params); + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/InventoryRepository.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/InventoryRepository.java new file mode 100644 index 0000000000..f4a0043408 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/InventoryRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.graphql.error.handling.repository; + +import com.baeldung.graphql.error.handling.domain.Vehicle; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface InventoryRepository extends JpaRepository { +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/LocationRepository.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/LocationRepository.java new file mode 100644 index 0000000000..716b8d3ef3 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/repository/LocationRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.graphql.error.handling.repository; + +import com.baeldung.graphql.error.handling.domain.Location; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface LocationRepository extends JpaRepository { +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Mutation.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Mutation.java new file mode 100644 index 0000000000..8463ebf8eb --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Mutation.java @@ -0,0 +1,20 @@ +package com.baeldung.graphql.error.handling.resolver; + +import com.baeldung.graphql.error.handling.domain.Location; +import com.baeldung.graphql.error.handling.domain.Vehicle; +import com.baeldung.graphql.error.handling.service.InventoryService; +import com.coxautodev.graphql.tools.GraphQLMutationResolver; +import org.springframework.stereotype.Component; + +@Component +public class Mutation implements GraphQLMutationResolver { + private InventoryService inventoryService; + + public Mutation(InventoryService inventoryService) { + this.inventoryService = inventoryService; + } + + public Vehicle addVehicle(String vin, Integer year, String make, String model, String trim, Location location) { + return this.inventoryService.addVehicle(vin, year, make, model, trim, location); + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Query.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Query.java new file mode 100644 index 0000000000..ece018464a --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/resolver/Query.java @@ -0,0 +1,29 @@ +package com.baeldung.graphql.error.handling.resolver; + +import com.baeldung.graphql.error.handling.domain.Vehicle; +import com.baeldung.graphql.error.handling.service.InventoryService; +import com.coxautodev.graphql.tools.GraphQLQueryResolver; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class Query implements GraphQLQueryResolver { + private final InventoryService inventoryService; + + public Query(InventoryService inventoryService) { + this.inventoryService = inventoryService; + } + + public List searchAll() { + return this.inventoryService.searchAll(); + } + + public List searchByLocation(String zipcode) { + return this.inventoryService.searchByLocation(zipcode); + } + + public Vehicle searchByVin(String vin) { + return this.inventoryService.searchByVin(vin); + } +} diff --git a/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/service/InventoryService.java b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/service/InventoryService.java new file mode 100644 index 0000000000..7064b08760 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/java/com/baeldung/graphql/error/handling/service/InventoryService.java @@ -0,0 +1,67 @@ +package com.baeldung.graphql.error.handling.service; + +import com.baeldung.graphql.error.handling.domain.Location; +import com.baeldung.graphql.error.handling.domain.Vehicle; +import com.baeldung.graphql.error.handling.exception.InvalidInputException; +import com.baeldung.graphql.error.handling.exception.VehicleAlreadyPresentException; +import com.baeldung.graphql.error.handling.exception.VehicleNotFoundException; +import com.baeldung.graphql.error.handling.repository.InventoryRepository; +import com.baeldung.graphql.error.handling.repository.LocationRepository; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.*; + +@Service +public class InventoryService { + private InventoryRepository inventoryRepository; + private LocationRepository locationRepository; + + public InventoryService(InventoryRepository inventoryRepository, LocationRepository locationRepository) { + this.inventoryRepository = inventoryRepository; + this.locationRepository = locationRepository; + } + + @Transactional + public Vehicle addVehicle(String vin, Integer year, String make, String model, String trim, Location location) { + Optional existingVehicle = this.inventoryRepository.findById(vin); + if (existingVehicle.isPresent()) { + Map params = new HashMap<>(); + params.put("vin", vin); + throw new VehicleAlreadyPresentException("Failed to add vehicle. Vehicle with vin " + vin + " already present.", params); + } + Vehicle vehicle = Vehicle.builder() + .vin(vin) + .year(year) + .make(make) + .model(model) + .location(location) + .trim(trim) + .build(); + + this.locationRepository.save(location); + return this.inventoryRepository.save(vehicle); + } + + public List searchAll() { + return this.inventoryRepository.findAll(); + } + + public List searchByLocation(String zipcode) { + if (StringUtils.isEmpty(zipcode) || zipcode.length() != 5) { + throw new InvalidInputException("Invalid zipcode " + zipcode + " provided."); + } + return this.locationRepository.findById(zipcode) + .map(Location::getVehicles) + .orElse(new ArrayList<>()); + } + + public Vehicle searchByVin(String vin) { + return this.inventoryRepository.findById(vin).orElseThrow(() -> { + Map params = new HashMap<>(); + params.put("vin", vin); + return new VehicleNotFoundException("Vehicle with vin " + vin + " not found.", params); + }); + } +} diff --git a/graphql/graphql-error-handling/src/main/resources/application.yml b/graphql/graphql-error-handling/src/main/resources/application.yml new file mode 100644 index 0000000000..155e133a62 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/resources/application.yml @@ -0,0 +1,23 @@ +graphql: + servlet: + mapping: /graphql + +spring: + datasource: + url: "jdbc:h2:mem:graphqldb" + driverClassName: "org.h2.Driver" + username: sa + password: + + initialization-mode: always + platform: h2 + + jpa: + show-sql: true + properties: + hibernate: + dialect: org.hibernate.dialect.H2Dialect + ddl-auto: none + + h2: + console.enabled: true \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/main/resources/graphql/inventory.graphqls b/graphql/graphql-error-handling/src/main/resources/graphql/inventory.graphqls new file mode 100644 index 0000000000..7dcb5403c1 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/resources/graphql/inventory.graphqls @@ -0,0 +1,23 @@ +type Vehicle { + vin: ID! + year: Int! + make: String! + model: String! + trim: String! +} + +input Location { + city: String + state: String + zipcode: String! +} + +type Query { + searchAll: [Vehicle]! + searchByLocation(zipcode: String!): [Vehicle]! + searchByVin(vin: String!): Vehicle +} + +type Mutation { + addVehicle(vin: ID!, year: Int!, make: String!, model: String!, trim: String, location: Location): Vehicle! +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/main/resources/import.sql b/graphql/graphql-error-handling/src/main/resources/import.sql new file mode 100644 index 0000000000..62907a86c3 --- /dev/null +++ b/graphql/graphql-error-handling/src/main/resources/import.sql @@ -0,0 +1,7 @@ +insert into LOCATION values('07092', 'Mountainside', 'NJ'); +insert into LOCATION values ('94118', 'San Francisco', 'CA'); +insert into LOCATION values ('10002', 'New York', 'NY'); + +insert into VEHICLE (vin, year, make, model, trim, fk_location) values('KM8JN72DX7U587496', 2007, 'Hyundai', 'Tucson', null, '07092'); +insert into VEHICLE (vin, year, make, model, trim, fk_location) values('JTKKU4B41C1023346', 2012, 'Toyota', 'Scion', 'Xd', '94118'); +insert into VEHICLE (vin, year, make, model, trim, fk_location) values('1G1JC1444PZ215071', 2000, 'Chevrolet', 'CAVALIER VL', 'RS', '07092'); \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplicationIntegrationTest.java b/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplicationIntegrationTest.java new file mode 100644 index 0000000000..069a08ce02 --- /dev/null +++ b/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerApplicationIntegrationTest.java @@ -0,0 +1,55 @@ +package com.baeldung.graphql.error.handling; + +import com.graphql.spring.boot.test.GraphQLResponse; +import com.graphql.spring.boot.test.GraphQLTestTemplate; +import org.json.JSONException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; + +import static com.baeldung.graphql.error.handling.TestUtils.readFile; +import static java.lang.String.format; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = GraphQLErrorHandlerApplication.class) +public class GraphQLErrorHandlerApplicationIntegrationTest { + + @Autowired + private GraphQLTestTemplate graphQLTestTemplate; + + private static final String GRAPHQL_TEST_REQUEST_PATH = "graphql/request/%s.graphql"; + private static final String GRAPHQL_TEST_RESPONSE_PATH = "graphql/response/%s.json"; + + @Test + public void whenUnknownOperation_thenRespondWithRequestError() throws IOException, JSONException { + String graphqlName = "request_error_unknown_operation"; + GraphQLResponse actualResponse = graphQLTestTemplate.postForResource(format(GRAPHQL_TEST_REQUEST_PATH, graphqlName)); + String expectedResponse = readFile(format(GRAPHQL_TEST_RESPONSE_PATH, graphqlName)); + + JSONAssert.assertEquals(expectedResponse, actualResponse.getRawResponse().getBody(), true); + } + + @Test + public void whenInvalidSyntaxRequest_thenRespondWithRequestError() throws IOException, JSONException { + String graphqlName = "request_error_invalid_request_syntax"; + GraphQLResponse actualResponse = graphQLTestTemplate.postForResource(format(GRAPHQL_TEST_REQUEST_PATH, graphqlName)); + String expectedResponse = readFile(format(GRAPHQL_TEST_RESPONSE_PATH, graphqlName)); + + JSONAssert.assertEquals(expectedResponse, actualResponse.getRawResponse().getBody(), true); + } + + @Test + public void whenRequestAllNonNullField_thenRespondPartialDataWithFieldError() throws IOException, JSONException { + String graphqlName = "field_error_request_non_null_fields_partial_response"; + GraphQLResponse actualResponse = graphQLTestTemplate.postForResource(format(GRAPHQL_TEST_REQUEST_PATH, graphqlName)); + String expectedResponse = readFile(format(GRAPHQL_TEST_RESPONSE_PATH, graphqlName)); + + JSONAssert.assertEquals(expectedResponse, actualResponse.getRawResponse().getBody(), true); + } +} diff --git a/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/TestUtils.java b/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/TestUtils.java new file mode 100644 index 0000000000..557f1d9c91 --- /dev/null +++ b/graphql/graphql-error-handling/src/test/java/com/baeldung/graphql/error/handling/TestUtils.java @@ -0,0 +1,15 @@ +package com.baeldung.graphql.error.handling; + +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; +import java.nio.charset.Charset; + +public class TestUtils { + public static String readFile(String path) throws IOException { + return IOUtils.toString( + new ClassPathResource(path).getInputStream(), Charset.defaultCharset() + ); + } +} diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/request/field_error_request_non_null_fields_partial_response.graphql b/graphql/graphql-error-handling/src/test/resources/graphql/request/field_error_request_non_null_fields_partial_response.graphql new file mode 100644 index 0000000000..17affc50cb --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/request/field_error_request_non_null_fields_partial_response.graphql @@ -0,0 +1,10 @@ +# trim is non null but one of the record has null value for trim +query { + searchAll { + vin + year + make + model + trim + } +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_invalid_request_syntax.graphql b/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_invalid_request_syntax.graphql new file mode 100644 index 0000000000..98920eb17a --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_invalid_request_syntax.graphql @@ -0,0 +1,9 @@ +query { + searchByVin(vin: "error) { + vin + year + make + model + trim + } +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_unknown_operation.graphql b/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_unknown_operation.graphql new file mode 100644 index 0000000000..fb6c3d1039 --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/request/request_error_unknown_operation.graphql @@ -0,0 +1,9 @@ +subscription { + searchByVin(vin: "75024") { + vin + year + make + model + trim + } +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/response/field_error_request_non_null_fields_partial_response.json b/graphql/graphql-error-handling/src/test/resources/graphql/response/field_error_request_non_null_fields_partial_response.json new file mode 100644 index 0000000000..760190128e --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/response/field_error_request_non_null_fields_partial_response.json @@ -0,0 +1,34 @@ +{ + "data": { + "searchAll": [ + null, + { + "vin": "JTKKU4B41C1023346", + "year": 2012, + "make": "Toyota", + "model": "Scion", + "trim": "Xd" + }, + { + "vin": "1G1JC1444PZ215071", + "year": 2000, + "make": "Chevrolet", + "model": "CAVALIER VL", + "trim": "RS" + } + ] + }, + "errors": [ + { + "message": "Cannot return null for non-nullable type: 'String' within parent 'Vehicle' (/searchAll[0]/trim)", + "path": [ + "searchAll", + 0, + "trim" + ], + "errorType": "DataFetchingException", + "locations": null, + "extensions": null + } + ] +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_invalid_request_syntax.json b/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_invalid_request_syntax.json new file mode 100644 index 0000000000..2835b42133 --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_invalid_request_syntax.json @@ -0,0 +1,18 @@ +{ + "data": null, + "errors": [ + { + "message": "Invalid Syntax", + "locations": [ + { + "line": 5, + "column": 8, + "sourceName": null + } + ], + "errorType": "InvalidSyntax", + "path": null, + "extensions": null + } + ] +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_unknown_operation.json b/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_unknown_operation.json new file mode 100644 index 0000000000..b5872fc80f --- /dev/null +++ b/graphql/graphql-error-handling/src/test/resources/graphql/response/request_error_unknown_operation.json @@ -0,0 +1,18 @@ +{ + "data": null, + "errors": [ + { + "errorType": "OperationNotSupported", + "locations": [ + { + "line": 1, + "column": 1, + "sourceName": null + } + ], + "extensions": null, + "message": "Schema is not configured for subscriptions.", + "path": null + } + ] +} \ No newline at end of file diff --git a/graphql/graphql-error-handling/src/test/resources/init_script.sql b/graphql/graphql-error-handling/src/test/resources/init_script.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/graphql/graphql-java/pom.xml b/graphql/graphql-java/pom.xml index 5808dd17fb..068cb04ea8 100644 --- a/graphql/graphql-java/pom.xml +++ b/graphql/graphql-java/pom.xml @@ -36,6 +36,21 @@ graphql-java-annotations ${graphql-java-annotations.version} + + io.ratpack + ratpack-core + ${ratpack-core.version} + + + com.github.americanexpress.nodes + nodes + 0.5.0 + + + com.graphql-java + graphql-java + 11.0 + com.graphql-java graphql-java-tools @@ -95,6 +110,14 @@ ${mockserver-client-java.version} test + + + com.graphql-java + graphql-java-extended-scalars + ${graphql-java-extended-scalars.version} + + + @@ -133,6 +156,13 @@ false false true + + + JSON + java.util.Map + com.baeldung.graphqlreturnmap.ExtendedGraphQLScalarType + + @@ -154,6 +184,8 @@ 1.8 1.8 + 1.18 + 2022-04-06T00-10-27-a70541e - \ No newline at end of file + diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java b/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java index 8ba9fa25c5..f2ac792e80 100644 --- a/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java @@ -2,6 +2,7 @@ package com.baeldung.graphql.server; import com.baeldung.graphql.data.Book; import com.baeldung.graphql.data.BookRepository; +import com.baeldung.graphqlreturnmap.entity.Product; import com.coxautodev.graphql.tools.GraphQLQueryResolver; import java.util.List; @@ -18,4 +19,12 @@ public class GraphQLQuery implements GraphQLQueryResolver { return repository.getAllBooks(); } + public List getProducts(int pageSize, int pageNumber) { + return null; + } + + public Product getProduct(int id) { + return null; + } + } diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java new file mode 100644 index 0000000000..26ad0eef2c --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java @@ -0,0 +1,52 @@ +package com.baeldung.graphqlreturnmap; + +import com.baeldung.graphql.utils.SchemaUtils; +import com.baeldung.graphqlreturnmap.resolver.ProductResolver; +import com.baeldung.graphqlreturnmap.resolver.Query; +import com.coxautodev.graphql.tools.SchemaParser; +import graphql.ExecutionResult; +import graphql.GraphQL; +import graphql.scalars.ExtendedScalars; +import graphql.schema.GraphQLSchema; +import ratpack.handling.Context; +import ratpack.handling.Handler; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Logger; + +import static ratpack.jackson.Jackson.json; + +public class AppHandler implements Handler { + private static final Logger LOGGER = Logger.getLogger(AppHandler.class.getSimpleName()); + private GraphQL graphql; + + public AppHandler() throws Exception { + GraphQLSchema schema = SchemaParser.newParser() + .resolvers(new Query(), new ProductResolver()) + .scalars(ExtendedScalars.Json) + .file("schema.graphqls") + .build() + .makeExecutableSchema(); + graphql = GraphQL.newGraphQL(schema).build(); + } + + @Override + public void handle(Context context) throws Exception { + context.parse(Map.class) + .then(payload -> { + ExecutionResult executionResult = graphql.execute(payload.get(SchemaUtils.QUERY) + .toString(), null, this, Collections.emptyMap()); + Map result = new LinkedHashMap<>(); + if (executionResult.getErrors() + .isEmpty()) { + result.put(SchemaUtils.DATA, executionResult.getData()); + } else { + result.put(SchemaUtils.ERRORS, executionResult.getErrors()); + LOGGER.warning("Errors: " + executionResult.getErrors()); + } + context.render(json(result)); + }); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java new file mode 100644 index 0000000000..5cdc72b13d --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java @@ -0,0 +1,24 @@ +package com.baeldung.graphqlreturnmap; + +import graphql.language.ScalarTypeDefinition; +import graphql.schema.Coercing; +import graphql.schema.GraphQLDirective; +import graphql.schema.GraphQLScalarType; + +import java.util.List; + +public class ExtendedGraphQLScalarType extends GraphQLScalarType { + + public ExtendedGraphQLScalarType(){ + super("","",null); + + } + + public ExtendedGraphQLScalarType(String name, String description, Coercing coercing) { + super(name, description, coercing); + } + + public ExtendedGraphQLScalarType(String name, String description, Coercing coercing, List directives, ScalarTypeDefinition definition) { + super(name, description, coercing, directives, definition); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java new file mode 100644 index 0000000000..8717fcb722 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java @@ -0,0 +1,12 @@ +package com.baeldung.graphqlreturnmap; + +import ratpack.server.RatpackServer; + +public class GraphqlReturnMap { + + public static void main(String[] args) throws Exception { + final RatpackServer server = RatpackServer.of(s -> s.handlers(chain -> chain.post("product", new AppHandler()))); + server.start(); + } + +} \ No newline at end of file diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java new file mode 100644 index 0000000000..dd2766afa5 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java @@ -0,0 +1,46 @@ +package com.baeldung.graphqlreturnmap.entity; + +public class Attribute { + private String name; + private String description; + private String unit; + + public Attribute(String name, String description, String unit){ + this.name = name; + this.description = description; + this.unit = unit; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + @Override + public String toString() { + return "Attribute{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + ", unit='" + unit + '\'' + + '}'; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java new file mode 100644 index 0000000000..db39d763de --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java @@ -0,0 +1,48 @@ +package com.baeldung.graphqlreturnmap.entity; + + +import java.util.Map; + +public class Product { + private Integer id; + private String name; + private String description; + private Map attributes; + + + public Product(){ + + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java new file mode 100644 index 0000000000..bb7641143b --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java @@ -0,0 +1,30 @@ +package com.baeldung.graphqlreturnmap.model; + + +import com.baeldung.graphqlreturnmap.entity.Attribute; + +public class AttributeKeyValueModel { + private String key; + private Attribute value; + + public AttributeKeyValueModel(String key, Attribute value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Attribute getValue() { + return value; + } + + public void setValue(Attribute value) { + this.value = value; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java new file mode 100644 index 0000000000..c751efc183 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java @@ -0,0 +1,12 @@ +package com.baeldung.graphqlreturnmap.repository; + + +import com.baeldung.graphqlreturnmap.entity.Product; + +import java.util.List; + +public interface ProductRepository { + List getProducts(Integer pageSize, Integer pageNumber); + Product getProduct(Integer id); + +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java new file mode 100644 index 0000000000..466a2149f4 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java @@ -0,0 +1,43 @@ +package com.baeldung.graphqlreturnmap.repository.impl; + +import com.baeldung.graphqlreturnmap.entity.Attribute; +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.repository.ProductRepository; +import org.springframework.stereotype.Repository; + +import java.util.*; +import java.util.stream.Collectors; + +@Repository +public class ProductRepositoryImpl implements ProductRepository { + + private static List productList = new ArrayList<>(); + + public ProductRepositoryImpl() { + for (int i = 1; i <= 10; i++){ + Product product = new Product(); + product.setId(i); + product.setName(String.format("Product %d", i)); + product.setDescription(String.format("Product %d description", i)); + product.setAttributes(createAttributes(i)); + productList.add(product); + } + } + + private Map createAttributes(int i) { + Map attributeMap = new HashMap<>(); + attributeMap.put(String.format("attribute_%d",i), new Attribute(String.format("Attribute%d name",i),"This is custom attribute description","This is custom attribute unit")); + attributeMap.put("size", new Attribute((i & 1) == 0 ? "Small" : "Large","This is custom attribute description","This is custom attribute unit")); + return attributeMap; + } + + @Override + public List getProducts(Integer pageSize, Integer pageNumber) { + return productList.stream().skip(pageSize*pageNumber).limit(pageSize).collect(Collectors.toList()); + } + + @Override + public Product getProduct(Integer id) { + return productList.stream().filter(product -> product.getId().equals(id)).findFirst().orElse(null); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java new file mode 100644 index 0000000000..d9789ea0c6 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java @@ -0,0 +1,30 @@ +package com.baeldung.graphqlreturnmap.resolver; + +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.model.AttributeKeyValueModel; +import com.coxautodev.graphql.tools.GraphQLResolver; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.LinkedList; +import java.util.List; + +public class ProductResolver implements GraphQLResolver { + public ProductResolver(){ + } + + public List getAttribute_list(Product product){ + List attributeModelList = new LinkedList<>(); + product.getAttributes().forEach((key, val) -> attributeModelList.add(new AttributeKeyValueModel(key, val))); + return attributeModelList; + } + + public String getAttribute_string(Product product){ + try { + return new ObjectMapper().writeValueAsString(product.getAttributes()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return ""; + } + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java new file mode 100644 index 0000000000..cbcff6056b --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java @@ -0,0 +1,33 @@ +package com.baeldung.graphqlreturnmap.resolver; + +import com.baeldung.graphql.data.Book; +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.repository.ProductRepository; +import com.baeldung.graphqlreturnmap.repository.impl.ProductRepositoryImpl; +import com.coxautodev.graphql.tools.GraphQLQueryResolver; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class Query implements GraphQLQueryResolver { + + @Autowired + private ProductRepository productRepository; + public Query(){ + productRepository = new ProductRepositoryImpl(); + } + + public List getProducts(int pageSize, int pageNumber) { + return productRepository.getProducts(pageSize, pageNumber); + } + + public Product getProduct(int id) { + return productRepository.getProduct(id); + } + + public List allBooks() { + return null; + } + + +} diff --git a/graphql/graphql-java/src/main/resources/schema.graphqls b/graphql/graphql-java/src/main/resources/schema.graphqls index b0834e04b7..da10cd18bd 100644 --- a/graphql/graphql-java/src/main/resources/schema.graphqls +++ b/graphql/graphql-java/src/main/resources/schema.graphqls @@ -10,8 +10,34 @@ type Author { type Query { allBooks: [Book] + products(size: Int, page: Int): [Product]! + product(id: Int): Product! } + + +type Product { + id: ID + name: String! + description: String + attribute_string:String + attribute_list:[AttributeKeyValuePair] + attributes: JSON +} + +type AttributeKeyValuePair { + key:String + value:Attribute +} + +type Attribute { + name:String + description:String + unit:String +} +scalar JSON + + schema { query: Query } \ No newline at end of file diff --git a/jackson-modules/jackson-annotations/README.md b/jackson-modules/jackson-annotations/README.md index 783a06605b..3b6cd6f20b 100644 --- a/jackson-modules/jackson-annotations/README.md +++ b/jackson-modules/jackson-annotations/README.md @@ -7,3 +7,4 @@ This module contains articles about Jackson annotations. - [More Jackson Annotations](https://www.baeldung.com/jackson-advanced-annotations) - [Jackson – Bidirectional Relationships](https://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) - [Jackson JSON Views](https://www.baeldung.com/jackson-json-view-annotation) +- [Deduction-Based Polymorphism in Jackson 2.12](https://www.baeldung.com/jackson-deduction-based-polymorphism) diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Character.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Character.java new file mode 100644 index 0000000000..6be7483cc2 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Character.java @@ -0,0 +1,12 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; + +@JsonTypeInfo(use = Id.DEDUCTION) +@JsonSubTypes({ @Type(ImperialSpy.class), @Type(King.class), @Type(Knight.class) }) +public interface Character { + +} diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ControlledCharacter.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ControlledCharacter.java new file mode 100644 index 0000000000..9f6f03954e --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ControlledCharacter.java @@ -0,0 +1,14 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class ControlledCharacter { + + private Character character; + + public Character getCharacter() { + return character; + } + + public void setCharacter(Character character) { + this.character = character; + } +} diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ImperialSpy.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ImperialSpy.java new file mode 100644 index 0000000000..ff86966e38 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/ImperialSpy.java @@ -0,0 +1,5 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class ImperialSpy implements Character { + +} diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/King.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/King.java new file mode 100644 index 0000000000..3270d92b3a --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/King.java @@ -0,0 +1,14 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class King extends NamedCharacter { + + private String land; + + public String getLand() { + return land; + } + + public void setLand(String land) { + this.land = land; + } +} diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Knight.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Knight.java new file mode 100644 index 0000000000..197d3b758b --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/Knight.java @@ -0,0 +1,14 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class Knight extends NamedCharacter { + + private String weapon; + + public String getWeapon() { + return weapon; + } + + public void setWeapon(String weapon) { + this.weapon = weapon; + } +} diff --git a/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/NamedCharacter.java b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/NamedCharacter.java new file mode 100644 index 0000000000..15892f8659 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/main/java/com/baeldung/jackson/deductionbasedpolymorphism/NamedCharacter.java @@ -0,0 +1,14 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class NamedCharacter implements Character { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/CaseInsensitiveInferenceUnitTest.java b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/CaseInsensitiveInferenceUnitTest.java new file mode 100644 index 0000000000..cad9e73091 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/CaseInsensitiveInferenceUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +import static com.baeldung.jackson.deductionbasedpolymorphism.JsonStringFormatterUtil.formatJson; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; + +class CaseInsensitiveInferenceUnitTest { + + private final ObjectMapper objectMapper = JsonMapper.builder() + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) + .build(); + + @Test + void givenACaseInsensitiveKnight_whenMapping_thenExpectKnight() throws Exception { + String knightJson = formatJson("{'NaMe':'Ostrava, of Boletaria', 'WeaPON':'Rune Sword'}"); + + Character character = objectMapper.readValue(knightJson, Character.class); + + assertTrue(character instanceof Knight); + assertSame(character.getClass(), Knight.class); + Knight knight = (Knight) character; + assertEquals("Ostrava, of Boletaria", knight.getName()); + assertEquals("Rune Sword", knight.getWeapon()); + } + +} diff --git a/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/ContainedInferenceUnitTest.java b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/ContainedInferenceUnitTest.java new file mode 100644 index 0000000000..810051f2ab --- /dev/null +++ b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/ContainedInferenceUnitTest.java @@ -0,0 +1,73 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +import static com.baeldung.jackson.deductionbasedpolymorphism.JsonStringFormatterUtil.formatJson; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; + +class ContainedInferenceUnitTest { + + private final ObjectMapper objectMapper = JsonMapper.builder() + .build(); + + @Test + void givenAKnightControlledCharacter_whenMapping_thenExpectAControlledCharacterWithKnight() throws Exception { + String controlledCharacterJson = formatJson("{'character': {'name': 'Ostrava, of Boletaria', 'weapon': 'Rune Sword'}}"); + + ControlledCharacter controlledCharacter = objectMapper.readValue(controlledCharacterJson, ControlledCharacter.class); + Character character = controlledCharacter.getCharacter(); + + assertTrue(character instanceof Knight); + assertSame(character.getClass(), Knight.class); + Knight knight = (Knight) character; + assertEquals("Ostrava, of Boletaria", knight.getName()); + assertEquals("Rune Sword", knight.getWeapon()); + } + + @Test + void givenAKingControlledCharacter_whenMapping_thenExpectAControlledCharacterWithKing() throws Exception { + String controlledCharacterJson = formatJson("{'character': {'name': 'King Allant', 'land': 'Boletaria'}}"); + + ControlledCharacter controlledCharacter = objectMapper.readValue(controlledCharacterJson, ControlledCharacter.class); + Character character = controlledCharacter.getCharacter(); + + assertTrue(character instanceof King); + assertSame(character.getClass(), King.class); + King king = (King) character; + assertEquals("King Allant", king.getName()); + assertEquals("Boletaria", king.getLand()); + } + + @Test + void givenAnEmptySubtype_whenMapping_thenExpectImperialSpy() throws Exception { + String controlledCharacterJson = formatJson("{'character': {}}"); + + ControlledCharacter controlledCharacter = objectMapper.readValue(controlledCharacterJson, ControlledCharacter.class); + + assertTrue(controlledCharacter.getCharacter() instanceof ImperialSpy); + } + + @Test + void givenANullCharacter_whenMapping_thenExpectNullCharacter() throws Exception { + String controlledCharacterJson = formatJson("{'character': null}"); + + ControlledCharacter controlledCharacter = objectMapper.readValue(controlledCharacterJson, ControlledCharacter.class); + + assertNull(controlledCharacter.getCharacter()); + } + + @Test + void givenAAnAbsentCharacter_whenMapping_thenExpectNullCharacter() throws Exception { + String controlledCharacterJson = formatJson("{}"); + + ControlledCharacter controlledCharacter = objectMapper.readValue(controlledCharacterJson, ControlledCharacter.class); + + assertNull(controlledCharacter.getCharacter()); + } +} diff --git a/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/JsonStringFormatterUtil.java b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/JsonStringFormatterUtil.java new file mode 100644 index 0000000000..948b264c45 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/JsonStringFormatterUtil.java @@ -0,0 +1,9 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +public class JsonStringFormatterUtil { + + public static String formatJson(String input) { + return input.replaceAll("'", "\""); + } + +} diff --git a/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/SimpleInferenceUnitTest.java b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/SimpleInferenceUnitTest.java new file mode 100644 index 0000000000..5e63e95289 --- /dev/null +++ b/jackson-modules/jackson-annotations/src/test/java/com/baeldung/jackson/deductionbasedpolymorphism/SimpleInferenceUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.jackson.deductionbasedpolymorphism; + +import static com.baeldung.jackson.deductionbasedpolymorphism.JsonStringFormatterUtil.formatJson; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; + +class SimpleInferenceUnitTest { + + private final ObjectMapper objectMapper = JsonMapper.builder() + .build(); + + @Test + void givenAKnight_whenMapping_thenExpectAKnightType() throws Exception { + String knightJson = formatJson("{'name':'Ostrava, of Boletaria', 'weapon':'Rune Sword'}"); + + Character character = objectMapper.readValue(knightJson, Character.class); + + assertTrue(character instanceof Knight); + assertSame(character.getClass(), Knight.class); + Knight king = (Knight) character; + assertEquals("Ostrava, of Boletaria", king.getName()); + assertEquals("Rune Sword", king.getWeapon()); + } + + @Test + void givenAKing_whenMapping_thenExpectAKingType() throws Exception { + String kingJson = formatJson("{'name':'Old King Allant', 'land':'Boletaria'}"); + + Character character = objectMapper.readValue(kingJson, Character.class); + + assertTrue(character instanceof King); + assertSame(character.getClass(), King.class); + King king = (King) character; + assertEquals("Old King Allant", king.getName()); + assertEquals("Boletaria", king.getLand()); + } + + @Test + void givenAnEmptyObject_whenMapping_thenExpectAnImperialSpy() throws Exception { + String imperialSpyJson = "{}"; + + Character character = objectMapper.readValue(imperialSpyJson, Character.class); + + assertTrue(character instanceof ImperialSpy); + } + + @Test + void givenANullObject_whenMapping_thenExpectANullObject() throws Exception { + Character character = objectMapper.readValue("null", Character.class); + + assertNull(character); + } + +} diff --git a/java-numbers-4/README.md b/java-numbers-4/README.md index 95d46203ab..267639a829 100644 --- a/java-numbers-4/README.md +++ b/java-numbers-4/README.md @@ -6,3 +6,4 @@ - [Guide to Java BigInteger](https://www.baeldung.com/java-biginteger) - [Automorphic Numbers in Java](https://www.baeldung.com/java-automorphic-numbers) - [Convert Byte Size Into a Human-Readable Format in Java](https://www.baeldung.com/java-human-readable-byte-size) +- [Convert boolean to int in Java](https://www.baeldung.com/java-boolean-to-int) diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java index 94ce329ad0..64b645a1c6 100644 --- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java +++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java @@ -34,7 +34,7 @@ public class StocksResource { @Produces(MediaType.APPLICATION_JSON) public Response get(@PathParam("ticker") String id) { Optional stock = stocks.findById(id); - stock.orElseThrow(IllegalArgumentException::new); + stock.orElseThrow(() -> new IllegalArgumentException("ticker")); return Response.ok(stock.get()) .build(); diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java index a6e9cc7f39..adfac000e8 100644 --- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java +++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java @@ -7,7 +7,7 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.ext.ExceptionMapper; public class ServerExceptionMapper implements ExceptionMapper { - public static final String HTTP_405_MESSAGE = "METHOD_NOT_ALLOWED"; + public static final String HTTP_405_MESSAGE = "use one of"; @Override public Response toResponse(final WebApplicationException exception) { @@ -18,7 +18,7 @@ public class ServerExceptionMapper implements ExceptionMapper]](../libraries-4) diff --git a/persistence-modules/hibernate-exceptions/README.md b/persistence-modules/hibernate-exceptions/README.md index 2e5a98c2f8..c485de2f34 100644 --- a/persistence-modules/hibernate-exceptions/README.md +++ b/persistence-modules/hibernate-exceptions/README.md @@ -5,3 +5,4 @@ - [TransactionRequiredException Error](https://www.baeldung.com/jpa-transaction-required-exception) - [Hibernate’s “Object References an Unsaved Transient Instance” Error](https://www.baeldung.com/hibernate-unsaved-transient-instance-error) - [EntityNotFoundException in Hibernate](https://www.baeldung.com/hibernate-entitynotfoundexception) +- [Hibernate’s “Not-Null Property References a Null or Transient Value” Error](https://www.baeldung.com/hibernate-not-null-error) diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/HibernateUtil.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/HibernateUtil.java new file mode 100644 index 0000000000..641b80b412 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/HibernateUtil.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.exception.persistentobject; + +import java.util.Properties; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.exception.persistentobject.entity.Article; +import com.baeldung.hibernate.exception.persistentobject.entity.Author; +import com.baeldung.hibernate.exception.persistentobject.entity.Book; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + try { + Configuration configuration = new Configuration(); + Properties settings = new Properties(); + + settings.put(Environment.DRIVER, "org.hsqldb.jdbcDriver"); + settings.put(Environment.URL, "jdbc:hsqldb:mem:userrole"); + settings.put(Environment.USER, "sa"); + settings.put(Environment.PASS, ""); + settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect"); + settings.put(Environment.SHOW_SQL, "true"); + settings.put(Environment.HBM2DDL_AUTO, "update"); + settings.put(Environment.CHECK_NULLABILITY, "true"); + + configuration.setProperties(settings); + configuration.addAnnotatedClass(Book.class); + configuration.addAnnotatedClass(Author.class); + configuration.addAnnotatedClass(Article.class); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()).build(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + } catch (Exception e) { + e.printStackTrace(); + } + } + return sessionFactory; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Article.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Article.java new file mode 100644 index 0000000000..3c9c7c5b31 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Article.java @@ -0,0 +1,29 @@ +package com.baeldung.hibernate.exception.persistentobject.entity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Article { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String title; + + @ManyToOne(optional = false) + private Author author; + + public Article(String title) { + this.title = title; + } + + public void setAuthor(Author author) { + this.author = author; + } + +} diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Author.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Author.java new file mode 100644 index 0000000000..fa6aaa9abe --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Author.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.exception.persistentobject.entity; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +@Entity +public class Author { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String name; + + @OneToMany + @Cascade(CascadeType.ALL) + private List
articles; + + public Author(String name) { + this.name = name; + } + + public Author() { + } + + public List
getArticles() { + return articles; + } + + public void setArticles(List
articles) { + this.articles = articles; + } + + public void addArticles(List
articles) { + this.articles = articles; + articles.forEach(article -> article.setAuthor(this)); + } + +} diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Book.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Book.java new file mode 100644 index 0000000000..342da27c77 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/persistentobject/entity/Book.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.exception.persistentobject.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; + +@Entity +public class Book { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column(nullable = false) + private String title; + + public Book(String title) { + this.title = title; + } + + public Book() { + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/persistentobject/HibernatePersistentObjectUnitTest.java b/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/persistentobject/HibernatePersistentObjectUnitTest.java new file mode 100644 index 0000000000..09f11b07a2 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/persistentobject/HibernatePersistentObjectUnitTest.java @@ -0,0 +1,65 @@ +package com.baeldung.hibernate.exception.persistentobject; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.hibernate.PropertyValueException; +import org.hibernate.Session; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.exception.persistentobject.entity.Article; +import com.baeldung.hibernate.exception.persistentobject.entity.Author; +import com.baeldung.hibernate.exception.persistentobject.entity.Book; + +public class HibernatePersistentObjectUnitTest { + + private static Session session; + + @Before + public void beforeAll() { + session = HibernateUtil.getSessionFactory() + .openSession(); + session.beginTransaction(); + } + + @After + public void afterAll() { + session.close(); + } + + @Test + public void whenSavingEntityWithNullMandatoryField_thenThrowPropertyValueException() { + Book book = new Book(); + + assertThatThrownBy(() -> session.save(book)).isInstanceOf(PropertyValueException.class) + .hasMessageContaining("not-null property references a null or transient value"); + } + + @Test + public void whenSavingEntityWithAllMandatoryField_thenDoNotThrowException() { + Book book = new Book(); + book.setTitle("Clean Code"); + + session.save(book); + } + + @Test + public void whenSavingBidirectionalEntitiesWithoutSettingParent_thenThrowPropertyValueException() { + Author author = new Author("John Doe"); + author.setArticles(asList(new Article("Java Tutorial"), new Article("What's New in JUnit5"))); + + assertThatThrownBy(() -> session.save(author)).isInstanceOf(PropertyValueException.class) + .hasMessageContaining("not-null property references a null or transient value"); + } + + @Test + public void whenSavingBidirectionalEntitiesWithCorrectParent_thenDoNotThrowException() { + Author author = new Author("John Doe"); + author.addArticles(asList(new Article("Java tutorial"), new Article("What's new in JUnit5"))); + + session.save(author); + } + +} \ No newline at end of file diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java index 58724e690c..84b20197bd 100644 --- a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -13,6 +13,8 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.service.ServiceRegistry; import com.baeldung.hibernate.customtypes.LocalDateStringType; +import com.baeldung.hibernate.distinct.entities.Post; +import com.baeldung.hibernate.distinct.entities.Comment; import com.baeldung.hibernate.entities.DeptEmployee; import com.baeldung.hibernate.pojo.Student; @@ -41,6 +43,8 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(Student.class); metadataSources.addAnnotatedClass(DeptEmployee.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); + metadataSources.addAnnotatedClass(Comment.class); + metadataSources.addAnnotatedClass(Post.class); Metadata metadata = metadataSources.getMetadataBuilder() .applyBasicType(LocalDateStringType.INSTANCE) diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Comment.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Comment.java new file mode 100644 index 0000000000..1d155b112e --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Comment.java @@ -0,0 +1,28 @@ +package com.baeldung.hibernate.distinct.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Comment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String text; + + public Comment() { + } + + public Comment(String text) { + this.text = text; + } + + @Override + public String toString() { + return "Comment{" + "id=" + id + ", text='" + text + '\'' + '}'; + } +} diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Post.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Post.java new file mode 100644 index 0000000000..d2608e614c --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/distinct/entities/Post.java @@ -0,0 +1,59 @@ +package com.baeldung.hibernate.distinct.entities; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +@Entity +public class Post { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String title; + + @OneToMany + @Cascade(CascadeType.ALL) + private List comments; + + public Post() { + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public List getComments() { + return comments; + } + + public void setComments(List comments) { + this.comments = comments; + } + + @Override + public String toString() { + return "Post{" + "id=" + id + ", title='" + title + '\'' + ", comments=" + comments + '}'; + } +} diff --git a/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/distinct/entities/DistinctHqlQueriesUnitTest.java b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/distinct/entities/DistinctHqlQueriesUnitTest.java new file mode 100644 index 0000000000..799439a51b --- /dev/null +++ b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/distinct/entities/DistinctHqlQueriesUnitTest.java @@ -0,0 +1,80 @@ +package com.baeldung.hibernate.distinct.entities; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.annotations.QueryHints; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; + +public class DistinctHqlQueriesUnitTest { + + private Session session; + + @Before + public void setUp() throws IOException { + this.session = HibernateUtil.getSessionFactory() + .openSession(); + saveDummyData(); + } + + private void saveDummyData() { + Transaction trx = session.beginTransaction(); + session.createQuery("delete from Post") + .executeUpdate(); + + Post post = new Post(); + post.setTitle("Distinct Queries in HQL"); + post.setComments(Arrays.asList(new Comment("Great article!"), new Comment("Nice one :)"), new Comment("Keep up the good work!"))); + session.persist(post); + + trx.commit(); + } + + @After + public void tearDown() { + session.close(); + } + + @Test + public void whenExecutingSelectQuery_thereWillBeDuplicates() { + String hql = "SELECT p FROM Post p LEFT JOIN FETCH p.comments"; + List posts = session.createQuery(hql, Post.class) + .getResultList(); + + assertThat(posts).hasSize(3); + } + + @Test + public void whenExecutingSelectDistinctQuery_thereShouldBeNoDuplicates() { + String hql = "SELECT DISTINCT p FROM Post p LEFT JOIN FETCH p.comments"; + List posts = session.createQuery(hql, Post.class) + .getResultList(); + + assertThat(posts).hasSize(1) + .allMatch(post -> post.getTitle() + .equals("Distinct Queries in HQL") && post.getComments() + .size() == 3); + } + + @Test + public void whenExecutingSelectDistinctQueryWithHint_thereShouldBeNoDuplicates() { + String hql = "SELECT DISTINCT p FROM Post p LEFT JOIN FETCH p.comments"; + List posts = session.createQuery(hql, Post.class) + .setHint(QueryHints.PASS_DISTINCT_THROUGH, false) + .getResultList(); + + assertThat(posts).hasSize(1) + .allMatch(post -> post.getTitle() + .equals("Distinct Queries in HQL") && post.getComments() + .size() == 3); + } +} \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/ConnectionCheck.java b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/ConnectionCheck.java index 240e54ab99..df17e27351 100644 --- a/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/ConnectionCheck.java +++ b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/ConnectionCheck.java @@ -7,7 +7,7 @@ import com.mongodb.ServerAddress; public class ConnectionCheck { - public static void checkingConnection() { + public static MongoClient checkingConnection() { MongoClientOptions.Builder builder = MongoClientOptions.builder(); @@ -27,9 +27,10 @@ public class ConnectionCheck { System.out.println(db.getStats()); } catch (Exception e) { System.out.println("MongoDB Server is Down"); - mongoClient.close(); } + return mongoClient; + } public static void main(String[] args) { @@ -42,5 +43,4 @@ public class ConnectionCheck { } -} - +} \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/ConnectionCheckLiveTest.java b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/ConnectionCheckLiveTest.java index 69f356997c..32014a4473 100644 --- a/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/ConnectionCheckLiveTest.java +++ b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/ConnectionCheckLiveTest.java @@ -3,45 +3,22 @@ package com.baeldung.mongo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import java.io.IOException; - -import org.junit.BeforeClass; import org.junit.Test; +import com.baeldung.ConnectionCheck; import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.ServerAddress; public class ConnectionCheckLiveTest { - private static MongoClient mongoClient; - private static MongoClientOptions.Builder builder; - private static ServerAddress ServerAddress; - - @BeforeClass - public static void setup() throws IOException { - if (mongoClient == null) { - - builder = MongoClientOptions.builder(); - builder.connectionsPerHost(100); - builder.maxWaitTime(60000); - builder.connectTimeout(1500); - builder.socketTimeout(60000); - builder.socketKeepAlive(true); - - ServerAddress = new ServerAddress("localhost", 27017); - mongoClient = new MongoClient(ServerAddress, builder.build()); - - } - } + ConnectionCheck ConnectionCheck = new ConnectionCheck(); @Test public void givenMongoClient_whenConnectionCheck_thenCheckingForConnectionPoint() { + MongoClient mongoClient = ConnectionCheck.checkingConnection(); String connectionPoint = mongoClient.getConnectPoint(); assertNotNull(connectionPoint); assertFalse(connectionPoint.isEmpty()); } -} - +} \ No newline at end of file diff --git a/persistence-modules/java-mongodb/src/test/java/com/baeldung/bsontojson/BsonToJsonLiveTest.java b/persistence-modules/java-mongodb/src/test/java/com/baeldung/bsontojson/BsonToJsonLiveTest.java index 12053523f8..0548119d7a 100644 --- a/persistence-modules/java-mongodb/src/test/java/com/baeldung/bsontojson/BsonToJsonLiveTest.java +++ b/persistence-modules/java-mongodb/src/test/java/com/baeldung/bsontojson/BsonToJsonLiveTest.java @@ -21,7 +21,7 @@ import dev.morphia.Datastore; import dev.morphia.Morphia; public class BsonToJsonLiveTest { - + private static final String DB_NAME = "library"; private static Datastore datastore; @@ -31,17 +31,17 @@ public class BsonToJsonLiveTest { morphia.mapPackage("com.baeldung.bsontojson"); datastore = morphia.createDatastore(new MongoClient(), DB_NAME); datastore.ensureIndexes(); - + datastore.save(new Book() .setIsbn("isbn") .setTitle("title") .setAuthor("author") .setCost(3.95) .setPublisher(new Publisher(new ObjectId("fffffffffffffffffffffffa"),"publisher")) - .setPublishDate(LocalDateTime.parse("2020-01-01T18:13:32Z", DateTimeFormatter.ISO_DATE_TIME)) + .setPublishDate(LocalDateTime.parse("2020-01-01T17:13:32Z", DateTimeFormatter.ISO_DATE_TIME)) .addCompanionBooks(new Book().setIsbn("isbn2"))); } - + @AfterClass public static void tearDown() { datastore.delete(datastore.createQuery(Book.class)); @@ -50,32 +50,32 @@ public class BsonToJsonLiveTest { @Test public void givenBsonDocument_whenUsingStandardJsonTransformation_thenJsonDateIsObjectEpochTime() { - String json = null; + String json; try (MongoClient mongoClient = new MongoClient()) { MongoDatabase mongoDatabase = mongoClient.getDatabase(DB_NAME); Document bson = mongoDatabase.getCollection("Books").find().first(); json = bson.toJson(); } - - String expectedJson = "{\"_id\": \"isbn\", " + - "\"className\": \"com.baeldung.bsontojson.Book\", " + - "\"title\": \"title\", " + - "\"author\": \"author\", " + - "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + - "\"name\": \"publisher\"}, " + - "\"price\": 3.95, " + + + String expectedJson = "{\"_id\": \"isbn\", " + + "\"className\": \"com.baeldung.bsontojson.Book\", " + + "\"title\": \"title\", " + + "\"author\": \"author\", " + + "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + + "\"name\": \"publisher\"}, " + + "\"price\": 3.95, " + "\"publishDate\": {\"$date\": 1577898812000}}"; assertNotNull(json); - + assertEquals(expectedJson, json); } - + @Test public void givenBsonDocument_whenUsingRelaxedJsonTransformation_thenJsonDateIsObjectIsoDate() { - - String json = null; + + String json; try (MongoClient mongoClient = new MongoClient()) { MongoDatabase mongoDatabase = mongoClient.getDatabase(DB_NAME); Document bson = mongoDatabase.getCollection("Books").find().first(); @@ -84,25 +84,25 @@ public class BsonToJsonLiveTest { .outputMode(JsonMode.RELAXED) .build()); } - - String expectedJson = "{\"_id\": \"isbn\", " + - "\"className\": \"com.baeldung.bsontojson.Book\", " + - "\"title\": \"title\", " + - "\"author\": \"author\", " + - "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + - "\"name\": \"publisher\"}, " + - "\"price\": 3.95, " + + + String expectedJson = "{\"_id\": \"isbn\", " + + "\"className\": \"com.baeldung.bsontojson.Book\", " + + "\"title\": \"title\", " + + "\"author\": \"author\", " + + "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + + "\"name\": \"publisher\"}, " + + "\"price\": 3.95, " + "\"publishDate\": {\"$date\": \"2020-01-01T17:13:32Z\"}}"; assertNotNull(json); - + assertEquals(expectedJson, json); } - + @Test public void givenBsonDocument_whenUsingCustomJsonTransformation_thenJsonDateIsStringField() { - String json = null; + String json; try (MongoClient mongoClient = new MongoClient()) { MongoDatabase mongoDatabase = mongoClient.getDatabase(DB_NAME); Document bson = mongoDatabase.getCollection("Books").find().first(); @@ -112,13 +112,13 @@ public class BsonToJsonLiveTest { .build()); } - String expectedJson = "{\"_id\": \"isbn\", " + - "\"className\": \"com.baeldung.bsontojson.Book\", " + - "\"title\": \"title\", " + - "\"author\": \"author\", " + - "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + - "\"name\": \"publisher\"}, " + - "\"price\": 3.95, " + + String expectedJson = "{\"_id\": \"isbn\", " + + "\"className\": \"com.baeldung.bsontojson.Book\", " + + "\"title\": \"title\", " + + "\"author\": \"author\", " + + "\"publisher\": {\"_id\": {\"$oid\": \"fffffffffffffffffffffffa\"}, " + + "\"name\": \"publisher\"}, " + + "\"price\": 3.95, " + "\"publishDate\": \"2020-01-01T17:13:32Z\"}"; assertEquals(expectedJson, json); diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java index eec15c5e56..ac79653b2b 100644 --- a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java @@ -13,6 +13,9 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedStoredProcedureQuery; +import javax.persistence.ParameterMode; +import javax.persistence.StoredProcedureParameter; import org.hibernate.envers.Audited; @@ -20,6 +23,20 @@ import org.hibernate.envers.Audited; @NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class), @NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class) }) +@NamedStoredProcedureQuery( + name="GetAllFoos", + procedureName="GetAllFoos", + resultClasses = { Foo.class } + ) +@NamedStoredProcedureQuery( + name="GetFoosByName", + procedureName="GetFoosByName", + resultClasses = { Foo.class }, + parameters={ + @StoredProcedureParameter(name="fooName", type=String.class, mode=ParameterMode.IN) + } + ) + @Entity @Audited // @Proxy(lazy = false) diff --git a/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java index 8bf33c4110..f6dedfc6de 100644 --- a/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java +++ b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java @@ -1,10 +1,14 @@ package com.baeldung.persistence.service; -import java.util.List; - import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.junit.Assert.assertEquals; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.StoredProcedureQuery; + import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -17,6 +21,7 @@ import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -38,8 +43,15 @@ public class FooStoredProceduresLiveTest { private Session session; + @Autowired + @Qualifier("jpaEntityManager") + private EntityManagerFactory entityManagerFactory; + + private EntityManager entityManager; + @Before public final void before() { + entityManager = entityManagerFactory.createEntityManager(); session = sessionFactory.openSession(); Assume.assumeTrue(getAllFoosExists()); Assume.assumeTrue(getFoosByNameExists()); @@ -70,6 +82,7 @@ public class FooStoredProceduresLiveTest { @After public final void after() { session.close(); + entityManager.close(); } @Test @@ -94,6 +107,15 @@ public class FooStoredProceduresLiveTest { LOGGER.info("getAllFoos() NamedQuery result : {}", foo.getName()); } assertEquals(allFoos2.size(), fooService.findAll().size()); + + StoredProcedureQuery spQuery = + entityManager.createNamedStoredProcedureQuery("GetAllFoos"); + List allFoos3 = spQuery.getResultList(); + for (Foo foo : allFoos3) { + LOGGER.info("getAllFoos() StoredProcedureQuery result : {}", foo.getName()); + } + assertEquals(allFoos3.size(), fooService.findAll().size()); + } @Test @@ -116,6 +138,15 @@ public class FooStoredProceduresLiveTest { for (Foo foo : allFoosByName2) { LOGGER.info("getFoosByName() using Native Query : found => {}", foo.toString()); } - + + StoredProcedureQuery spQuery = entityManager. + createNamedStoredProcedureQuery("GetFoosByName") + .setParameter("fooName", "NewFooName"); + List allFoosByName3 = spQuery.getResultList(); + assertEquals(1, allFoosByName3.size()); + for (Foo foo : allFoosByName3) { + LOGGER.info("getFoosByName() using StoredProcedureQuery : found => {}", foo.toString()); + assertEquals("NewFooName", foo.getName()); + } } } diff --git a/pom.xml b/pom.xml index 21589f5525..25aeebef9d 100644 --- a/pom.xml +++ b/pom.xml @@ -366,11 +366,8 @@ atomix - aws - aws-app-sync - aws-lambda - aws-reactive - + aws-modules + axon azure @@ -428,7 +425,7 @@ hazelcast helidon - httpclient + apache-httpclient httpclient-simple hystrix @@ -850,11 +847,8 @@ atomix - aws - aws-app-sync - aws-lambda - aws-reactive - + aws-modules + axon azure @@ -912,7 +906,7 @@ hazelcast helidon - httpclient + apache-httpclient httpclient-simple hystrix @@ -1346,7 +1340,7 @@ core-java-modules/core-java-strings ddd-modules docker - httpclient-2 + apache-httpclient-2 libraries-concurrency persistence-modules/sirix persistence-modules/spring-data-cassandra-2 @@ -1413,7 +1407,7 @@ core-java-modules/core-java-strings ddd-modules docker - httpclient-2 + apache-httpclient-2 libraries-concurrency persistence-modules/sirix persistence-modules/spring-data-cassandra-2 diff --git a/rule-engines/jess/pom.xml b/rule-engines/jess/pom.xml index f5db0374ef..be26d54a1e 100644 --- a/rule-engines/jess/pom.xml +++ b/rule-engines/jess/pom.xml @@ -7,18 +7,28 @@ jess 1.0-SNAPSHOT - jsr94 jsr94 1.1 + + + + + wso2 + Numerical Method's Maven Repository + http://dist.wso2.org/maven2/ + + + \ No newline at end of file diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index fabd54aa92..939add1147 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -16,8 +16,7 @@ ../parent-boot-2 - - spring-boot + spring-boot-1 spring-boot-2 spring-boot-admin @@ -56,6 +55,7 @@ spring-boot-mvc spring-boot-mvc-2 spring-boot-mvc-3 + spring-boot-mvc-4 spring-boot-mvc-birt spring-boot-mvc-jersey spring-boot-nashorn @@ -64,6 +64,7 @@ spring-boot-properties spring-boot-properties-2 spring-boot-properties-3 + spring-boot-properties-migrator-demo spring-boot-property-exp spring-boot-runtime spring-boot-runtime-2 diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/customer.html b/spring-boot-modules/spring-boot-1/src/main/resources/templates/customer.html similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/templates/customer.html rename to spring-boot-modules/spring-boot-1/src/main/resources/templates/customer.html diff --git a/spring-boot-modules/spring-boot-basic-customization-2/README.md b/spring-boot-modules/spring-boot-basic-customization-2/README.md index 9488618ca5..bfd24a0475 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/README.md +++ b/spring-boot-modules/spring-boot-basic-customization-2/README.md @@ -8,3 +8,5 @@ This module contains articles about Spring Boot customization 2 - [XML Defined Beans in Spring Boot](https://www.baeldung.com/spring-boot-xml-beans) - [What Is OncePerRequestFilter?](https://www.baeldung.com/spring-onceperrequestfilter) - [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes) + - [Guide to Spring Type Conversions](https://www.baeldung.com/spring-type-conversions) + - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) \ No newline at end of file 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 b615947de7..b537f43c23 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization-2/pom.xml @@ -19,10 +19,23 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + org.springframework.boot spring-boot-starter-test + + com.google.guava + guava + ${guava.version} + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/container/CustomContainer.java similarity index 93% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/container/CustomContainer.java index aaa3188010..6ebd4d5c62 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/container/CustomContainer.java @@ -1,4 +1,4 @@ -package com.baeldung.rss; +package com.baeldung.container; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/Application.java similarity index 91% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/Application.java index cb0d0c1532..1313032bbe 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/Application.java @@ -1,4 +1,4 @@ -package com.baeldung.boot; +package com.baeldung.typeconversion; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/config/WebConfig.java similarity index 67% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/config/WebConfig.java index b23c910a04..bad84edf88 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/config/WebConfig.java @@ -1,12 +1,13 @@ -package com.baeldung.boot.config; +package com.baeldung.typeconversion.config; -import com.baeldung.boot.converter.StringToEmployeeConverter; -import com.baeldung.boot.converter.StringToEnumConverterFactory; -import com.baeldung.boot.converter.GenericBigDecimalConverter; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import com.baeldung.typeconversion.converter.GenericBigDecimalConverter; +import com.baeldung.typeconversion.converter.StringToEmployeeConverter; +import com.baeldung.typeconversion.converter.StringToEnumConverterFactory; + @Configuration public class WebConfig implements WebMvcConfigurer { diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/GenericBigDecimalConverter.java similarity index 96% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/GenericBigDecimalConverter.java index fc73cfee5f..440ffba5ee 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/GenericBigDecimalConverter.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.converter; +package com.baeldung.typeconversion.converter; import com.google.common.collect.ImmutableSet; import org.springframework.core.convert.TypeDescriptor; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEmployeeConverter.java similarity index 76% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEmployeeConverter.java index ac635532ea..9703ed2514 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEmployeeConverter.java @@ -1,8 +1,8 @@ -package com.baeldung.boot.converter; +package com.baeldung.typeconversion.converter; import org.springframework.core.convert.converter.Converter; -import com.baeldung.toggle.Employee; +import com.baeldung.typeconversion.entity.Employee; public class StringToEmployeeConverter implements Converter { diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEnumConverterFactory.java similarity index 94% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEnumConverterFactory.java index a2dce11a6a..dc15f83d6d 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/StringToEnumConverterFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.converter; +package com.baeldung.typeconversion.converter; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterController.java similarity index 81% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterController.java index 260b1c734b..5c3f93f346 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterController.java @@ -1,11 +1,11 @@ -package com.baeldung.boot.converter.controller; +package com.baeldung.typeconversion.converter.controller; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.toggle.Employee; +import com.baeldung.typeconversion.entity.Employee; @RestController public class StringToEmployeeConverterController { diff --git a/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/domain/Modes.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/domain/Modes.java new file mode 100644 index 0000000000..d905faacac --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/domain/Modes.java @@ -0,0 +1,6 @@ +package com.baeldung.typeconversion.domain; + +public enum Modes { + + ALPHA, BETA; +} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/toggle/Employee.java b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/entity/Employee.java similarity index 92% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/toggle/Employee.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/entity/Employee.java index 64a8b3ce5b..e1897de877 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/toggle/Employee.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/main/java/com/baeldung/typeconversion/entity/Employee.java @@ -1,4 +1,4 @@ -package com.baeldung.toggle; +package com.baeldung.typeconversion.entity; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java b/spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/CustomConverterIntegrationTest.java similarity index 90% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/CustomConverterIntegrationTest.java index 4619964783..3e12e3c58d 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/CustomConverterIntegrationTest.java @@ -1,9 +1,9 @@ -package com.baeldung.converter; +package com.baeldung.typeconversion.converter; -import com.baeldung.toggle.Employee; +import com.baeldung.typeconversion.Application; +import com.baeldung.typeconversion.domain.Modes; +import com.baeldung.typeconversion.entity.Employee; -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.Modes; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java b/spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java similarity index 92% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java index 52dc542ebf..8632eebda3 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java +++ b/spring-boot-modules/spring-boot-basic-customization-2/src/test/java/com/baeldung/typeconversion/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.converter.controller; +package com.baeldung.typeconversion.converter.controller; import org.junit.Test; import org.junit.runner.RunWith; @@ -8,14 +8,14 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; +import com.baeldung.typeconversion.Application; + import static org.hamcrest.CoreMatchers.is; 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.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.baeldung.boot.Application; - @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = Application.class) @AutoConfigureMockMvc diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/DemoApplication.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/DemoApplication.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/DemoApplication.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/components/FooService.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/components/FooService.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/components/FooService.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/components/FooService.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/CommonException.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/exceptions/CommonException.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/CommonException.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/exceptions/CommonException.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/model/Foo.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/model/Foo.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/model/Foo.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/model/Foo.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/repository/FooRepository.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/repository/FooRepository.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/repository/FooRepository.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/repository/FooRepository.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/service/FooController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/service/FooController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/service/FooController.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/demo/service/FooController.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/Application.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/Application.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/Application.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/Application.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepository.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/repository/FooRepository.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepository.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/repository/FooRepository.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java rename to spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java similarity index 99% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java rename to spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java index 462291e0ac..88ff8c75f1 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java @@ -1,12 +1,13 @@ package com.baeldung.boot; -import com.baeldung.session.exception.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.session.exception.Application; + @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) @TestPropertySource("classpath:exception.properties") diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java similarity index 94% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java rename to spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java index 1772739d20..9de1f56af0 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java @@ -1,6 +1,6 @@ package com.baeldung.boot.repository; -import com.baeldung.boot.DemoApplicationIntegrationTest; +import com.baeldung.demo.DemoApplicationIntegrationTest; import com.baeldung.demo.model.Foo; import com.baeldung.demo.repository.FooRepository; import org.junit.Before; diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java similarity index 94% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java rename to spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java index 2fe072bb67..63b4734cf0 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java @@ -1,6 +1,6 @@ package com.baeldung.boot.repository; -import com.baeldung.boot.DemoApplicationIntegrationTest; +import com.baeldung.demo.DemoApplicationIntegrationTest; import com.baeldung.demo.model.Foo; import com.baeldung.demo.repository.FooRepository; import org.junit.Test; diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java similarity index 99% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java rename to spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java index 2e3326e6b1..ae20b15cb3 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java @@ -3,6 +3,7 @@ package com.baeldung.boot.repository; import com.baeldung.boot.ApplicationIntegrationTest; import com.baeldung.demo.model.Foo; import com.baeldung.session.exception.repository.FooRepository; + import org.hibernate.HibernateException; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/demo/DemoApplicationIntegrationTest.java similarity index 95% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java rename to spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/demo/DemoApplicationIntegrationTest.java index aaf4f1f780..3d72ec0140 100644 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/demo/DemoApplicationIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.boot; +package com.baeldung.demo; import com.baeldung.demo.DemoApplication; import org.junit.Test; diff --git a/spring-boot-modules/spring-boot/src/test/resources/exception-hibernate.properties b/spring-boot-modules/spring-boot-crud/src/test/resources/exception-hibernate.properties similarity index 100% rename from spring-boot-modules/spring-boot/src/test/resources/exception-hibernate.properties rename to spring-boot-modules/spring-boot-crud/src/test/resources/exception-hibernate.properties diff --git a/spring-boot-modules/spring-boot/src/test/resources/exception.properties b/spring-boot-modules/spring-boot-crud/src/test/resources/exception.properties similarity index 100% rename from spring-boot-modules/spring-boot/src/test/resources/exception.properties rename to spring-boot-modules/spring-boot-crud/src/test/resources/exception.properties diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/displayallbeans.html b/spring-boot-modules/spring-boot-di/src/main/resources/templates/displayallbeans.html similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/templates/displayallbeans.html rename to spring-boot-modules/spring-boot-di/src/main/resources/templates/displayallbeans.html diff --git a/spring-boot-modules/spring-boot-mvc-3/README.md b/spring-boot-modules/spring-boot-mvc-3/README.md index fa24ac11ed..e4b0a73bda 100644 --- a/spring-boot-modules/spring-boot-mvc-3/README.md +++ b/spring-boot-modules/spring-boot-mvc-3/README.md @@ -11,4 +11,4 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [CharacterEncodingFilter In SpringBoot](https://www.baeldung.com/spring-boot-characterencodingfilter) - [HandlerInterceptors vs. Filters in Spring MVC](https://www.baeldung.com/spring-mvc-handlerinterceptor-vs-filter) - [ETags for REST with Spring](https://www.baeldung.com/etags-for-rest-with-spring) -- More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc-2) +- More articles: [[<-- Prev]](/spring-boot-modules/spring-boot-mvc-2)[[Next -->]](/spring-boot-modules/spring-boot-mvc-4) diff --git a/spring-boot-modules/spring-boot-mvc-4/README.md b/spring-boot-modules/spring-boot-mvc-4/README.md index 651453c6d4..c6820ce930 100644 --- a/spring-boot-modules/spring-boot-mvc-4/README.md +++ b/spring-boot-modules/spring-boot-mvc-4/README.md @@ -2,3 +2,9 @@ This module contains articles about Spring Web MVC in Spring Boot projects. +### Relevant Articles: + +- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) +- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) +- [Configure a Spring Boot Web Application](https://www.baeldung.com/spring-boot-application-configuration) +- [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) diff --git a/spring-boot-modules/spring-boot-mvc-4/pom.xml b/spring-boot-modules/spring-boot-mvc-4/pom.xml index edf6185259..5b58b326ab 100644 --- a/spring-boot-modules/spring-boot-mvc-4/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-4/pom.xml @@ -2,24 +2,28 @@ + 4.0.0 spring-boot-mvc-4 spring-boot-mvc-4 jar - Module For Spring Boot - + Module For Spring Boot MVC Web + com.baeldung.spring-boot-modules spring-boot-modules 1.0.0-SNAPSHOT - org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-starter-validation @@ -38,6 +42,19 @@ com.fasterxml.jackson.core jackson-databind + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + + + commons-io + commons-io + ${commons-io.version} + diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/MyCustomErrorController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/MyCustomErrorController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/MyCustomErrorController.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/MyCustomErrorController.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/controller/ErrorController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/controller/ErrorController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/controller/ErrorController.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/controller/ErrorController.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/main/SpringBootApplication.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/main/SpringBootApplication.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/ApplicationMain.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/ApplicationMain.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/Constants.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/Constants.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/Constants.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/Constants.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/PropertyLoader.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/PropertyLoader.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/PropertyLoader.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/PropertyLoader.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/PropertySourcesLoader.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/PropertySourcesLoader.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/props/PropertySourcesLoader.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/props/PropertySourcesLoader.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java diff --git a/spring-boot-modules/spring-boot/src/main/resources/application.properties b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/application.properties similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/application.properties rename to spring-boot-modules/spring-boot-mvc-4/src/main/resources/application.properties diff --git a/spring-boot-modules/spring-boot/src/main/resources/custom.properties b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/custom.properties similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/custom.properties rename to spring-boot-modules/spring-boot-mvc-4/src/main/resources/custom.properties diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/resources/logback.xml b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/shutdown/shutdown.bat b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/shutdown/shutdown.bat similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/shutdown/shutdown.bat rename to spring-boot-modules/spring-boot-mvc-4/src/main/resources/shutdown/shutdown.bat diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/other.html b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/templates/other.html similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/templates/other.html rename to spring-boot-modules/spring-boot-mvc-4/src/main/resources/templates/other.html diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/utils.html b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/templates/utils.html similarity index 100% rename from spring-boot-modules/spring-boot/src/main/resources/templates/utils.html rename to spring-boot-modules/spring-boot-mvc-4/src/main/resources/templates/utils.html diff --git a/spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/context.xml b/spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/context.xml similarity index 100% rename from spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/context.xml rename to spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/context.xml diff --git a/spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/dispatcher.xml b/spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/dispatcher.xml similarity index 100% rename from spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/dispatcher.xml rename to spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/dispatcher.xml diff --git a/spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/web.xml b/spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-boot-modules/spring-boot/src/main/webapp/WEB-INF/web.xml rename to spring-boot-modules/spring-boot-mvc-4/src/main/webapp/WEB-INF/web.xml diff --git a/spring-boot-modules/spring-boot/src/main/webapp/annotationservlet.jsp b/spring-boot-modules/spring-boot-mvc-4/src/main/webapp/annotationservlet.jsp similarity index 100% rename from spring-boot-modules/spring-boot/src/main/webapp/annotationservlet.jsp rename to spring-boot-modules/spring-boot-mvc-4/src/main/webapp/annotationservlet.jsp diff --git a/spring-boot-modules/spring-boot/src/main/webapp/index.jsp b/spring-boot-modules/spring-boot-mvc-4/src/main/webapp/index.jsp similarity index 100% rename from spring-boot-modules/spring-boot/src/main/webapp/index.jsp rename to spring-boot-modules/spring-boot-mvc-4/src/main/webapp/index.jsp diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties-migrator-demo/README.md b/spring-boot-modules/spring-boot-properties-migrator-demo/README.md new file mode 100644 index 0000000000..c00eae2681 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/README.md @@ -0,0 +1,3 @@ + +### Relevant Articles: +- [Spring Boot Configuration Properties Migrator](https://www.baeldung.com/spring-boot-properties-migrator) diff --git a/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml b/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml new file mode 100644 index 0000000000..d44a8ce6f1 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + spring-boot-properties-migrator-demo + 1.0-SNAPSHOT + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../pom.xml + + + + + + + + + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-properties-migrator + runtime + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/App.java b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/java/com/baeldung/spring/boot/properties/migrator/Main.java similarity index 61% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/App.java rename to spring-boot-modules/spring-boot-properties-migrator-demo/src/main/java/com/baeldung/spring/boot/properties/migrator/Main.java index 77cdf4ddb9..848b9680a0 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/App.java +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/java/com/baeldung/spring/boot/properties/migrator/Main.java @@ -1,11 +1,11 @@ -package com.baeldung.intro; +package com.baeldung.spring.boot.properties.migrator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class App { +public class Main { public static void main(String[] args) { - SpringApplication.run(App.class, args); + SpringApplication.run(Main.class, args); } } diff --git a/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application-dev.yaml b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application-dev.yaml new file mode 100644 index 0000000000..6eadac798b --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application-dev.yaml @@ -0,0 +1,16 @@ +# Deprecated Properties for Demonstration +#spring: +# resources: +# cache: +# period: 31536000 +# chain: +# compressed: true +# html-application-cache: true + +spring: + web: + resources: + cache: + period: 31536000 + chain: + compressed: false diff --git a/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..15199b7710 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/src/main/resources/application.properties @@ -0,0 +1,7 @@ +# Deprecated Properties for Demonstration +#spring.resources.cache.period=31536000 +#spring.resources.chain.compressed=false +#spring.resources.chain.html-application-cache=false +spring.web.resources.cache.period=31536000 +spring.web.resources.chain.compressed=false +banner.image.location="myBanner.txt" diff --git a/spring-boot-modules/spring-boot-validation/README.md b/spring-boot-modules/spring-boot-validation/README.md index 8c3c8b9305..93b6e7d2d1 100644 --- a/spring-boot-modules/spring-boot-validation/README.md +++ b/spring-boot-modules/spring-boot-validation/README.md @@ -1,3 +1,4 @@ ### Relevant Articles - [Spring Validation in the Service Layer](https://www.baeldung.com/spring-service-layer-validation) +- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) diff --git a/spring-boot-modules/spring-boot-validation/pom.xml b/spring-boot-modules/spring-boot-validation/pom.xml index fa4e8439e6..639a62059d 100644 --- a/spring-boot-modules/spring-boot-validation/pom.xml +++ b/spring-boot-modules/spring-boot-validation/pom.xml @@ -22,6 +22,14 @@ org.hibernate.validator hibernate-validator + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/Application.java b/spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/Application.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/Application.java rename to spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/Application.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/controllers/UserController.java b/spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/controllers/UserController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/controllers/UserController.java rename to spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/controllers/UserController.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/entities/User.java b/spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/entities/User.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/entities/User.java rename to spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/entities/User.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/repositories/UserRepository.java b/spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/repositories/UserRepository.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/beanvalidation/application/repositories/UserRepository.java rename to spring-boot-modules/spring-boot-validation/src/main/java/com/baeldung/beanvalidation/application/repositories/UserRepository.java diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java b/spring-boot-modules/spring-boot-validation/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-validation/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java diff --git a/spring-boot-modules/spring-boot/.gitignore b/spring-boot-modules/spring-boot/.gitignore deleted file mode 100644 index da7c2c5c0a..0000000000 --- a/spring-boot-modules/spring-boot/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/target/ -.settings/ -.classpath -.project - diff --git a/spring-boot-modules/spring-boot/.mvn/wrapper/maven-wrapper.properties b/spring-boot-modules/spring-boot/.mvn/wrapper/maven-wrapper.properties deleted file mode 100755 index a447c9fa81..0000000000 --- a/spring-boot-modules/spring-boot/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/README.md b/spring-boot-modules/spring-boot/README.md deleted file mode 100644 index fdc8093806..0000000000 --- a/spring-boot-modules/spring-boot/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Spring Boot - -This module contains articles about Spring Boot - -### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring - -### Relevant Articles: - -- [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) -- [Guide to Spring Type Conversions](https://www.baeldung.com/spring-type-conversions) -- [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) -- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) -- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) -- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) -- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) diff --git a/spring-boot-modules/spring-boot/mvnw b/spring-boot-modules/spring-boot/mvnw deleted file mode 100755 index e96ccd5fbb..0000000000 --- a/spring-boot-modules/spring-boot/mvnw +++ /dev/null @@ -1,227 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/spring-boot-modules/spring-boot/mvnw.cmd b/spring-boot-modules/spring-boot/mvnw.cmd deleted file mode 100755 index 6a6eec39ba..0000000000 --- a/spring-boot-modules/spring-boot/mvnw.cmd +++ /dev/null @@ -1,145 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/spring-boot-modules/spring-boot/pom.xml b/spring-boot-modules/spring-boot/pom.xml deleted file mode 100644 index 3afccef925..0000000000 --- a/spring-boot-modules/spring-boot/pom.xml +++ /dev/null @@ -1,166 +0,0 @@ - - - 4.0.0 - spring-boot - 0.0.1-SNAPSHOT - spring-boot - war - This is simple boot application for Spring boot actuator test - - - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.ehcache - ehcache - - - org.hibernate - hibernate-ehcache - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-test - test - - - io.dropwizard.metrics - metrics-core - - - com.h2database - h2 - - - org.springframework.boot - spring-boot-starter - - - com.jayway.jsonpath - json-path - test - - - com.google.guava - guava - ${guava.version} - - - org.apache.tomcat - tomcat-servlet-api - ${tomee-servlet-api.version} - provided - - - org.apache.activemq - artemis-server - - - com.rometools - rome - ${rome.version} - - - - - spring-boot - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-war-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - @ - - false - - - - - - - - autoconfiguration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - **/*IntegrationTest.java - **/*IntTest.java - - - **/AutoconfigurationTest.java - - - - - - - json - - - - - - - - - - - com.baeldung.intro.App - 8.5.11 - 1.9.0 - @ - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java deleted file mode 100644 index 928928c9a5..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.boot.config; - -import java.util.Properties; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@Configuration -@EnableJpaRepositories(basePackages = { "com.baeldung.boot.repository", "com.baeldung.boot.boottest", "com.baeldung.repository" }) -@PropertySource("classpath:persistence-generic-entity.properties") -@EnableTransactionManagement -public class H2JpaConfig { - - @Autowired - private Environment env; - - @Bean - public DataSource dataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); - dataSource.setUrl(env.getProperty("jdbc.url")); - dataSource.setUsername(env.getProperty("jdbc.user")); - dataSource.setPassword(env.getProperty("jdbc.pass")); - - return dataSource; - } - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.boot.domain", "com.baeldung.boot.model", "com.baeldung.boot.boottest", "com.baeldung.model" }); - em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); - em.setJpaProperties(additionalProperties()); - return em; - } - - @Bean - JpaTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory); - return transactionManager; - } - - final Properties additionalProperties() { - final Properties hibernateProperties = new Properties(); - - hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); - - return hibernateProperties; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java deleted file mode 100644 index 7717294996..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.boot.domain; - -public enum Modes { - - ALPHA, BETA; -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/Application.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/Application.java deleted file mode 100644 index 405cec3eac..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/Application.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.buildproperties; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.buildproperties") -@PropertySource("classpath:build.properties") -//@PropertySource("classpath:build.yml") -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/BuildInfoService.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/BuildInfoService.java deleted file mode 100644 index 2a0d27188e..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/buildproperties/BuildInfoService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.buildproperties; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -@Service -public class BuildInfoService { - @Value("${application-description}") - private String applicationDescription; - - @Value("${application-version}") - private String applicationVersion; - - public String getApplicationDescription() { - return applicationDescription; - } - - public String getApplicationVersion() { - return applicationVersion; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java deleted file mode 100644 index 4797d6e593..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.intro.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class HomeController { - - @GetMapping("/") - public String root() { - return "Index Page"; - } - - @GetMapping("/local") - public String local() { - return "/local"; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/Contact.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/Contact.java deleted file mode 100644 index f131d17196..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/Contact.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -public class Contact { - - private String name; - private String address; - private String phone; - - @JsonFormat(pattern="yyyy-MM-dd") - private LocalDate birthday; - - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") - private LocalDateTime lastUpdate; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public LocalDate getBirthday() { - return birthday; - } - - public void setBirthday(LocalDate birthday) { - this.birthday = birthday; - } - - public LocalDateTime getLastUpdate() { - return lastUpdate; - } - - public void setLastUpdate(LocalDateTime lastUpdate) { - this.lastUpdate = lastUpdate; - } - - public Contact() { - } - - public Contact(String name, String address, String phone, LocalDate birthday, LocalDateTime lastUpdate) { - this.name = name; - this.address = address; - this.phone = phone; - this.birthday = birthday; - this.lastUpdate = lastUpdate; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactAppConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactAppConfig.java deleted file mode 100644 index 7a20ebfa51..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactAppConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; - -import java.time.format.DateTimeFormatter; - -@Configuration -public class ContactAppConfig { - - private static final String dateFormat = "yyyy-MM-dd"; - - private static final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; - - @Bean - @ConditionalOnProperty(value = "spring.jackson.date-format", matchIfMissing = true, havingValue = "none") - public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { - return new Jackson2ObjectMapperBuilderCustomizer() { - @Override - public void customize(Jackson2ObjectMapperBuilder builder) { - builder.simpleDateFormat(dateTimeFormat); - builder.serializers(new LocalDateSerializer(DateTimeFormatter.ofPattern(dateFormat))); - builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat))); - } - }; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactController.java deleted file mode 100644 index 8894d82fc7..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactController.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.baeldung.jsondateformat; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@RestController -@RequestMapping(value = "/contacts") -public class ContactController { - - @GetMapping - public List getContacts() { - List contacts = new ArrayList<>(); - - Contact contact1 = new Contact("John Doe", "123 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - Contact contact2 = new Contact("John Doe 2", "124 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - Contact contact3 = new Contact("John Doe 3", "125 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - - contacts.add(contact1); - contacts.add(contact2); - contacts.add(contact3); - - return contacts; - } - - @GetMapping("/javaUtilDate") - public List getContactsWithJavaUtilDate() { - List contacts = new ArrayList<>(); - - ContactWithJavaUtilDate contact1 = new ContactWithJavaUtilDate("John Doe", "123 Sesame Street", "123-456-789", new Date(), new Date()); - ContactWithJavaUtilDate contact2 = new ContactWithJavaUtilDate("John Doe 2", "124 Sesame Street", "123-456-789", new Date(), new Date()); - ContactWithJavaUtilDate contact3 = new ContactWithJavaUtilDate("John Doe 3", "125 Sesame Street", "123-456-789", new Date(), new Date()); - - contacts.add(contact1); - contacts.add(contact2); - contacts.add(contact3); - - return contacts; - } - - @GetMapping("/plain") - public List getPlainContacts() { - List contacts = new ArrayList<>(); - - PlainContact contact1 = new PlainContact("John Doe", "123 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - PlainContact contact2 = new PlainContact("John Doe 2", "124 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - PlainContact contact3 = new PlainContact("John Doe 3", "125 Sesame Street", "123-456-789", LocalDate.now(), LocalDateTime.now()); - - contacts.add(contact1); - contacts.add(contact2); - contacts.add(contact3); - - return contacts; - } - - @GetMapping("/plainWithJavaUtilDate") - public List getPlainContactsWithJavaUtilDate() { - List contacts = new ArrayList<>(); - - PlainContactWithJavaUtilDate contact1 = new PlainContactWithJavaUtilDate("John Doe", "123 Sesame Street", "123-456-789", new Date(), new Date()); - PlainContactWithJavaUtilDate contact2 = new PlainContactWithJavaUtilDate("John Doe 2", "124 Sesame Street", "123-456-789", new Date(), new Date()); - PlainContactWithJavaUtilDate contact3 = new PlainContactWithJavaUtilDate("John Doe 3", "125 Sesame Street", "123-456-789", new Date(), new Date()); - - contacts.add(contact1); - contacts.add(contact2); - contacts.add(contact3); - - return contacts; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactWithJavaUtilDate.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactWithJavaUtilDate.java deleted file mode 100644 index 5a1c508098..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactWithJavaUtilDate.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.util.Date; - -public class ContactWithJavaUtilDate { - - private String name; - private String address; - private String phone; - - @JsonFormat(pattern="yyyy-MM-dd") - private Date birthday; - - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") - private Date lastUpdate; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public Date getBirthday() { - return birthday; - } - - public void setBirthday(Date birthday) { - this.birthday = birthday; - } - - public Date getLastUpdate() { - return lastUpdate; - } - - public void setLastUpdate(Date lastUpdate) { - this.lastUpdate = lastUpdate; - } - - public ContactWithJavaUtilDate() { - } - - public ContactWithJavaUtilDate(String name, String address, String phone, Date birthday, Date lastUpdate) { - this.name = name; - this.address = address; - this.phone = phone; - this.birthday = birthday; - this.lastUpdate = lastUpdate; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContact.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContact.java deleted file mode 100644 index 7e9e53d205..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContact.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.jsondateformat; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -public class PlainContact { - - private String name; - private String address; - private String phone; - - private LocalDate birthday; - - private LocalDateTime lastUpdate; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public LocalDate getBirthday() { - return birthday; - } - - public void setBirthday(LocalDate birthday) { - this.birthday = birthday; - } - - public LocalDateTime getLastUpdate() { - return lastUpdate; - } - - public void setLastUpdate(LocalDateTime lastUpdate) { - this.lastUpdate = lastUpdate; - } - - public PlainContact() { - } - - public PlainContact(String name, String address, String phone, LocalDate birthday, LocalDateTime lastUpdate) { - this.name = name; - this.address = address; - this.phone = phone; - this.birthday = birthday; - this.lastUpdate = lastUpdate; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContactWithJavaUtilDate.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContactWithJavaUtilDate.java deleted file mode 100644 index daefb15543..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/PlainContactWithJavaUtilDate.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.util.Date; - -public class PlainContactWithJavaUtilDate { - - private String name; - private String address; - private String phone; - - @JsonFormat(pattern="yyyy-MM-dd") - private Date birthday; - - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") - private Date lastUpdate; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public Date getBirthday() { - return birthday; - } - - public void setBirthday(Date birthday) { - this.birthday = birthday; - } - - public Date getLastUpdate() { - return lastUpdate; - } - - public void setLastUpdate(Date lastUpdate) { - this.lastUpdate = lastUpdate; - } - - public PlainContactWithJavaUtilDate() { - } - - public PlainContactWithJavaUtilDate(String name, String address, String phone, Date birthday, Date lastUpdate) { - this.name = name; - this.address = address; - this.phone = phone; - this.birthday = birthday; - this.lastUpdate = lastUpdate; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java deleted file mode 100644 index cc5f27f38c..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - - @Id - @GeneratedValue - private Integer id; - private String name; - private Integer status; - - public User() { - } - - public User(String name, Integer status) { - this.name = name; - this.status = status; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java deleted file mode 100644 index 4dd863fb17..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.model.User; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Repository; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; - -@Repository("userRepository") -public interface UserRepository extends JpaRepository { - - int countByStatus(int status); - - Optional findOneByName(String name); - - @Async - CompletableFuture findOneByStatus(Integer status); - - @Query("SELECT u FROM User u WHERE u.status = 1") - Collection findAllActiveUsers(); - - @Query(value = "SELECT * FROM USERS u WHERE u.status = 1", nativeQuery = true) - Collection findAllActiveUsersNative(); - - @Query("SELECT u FROM User u WHERE u.status = ?1") - User findUserByStatus(Integer status); - - @Query(value = "SELECT * FROM Users u WHERE u.status = ?1", nativeQuery = true) - User findUserByStatusNative(Integer status); - - @Query("SELECT u FROM User u WHERE u.status = ?1 and u.name = ?2") - User findUserByStatusAndName(Integer status, String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByStatusAndNameNamedParams(@Param("status") Integer status, @Param("name") String name); - - @Query(value = "SELECT * FROM Users u WHERE u.status = :status AND u.name = :name", nativeQuery = true) - User findUserByStatusAndNameNamedParamsNative(@Param("status") Integer status, @Param("name") String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByUserStatusAndUserName(@Param("status") Integer userStatus, @Param("name") String userName); - - @Query("SELECT u FROM User u WHERE u.name like ?1%") - User findUserByNameLike(String name); - - @Query("SELECT u FROM User u WHERE u.name like :name%") - User findUserByNameLikeNamedParam(@Param("name") String name); - - @Query(value = "SELECT * FROM users u WHERE u.name LIKE ?1%", nativeQuery = true) - User findUserByNameLikeNative(String name); - - @Query(value = "SELECT u FROM User u") - List findAllUsers(Sort sort); - - @Query(value = "SELECT u FROM User u ORDER BY id") - Page findAllUsersWithPagination(Pageable pageable); - - @Query(value = "SELECT * FROM Users ORDER BY id \n-- #pageable\n", countQuery = "SELECT count(*) FROM Users", nativeQuery = true) - Page findAllUsersWithPaginationNative(Pageable pageable); - - @Modifying - @Query("update User u set u.status = :status where u.name = :name") - int updateUserSetStatusForName(@Param("status") Integer status, @Param("name") String name); - - @Modifying - @Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true) - int updateUserSetStatusForNameNative(Integer status, String name); - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java deleted file mode 100644 index 3efa619409..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.rss; - -import com.rometools.rome.feed.rss.Channel; -import com.rometools.rome.feed.rss.Description; -import com.rometools.rome.feed.rss.Item; -import org.springframework.stereotype.Service; -import org.springframework.web.servlet.view.feed.AbstractRssFeedView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -@Service("articleFeedView") -public class ArticleFeedView extends AbstractRssFeedView { - - protected Channel newFeed() { - Channel channel = new Channel("rss_2.0"); - channel.setLink("http://localhost:8080/rss"); - channel.setTitle("Article Feed"); - channel.setDescription("Article Feed Description"); - channel.setPubDate(new Date()); - return channel; - } - - @Override - protected List buildFeedItems(Map map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception { - List list = new ArrayList(); - - Item item1 = new Item(); - item1.setLink("http://www.baeldung.com/netty-exception-handling"); - item1.setTitle("Exceptions in Netty"); - Description description1 = new Description(); - description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); - item1.setDescription(description1); - item1.setPubDate(new Date()); - item1.setAuthor("Carlos"); - - Item item2 = new Item(); - item2.setLink("http://www.baeldung.com/cockroachdb-java"); - item2.setTitle("Guide to CockroachDB in Java"); - Description description2 = new Description(); - description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); - item2.setDescription(description2); - item2.setPubDate(new Date()); - item2.setAuthor("Baeldung"); - - list.add(item1); - list.add(item2); - return list; - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java deleted file mode 100644 index daaeb8159b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.rss; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -@RequestMapping(value = "/rss", produces = "application/*") -public class ArticleRssController { - - @GetMapping - public String articleFeed() { - return "articleFeedView"; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/RssApp.java deleted file mode 100644 index e067d3cfd1..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/rss/RssApp.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.rss; - -import javax.annotation.security.RolesAllowed; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.rss") -public class RssApp { - - @RolesAllowed("*") - public static void main(String[] args) { - SpringApplication.run(RssApp.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties b/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties deleted file mode 100644 index 270e86d443..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties +++ /dev/null @@ -1,4 +0,0 @@ -#server -server.port=9000 -server.servlet-path=/ -server.context-path=/ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/build.properties b/spring-boot-modules/spring-boot/src/main/resources/build.properties deleted file mode 100644 index 1612b8086d..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -application-description=@project.description@ -application-version=@project.version@ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/build.yml b/spring-boot-modules/spring-boot/src/main/resources/build.yml deleted file mode 100644 index 528d2e3440..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/build.yml +++ /dev/null @@ -1,2 +0,0 @@ -application-description: ^project.description^ -application-version: ^project.version^ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/data-expressions.sql b/spring-boot-modules/spring-boot/src/main/resources/data-expressions.sql deleted file mode 100644 index 3e702a759d..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/data-expressions.sql +++ /dev/null @@ -1,3 +0,0 @@ -insert into contact_info_expression values ('email','[a-z0-9!#$%&*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?') -insert into contact_info_expression values ('phone','^([0-9]( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$') -insert into contact_info_expression values ('website','^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$') \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/data.sql b/spring-boot-modules/spring-boot/src/main/resources/data.sql deleted file mode 100644 index c44034c739..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/data.sql +++ /dev/null @@ -1,5 +0,0 @@ -insert into users values (1, 'Alex', 1); -insert into users values (2, 'Bob', 1); -insert into users values (3, 'John', 0); -insert into users values (4, 'Harry', 0); -insert into users values (5, 'Smith', 1); \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/demo.properties b/spring-boot-modules/spring-boot/src/main/resources/demo.properties deleted file mode 100644 index 6b4cbeb7a0..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/demo.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.output.ansi.enabled=never -server.port=7070 diff --git a/spring-boot-modules/spring-boot/src/main/resources/persistence-generic-entity.properties b/spring-boot-modules/spring-boot/src/main/resources/persistence-generic-entity.properties deleted file mode 100644 index b19304cb1f..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/persistence-generic-entity.properties +++ /dev/null @@ -1,8 +0,0 @@ -jdbc.driverClassName=org.h2.Driver -jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 -jdbc.user=sa -jdbc.pass=sa - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop diff --git a/spring-boot-modules/spring-boot/src/main/resources/public/error/404.html b/spring-boot-modules/spring-boot/src/main/resources/public/error/404.html deleted file mode 100644 index df83ce219b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/public/error/404.html +++ /dev/null @@ -1,8 +0,0 @@ - - - RESOURCE NOT FOUND - - -

404 RESOURCE NOT FOUND

- - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/schema-expressions.sql b/spring-boot-modules/spring-boot/src/main/resources/schema-expressions.sql deleted file mode 100644 index 59f6ab05eb..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/schema-expressions.sql +++ /dev/null @@ -1,5 +0,0 @@ -create table contact_info_expression( - expression_type varchar(50) not null, - pattern varchar(500) not null, - PRIMARY KEY ( expression_type ) -); \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/schema.sql b/spring-boot-modules/spring-boot/src/main/resources/schema.sql deleted file mode 100644 index 4cd345c762..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/schema.sql +++ /dev/null @@ -1,8 +0,0 @@ -drop table if exists USERS; - -create table USERS( - ID int not null AUTO_INCREMENT, - NAME varchar(100) not null, - STATUS int, - PRIMARY KEY ( ID ) -); \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/customers.html b/spring-boot-modules/spring-boot/src/main/resources/templates/customers.html deleted file mode 100644 index 5a060d31da..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/customers.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - -
-

- Hello, --name--. -

- - - - - - - - - - - - - - - - - -
IDNameAddressService Rendered
Text ...Text ...Text ...Text...
- -
- - - diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/error.html b/spring-boot-modules/spring-boot/src/main/resources/templates/error.html deleted file mode 100644 index bc517913b2..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/error.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - -
-
-

Something went wrong!

- -

Our Engineers are on it.

-

Go Home

-
- - diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/error/404.html b/spring-boot-modules/spring-boot/src/main/resources/templates/error/404.html deleted file mode 100644 index df83ce219b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/error/404.html +++ /dev/null @@ -1,8 +0,0 @@ - - - RESOURCE NOT FOUND - - -

404 RESOURCE NOT FOUND

- - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/external.html b/spring-boot-modules/spring-boot/src/main/resources/templates/external.html deleted file mode 100644 index 2f9cc76961..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/external.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - -
-
-

Customer Portal

-
-
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam - erat lectus, vehicula feugiat ultricies at, tempus sed ante. Cras - arcu erat, lobortis vitae quam et, mollis pharetra odio. Nullam sit - amet congue ipsum. Nunc dapibus odio ut ligula venenatis porta non - id dui. Duis nec tempor tellus. Suspendisse id blandit ligula, sit - amet varius mauris. Nulla eu eros pharetra, tristique dui quis, - vehicula libero. Aenean a neque sit amet tellus porttitor rutrum nec - at leo.

- -

Existing Customers

-
- Enter the intranet: customers -
-
- -
- - - - diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/index.html b/spring-boot-modules/spring-boot/src/main/resources/templates/index.html deleted file mode 100644 index c1314558f6..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - WebJars Demo - - - -

Welcome Home

-

-
- × - Success! It is working as we expected. -
-
- - - - - - diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/layout.html b/spring-boot-modules/spring-boot/src/main/resources/templates/layout.html deleted file mode 100644 index bab0c2982b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/layout.html +++ /dev/null @@ -1,18 +0,0 @@ - - - -Customer Portal - - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java deleted file mode 100644 index cb056fe56d..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.buildproperties; - -import static org.junit.Assert.assertThat; - -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -class BuildInfoServiceIntegrationTest { - - @Autowired - private BuildInfoService service; - - @Test - void whenGetApplicationDescription_thenSuccess() { - assertThat(service.getApplicationDescription(), Matchers.is("This is simple boot application for Spring boot actuator test")); - assertThat(service.getApplicationVersion(), Matchers.is("0.0.1-SNAPSHOT")); - } -} diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java deleted file mode 100644 index 2785054153..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.intro; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) -@AutoConfigureMockMvc -public class AppLiveTest { - - @Autowired - private MockMvc mvc; - - @Test - public void getIndex() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("Index Page"))); - } - - @Test - public void getLocal() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("/local"))); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppUnitTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppUnitTest.java deleted file mode 100644 index 7be85b5e4f..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppUnitTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.text.ParseException; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ContactApp.class) -@TestPropertySource(properties = { - "spring.jackson.date-format=yyyy-MM-dd HH:mm:ss" -}) -public class ContactAppUnitTest { - - private final ObjectMapper mapper = new ObjectMapper(); - - @Autowired - TestRestTemplate restTemplate; - - @LocalServerPort - int port; - - String url; - - @Before - public void before() { - url=String.format("http://localhost:%s", port); - } - - @Test - public void givenJsonFormatAnnotationAndJava8DateType_whenGet_thenReturnExpectedDateFormat() throws IOException, ParseException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - - assertNotNull(birthdayDate); - assertNotNull(lastUpdateTime); - } - - @Test - public void givenJsonFormatAnnotationAndLegacyDateType_whenGet_thenReturnExpectedDateFormat() throws IOException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts/javaUtilDate", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - - assertNotNull(birthdayDate); - assertNotNull(lastUpdateTime); - } - - @Test - public void givenDefaultDateFormatInAppPropertiesAndLegacyDateType_whenGet_thenReturnExpectedDateFormat() throws IOException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts/plainWithJavaUtilDate", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - - assertNotNull(birthdayDate); - assertNotNull(lastUpdateTime); - } - - @Test(expected = DateTimeParseException.class) - public void givenDefaultDateFormatInAppPropertiesAndJava8DateType_whenGet_thenNotApplyFormat() throws IOException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts/plain", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - } - -} diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppWithObjectMapperCustomizerUnitTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppWithObjectMapperCustomizerUnitTest.java deleted file mode 100644 index 114f9bfc1a..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/jsondateformat/ContactAppWithObjectMapperCustomizerUnitTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.jsondateformat; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ContactApp.class) -public class ContactAppWithObjectMapperCustomizerUnitTest { - - private final ObjectMapper mapper = new ObjectMapper(); - - @Autowired - TestRestTemplate restTemplate; - - @LocalServerPort - int port; - - String url; - - @Before - public void before() { - url=String.format("http://localhost:%s", port); - } - - @Test - public void givenDefaultDateFormatInAppPropertiesAndLegacyDateType_whenGet_thenReturnExpectedDateFormat() throws IOException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts/plainWithJavaUtilDate", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - - assertNotNull(birthdayDate); - assertNotNull(lastUpdateTime); - } - - @Test - public void givenDefaultDateFormatInAppPropertiesAndJava8DateType_whenGet_thenReturnExpectedDateFormat() throws IOException { - ResponseEntity response = restTemplate.getForEntity(url + "/contacts/plain", String.class); - - assertEquals(200, response.getStatusCodeValue()); - - List> respMap = mapper.readValue(response.getBody(), new TypeReference>>(){}); - - LocalDate birthdayDate = LocalDate.parse(respMap.get(0).get("birthday"), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - LocalDateTime lastUpdateTime = LocalDateTime.parse(respMap.get(0).get("lastUpdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - - assertNotNull(birthdayDate); - assertNotNull(lastUpdateTime); - } - -} diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java deleted file mode 100644 index a1318949f3..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.boot.config.H2JpaConfig; -import com.baeldung.model.User; -import com.baeldung.repository.UserRepository; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Created by adam. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = H2JpaConfig.class) -public class UserRepositoryIntegrationTest { - - private final String USER_NAME_ADAM = "Adam"; - private final Integer ACTIVE_STATUS = 1; - - @Autowired - private UserRepository userRepository; - - @Test - public void givenEmptyDBWhenFindOneByNameThenReturnEmptyOptional() { - Optional foundUser = userRepository.findOneByName(USER_NAME_ADAM); - - assertThat(foundUser.isPresent()).isEqualTo(false); - } - - @Test - public void givenUserInDBWhenFindOneByNameThenReturnOptionalWithUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - userRepository.save(user); - - Optional foundUser = userRepository.findOneByName(USER_NAME_ADAM); - - assertThat(foundUser.isPresent()).isEqualTo(true); - - assertThat(foundUser - .get() - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUserInDBWhenFindOneByStatusAsyncThenReturnCompletableFutureUser() throws ExecutionException, InterruptedException { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - CompletableFuture userByStatus = userRepository.findOneByStatus(ACTIVE_STATUS); - - assertThat(userByStatus - .get() - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @After - public void cleanUp() { - userRepository.deleteAll(); - } - -} diff --git a/spring-boot-modules/spring-boot/src/test/resources/README.md b/spring-boot-modules/spring-boot/src/test/resources/README.md deleted file mode 100644 index 51c95afd9d..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [How to Test GraphQL Using Postman](https://www.baeldung.com/graphql-postman) diff --git a/spring-boot-modules/spring-boot/src/test/resources/application.properties b/spring-boot-modules/spring-boot/src/test/resources/application.properties deleted file mode 100644 index 9ad65e1815..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/application.properties +++ /dev/null @@ -1,19 +0,0 @@ -spring.mail.host=localhost -spring.mail.port=8025 -spring.mail.properties.mail.smtp.auth=false - - -# spring.datasource.x -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 -spring.datasource.username=sa -spring.datasource.password=sa - -# hibernate.X -spring.jpa.hibernate.dialect=org.hibernate.dialect.H2Dialect -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.show_sql=true -spring.jpa.hibernate.hbm2ddl.auto=create-drop -spring.jpa.hibernate.cache.use_second_level_cache=true -spring.jpa.hibernate.cache.use_query_cache=true -spring.jpa.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory diff --git a/spring-boot-modules/spring-boot/src/test/resources/conversion.properties b/spring-boot-modules/spring-boot/src/test/resources/conversion.properties deleted file mode 100644 index 640442ec33..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/conversion.properties +++ /dev/null @@ -1,11 +0,0 @@ -###### time unit -conversion.timeInDefaultUnit=10 -conversion.timeInNano=9ns -conversion.timeInDays=2 - -###### data size -conversion.sizeInDefaultUnit=300 -conversion.sizeInGB=2GB -conversion.sizeInTB=4 - -conversion.employee=john,2000 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/test/resources/import.sql b/spring-boot-modules/spring-boot/src/test/resources/import.sql deleted file mode 100644 index 9095b9468c..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/import.sql +++ /dev/null @@ -1 +0,0 @@ ---insert into Foo values(1,'Foo_Name'); \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/test/resources/org/baeldung/boot/expected.json b/spring-boot-modules/spring-boot/src/test/resources/org/baeldung/boot/expected.json deleted file mode 100644 index f5409421a6..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/org/baeldung/boot/expected.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "id":3, - "name":"Foo_Name_3" -} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/README.md b/spring-cloud/spring-cloud-eureka/README.md index 5fc96256f4..0029ea60f6 100644 --- a/spring-cloud/spring-cloud-eureka/README.md +++ b/spring-cloud/spring-cloud-eureka/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Introduction to Spring Cloud Netflix – Eureka](http://www.baeldung.com/spring-cloud-netflix-eureka) - [Integration Tests With Spring Cloud Netflix and Feign](https://www.baeldung.com/spring-cloud-feign-integration-tests) +- [Spring Cloud – Disable Discovery Clients with Profiles](https://www.baeldung.com/spring-cloud-disable-discovery-clients) diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/pom.xml new file mode 100644 index 0000000000..23e06a55f9 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + spring-cloud-eureka-client-profiles + 1.0.0-SNAPSHOT + spring-cloud-eureka-client-profiles + jar + Spring Cloud Eureka Sample Client + + + com.baeldung.spring.cloud + spring-cloud-eureka + 1.0.0-SNAPSHOT + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + org.springframework.cloud + spring-cloud-starter-parent + ${spring-cloud-dependencies.version} + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactApp.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java similarity index 56% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactApp.java rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java index 79037e1038..854bab97e7 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/jsondateformat/ContactApp.java +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java @@ -1,13 +1,13 @@ -package com.baeldung.jsondateformat; +package com.baeldung.spring.cloud.eureka.client; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class ContactApp { +public class EurekaClientApplication { public static void main(String[] args) { - SpringApplication.run(ContactApp.class, args); + SpringApplication.run(EurekaClientApplication.class, args); } } diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/controller/HelloWorldController.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/controller/HelloWorldController.java new file mode 100644 index 0000000000..d0d0a6ec9f --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/java/com/baeldung/spring/cloud/eureka/client/controller/HelloWorldController.java @@ -0,0 +1,13 @@ +package com.baeldung.spring.cloud.eureka.client.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloWorldController { + + @RequestMapping("/hello") + public String hello() { + return "Hello World!"; + } +} diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application-dev.properties b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application-dev.properties new file mode 100644 index 0000000000..c565e42678 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application-dev.properties @@ -0,0 +1,2 @@ +server.port=8080 +spring.cloud.discovery.enabled=false \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application.properties b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application.properties new file mode 100644 index 0000000000..3cfecbbf08 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/main/resources/application.properties @@ -0,0 +1,9 @@ +server.port=8080 + +eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka} +eureka.instance.preferIpAddress=false + +spring.application.name=spring-cloud-eureka-client +#--- +spring.config.activate.on-profile=dev +spring.cloud.discovery.enabled=false \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextTest.java new file mode 100644 index 0000000000..a3ed012abb --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client-profiles/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextTest.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.eureka.client; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } + +}