From a6e7c73a5f8646c0653d956aec8a1dd8d6c073ad Mon Sep 17 00:00:00 2001 From: sixcorners Date: Tue, 20 Aug 2019 10:56:01 -0500 Subject: [PATCH 01/47] Fix AwsSecretsManagerProperties.prefix javadoc --- .../cloud/aws/secretsmanager/AwsSecretsManagerProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java index c06555501..348e414c0 100644 --- a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java +++ b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java @@ -41,7 +41,7 @@ public class AwsSecretsManagerProperties { /** * Prefix indicating first level for every property. Value must start with a forward - * slash followed by a valid path segment or be empty. Defaults to "/config". + * slash followed by a valid path segment or be empty. Defaults to "/secret". */ @NotNull @Pattern(regexp = "(/[a-zA-Z0-9.\\-_]+)*") From d52dae11fb5b2bc503d1dd4632e68ed417e8ea22 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 20 Jan 2020 13:16:46 +0000 Subject: [PATCH 02/47] Bumping versions --- docs/pom.xml | 2 +- pom.xml | 4 ++-- spring-cloud-aws-actuator/pom.xml | 2 +- spring-cloud-aws-autoconfigure/pom.xml | 2 +- spring-cloud-aws-context/pom.xml | 2 +- spring-cloud-aws-core/pom.xml | 2 +- spring-cloud-aws-dependencies/pom.xml | 4 ++-- spring-cloud-aws-integration-test/pom.xml | 2 +- spring-cloud-aws-jdbc/pom.xml | 2 +- spring-cloud-aws-messaging/pom.xml | 2 +- spring-cloud-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws-jdbc/pom.xml | 2 +- spring-cloud-starter-aws-messaging/pom.xml | 2 +- spring-cloud-starter-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-starter-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws/pom.xml | 2 +- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index f3c41551b..2def5575f 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-docs pom diff --git a/pom.xml b/pom.xml index fa2912e1f..ab83f7d5d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,12 +22,12 @@ org.springframework.cloud spring-cloud-build - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT pom Spring Cloud AWS Spring Cloud AWS diff --git a/spring-cloud-aws-actuator/pom.xml b/spring-cloud-aws-actuator/pom.xml index 90e649dd2..4ab8e69b0 100644 --- a/spring-cloud-aws-actuator/pom.xml +++ b/spring-cloud-aws-actuator/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-autoconfigure/pom.xml b/spring-cloud-aws-autoconfigure/pom.xml index baa5a3739..576ae16bd 100644 --- a/spring-cloud-aws-autoconfigure/pom.xml +++ b/spring-cloud-aws-autoconfigure/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-context/pom.xml b/spring-cloud-aws-context/pom.xml index 577c2d4d2..bb11bfe57 100644 --- a/spring-cloud-aws-context/pom.xml +++ b/spring-cloud-aws-context/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-context diff --git a/spring-cloud-aws-core/pom.xml b/spring-cloud-aws-core/pom.xml index 7ab880a61..b4f1bf4a9 100644 --- a/spring-cloud-aws-core/pom.xml +++ b/spring-cloud-aws-core/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-core diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index a75606057..d9d6ee300 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -22,11 +22,11 @@ org.springframework.cloud spring-cloud-dependencies-parent - 2.2.1.RELEASE + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-dependencies - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT pom Spring Cloud AWS Dependencies Spring Cloud AWS Dependencies diff --git a/spring-cloud-aws-integration-test/pom.xml b/spring-cloud-aws-integration-test/pom.xml index 12bab49d6..2162cd454 100644 --- a/spring-cloud-aws-integration-test/pom.xml +++ b/spring-cloud-aws-integration-test/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-integration-test diff --git a/spring-cloud-aws-jdbc/pom.xml b/spring-cloud-aws-jdbc/pom.xml index 5c889bfed..b036ddd1f 100644 --- a/spring-cloud-aws-jdbc/pom.xml +++ b/spring-cloud-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-jdbc diff --git a/spring-cloud-aws-messaging/pom.xml b/spring-cloud-aws-messaging/pom.xml index 69d8b7ff8..04c7d7997 100644 --- a/spring-cloud-aws-messaging/pom.xml +++ b/spring-cloud-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-messaging diff --git a/spring-cloud-aws-parameter-store-config/pom.xml b/spring-cloud-aws-parameter-store-config/pom.xml index 744a6c757..9ec5cd737 100644 --- a/spring-cloud-aws-parameter-store-config/pom.xml +++ b/spring-cloud-aws-parameter-store-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-parameter-store-config diff --git a/spring-cloud-aws-secrets-manager-config/pom.xml b/spring-cloud-aws-secrets-manager-config/pom.xml index 679544a27..737c67553 100644 --- a/spring-cloud-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-aws-secrets-manager-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-aws-secrets-manager-config diff --git a/spring-cloud-starter-aws-jdbc/pom.xml b/spring-cloud-starter-aws-jdbc/pom.xml index aa2b15db8..157118f15 100644 --- a/spring-cloud-starter-aws-jdbc/pom.xml +++ b/spring-cloud-starter-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-starter-aws-jdbc Spring Cloud AWS JDBC Starter diff --git a/spring-cloud-starter-aws-messaging/pom.xml b/spring-cloud-starter-aws-messaging/pom.xml index 973545469..580bd54ab 100644 --- a/spring-cloud-starter-aws-messaging/pom.xml +++ b/spring-cloud-starter-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-starter-aws-messaging Spring Cloud AWS Messaging Starter diff --git a/spring-cloud-starter-aws-parameter-store-config/pom.xml b/spring-cloud-starter-aws-parameter-store-config/pom.xml index 2da9b7979..0d05b59ab 100644 --- a/spring-cloud-starter-aws-parameter-store-config/pom.xml +++ b/spring-cloud-starter-aws-parameter-store-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-starter-aws-parameter-store-config Spring Cloud AWS Parameter Store Configuration Starter diff --git a/spring-cloud-starter-aws-secrets-manager-config/pom.xml b/spring-cloud-starter-aws-secrets-manager-config/pom.xml index 8dcbffa49..92e3c79b6 100644 --- a/spring-cloud-starter-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-starter-aws-secrets-manager-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-starter-aws-secrets-manager-config Spring Cloud AWS Secrets Manager Configuration Starter diff --git a/spring-cloud-starter-aws/pom.xml b/spring-cloud-starter-aws/pom.xml index 25a771de1..4cc34c7a5 100644 --- a/spring-cloud-starter-aws/pom.xml +++ b/spring-cloud-starter-aws/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-starter-aws Spring Cloud AWS Starter From 33e1535012dba06573e29df74d8ba4f1419e3e5c Mon Sep 17 00:00:00 2001 From: buildmaster Date: Tue, 21 Jan 2020 07:33:06 +0000 Subject: [PATCH 03/47] Bumping versions --- docs/pom.xml | 2 +- pom.xml | 4 ++-- spring-cloud-aws-actuator/pom.xml | 2 +- spring-cloud-aws-autoconfigure/pom.xml | 2 +- spring-cloud-aws-context/pom.xml | 2 +- spring-cloud-aws-core/pom.xml | 2 +- spring-cloud-aws-dependencies/pom.xml | 4 ++-- spring-cloud-aws-integration-test/pom.xml | 2 +- spring-cloud-aws-jdbc/pom.xml | 2 +- spring-cloud-aws-messaging/pom.xml | 2 +- spring-cloud-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws-jdbc/pom.xml | 2 +- spring-cloud-starter-aws-messaging/pom.xml | 2 +- spring-cloud-starter-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-starter-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws/pom.xml | 2 +- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 2def5575f..f3c41551b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-docs pom diff --git a/pom.xml b/pom.xml index ab83f7d5d..fa2912e1f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,12 +22,12 @@ org.springframework.cloud spring-cloud-build - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT pom Spring Cloud AWS Spring Cloud AWS diff --git a/spring-cloud-aws-actuator/pom.xml b/spring-cloud-aws-actuator/pom.xml index 4ab8e69b0..90e649dd2 100644 --- a/spring-cloud-aws-actuator/pom.xml +++ b/spring-cloud-aws-actuator/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-autoconfigure/pom.xml b/spring-cloud-aws-autoconfigure/pom.xml index 576ae16bd..baa5a3739 100644 --- a/spring-cloud-aws-autoconfigure/pom.xml +++ b/spring-cloud-aws-autoconfigure/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-context/pom.xml b/spring-cloud-aws-context/pom.xml index bb11bfe57..577c2d4d2 100644 --- a/spring-cloud-aws-context/pom.xml +++ b/spring-cloud-aws-context/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-context diff --git a/spring-cloud-aws-core/pom.xml b/spring-cloud-aws-core/pom.xml index b4f1bf4a9..7ab880a61 100644 --- a/spring-cloud-aws-core/pom.xml +++ b/spring-cloud-aws-core/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-core diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index d9d6ee300..a75606057 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -22,11 +22,11 @@ org.springframework.cloud spring-cloud-dependencies-parent - 3.0.0.BUILD-SNAPSHOT + 2.2.1.RELEASE spring-cloud-aws-dependencies - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT pom Spring Cloud AWS Dependencies Spring Cloud AWS Dependencies diff --git a/spring-cloud-aws-integration-test/pom.xml b/spring-cloud-aws-integration-test/pom.xml index 2162cd454..12bab49d6 100644 --- a/spring-cloud-aws-integration-test/pom.xml +++ b/spring-cloud-aws-integration-test/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-integration-test diff --git a/spring-cloud-aws-jdbc/pom.xml b/spring-cloud-aws-jdbc/pom.xml index b036ddd1f..5c889bfed 100644 --- a/spring-cloud-aws-jdbc/pom.xml +++ b/spring-cloud-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-jdbc diff --git a/spring-cloud-aws-messaging/pom.xml b/spring-cloud-aws-messaging/pom.xml index 04c7d7997..69d8b7ff8 100644 --- a/spring-cloud-aws-messaging/pom.xml +++ b/spring-cloud-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-messaging diff --git a/spring-cloud-aws-parameter-store-config/pom.xml b/spring-cloud-aws-parameter-store-config/pom.xml index 9ec5cd737..744a6c757 100644 --- a/spring-cloud-aws-parameter-store-config/pom.xml +++ b/spring-cloud-aws-parameter-store-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-parameter-store-config diff --git a/spring-cloud-aws-secrets-manager-config/pom.xml b/spring-cloud-aws-secrets-manager-config/pom.xml index 737c67553..679544a27 100644 --- a/spring-cloud-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-aws-secrets-manager-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-aws-secrets-manager-config diff --git a/spring-cloud-starter-aws-jdbc/pom.xml b/spring-cloud-starter-aws-jdbc/pom.xml index 157118f15..aa2b15db8 100644 --- a/spring-cloud-starter-aws-jdbc/pom.xml +++ b/spring-cloud-starter-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-starter-aws-jdbc Spring Cloud AWS JDBC Starter diff --git a/spring-cloud-starter-aws-messaging/pom.xml b/spring-cloud-starter-aws-messaging/pom.xml index 580bd54ab..973545469 100644 --- a/spring-cloud-starter-aws-messaging/pom.xml +++ b/spring-cloud-starter-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-starter-aws-messaging Spring Cloud AWS Messaging Starter diff --git a/spring-cloud-starter-aws-parameter-store-config/pom.xml b/spring-cloud-starter-aws-parameter-store-config/pom.xml index 0d05b59ab..2da9b7979 100644 --- a/spring-cloud-starter-aws-parameter-store-config/pom.xml +++ b/spring-cloud-starter-aws-parameter-store-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-starter-aws-parameter-store-config Spring Cloud AWS Parameter Store Configuration Starter diff --git a/spring-cloud-starter-aws-secrets-manager-config/pom.xml b/spring-cloud-starter-aws-secrets-manager-config/pom.xml index 92e3c79b6..8dcbffa49 100644 --- a/spring-cloud-starter-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-starter-aws-secrets-manager-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-starter-aws-secrets-manager-config Spring Cloud AWS Secrets Manager Configuration Starter diff --git a/spring-cloud-starter-aws/pom.xml b/spring-cloud-starter-aws/pom.xml index 4cc34c7a5..25a771de1 100644 --- a/spring-cloud-starter-aws/pom.xml +++ b/spring-cloud-starter-aws/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 3.0.0.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT spring-cloud-starter-aws Spring Cloud AWS Starter From 328b1307f41f8b011a964d7491318e9df6345b17 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 1 Apr 2020 13:28:14 +0200 Subject: [PATCH 04/47] Updated docs --- docs/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/pom.xml b/docs/pom.xml index f3c41551b..e0be89b64 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -97,6 +97,10 @@ org.apache.maven.plugins maven-antrun-plugin + + org.codehaus.mojo + build-helper-maven-plugin + From 5ac4cdbf7b98a032ba7205d2c5d6054b6e0ca604 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 22 Apr 2020 10:47:24 -0400 Subject: [PATCH 05/47] Bumps versions to 3.0.0-SNAPHOT --- docs/pom.xml | 2 +- pom.xml | 4 ++-- spring-cloud-aws-actuator/pom.xml | 2 +- spring-cloud-aws-autoconfigure/pom.xml | 2 +- spring-cloud-aws-context/pom.xml | 2 +- spring-cloud-aws-core/pom.xml | 2 +- spring-cloud-aws-dependencies/pom.xml | 4 ++-- spring-cloud-aws-integration-test/pom.xml | 2 +- spring-cloud-aws-jdbc/pom.xml | 2 +- spring-cloud-aws-messaging/pom.xml | 2 +- spring-cloud-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws-jdbc/pom.xml | 2 +- spring-cloud-starter-aws-messaging/pom.xml | 2 +- spring-cloud-starter-aws-parameter-store-config/pom.xml | 2 +- spring-cloud-starter-aws-secrets-manager-config/pom.xml | 2 +- spring-cloud-starter-aws/pom.xml | 2 +- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 365685c7a..4b3a18d6d 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-docs pom diff --git a/pom.xml b/pom.xml index 1f6499034..3724cc666 100644 --- a/pom.xml +++ b/pom.xml @@ -22,12 +22,12 @@ org.springframework.cloud spring-cloud-build - 2.3.0.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT pom Spring Cloud AWS Spring Cloud AWS diff --git a/spring-cloud-aws-actuator/pom.xml b/spring-cloud-aws-actuator/pom.xml index 6ab158f1f..84acb0d7a 100644 --- a/spring-cloud-aws-actuator/pom.xml +++ b/spring-cloud-aws-actuator/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-autoconfigure/pom.xml b/spring-cloud-aws-autoconfigure/pom.xml index baa5a3739..802069b0c 100644 --- a/spring-cloud-aws-autoconfigure/pom.xml +++ b/spring-cloud-aws-autoconfigure/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/spring-cloud-aws-context/pom.xml b/spring-cloud-aws-context/pom.xml index 577c2d4d2..1358c9f14 100644 --- a/spring-cloud-aws-context/pom.xml +++ b/spring-cloud-aws-context/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-context diff --git a/spring-cloud-aws-core/pom.xml b/spring-cloud-aws-core/pom.xml index 7ab880a61..a57d97902 100644 --- a/spring-cloud-aws-core/pom.xml +++ b/spring-cloud-aws-core/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-core diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index 4427898cc..f90132fdd 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -22,11 +22,11 @@ org.springframework.cloud spring-cloud-dependencies-parent - 2.3.0.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-dependencies - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT pom Spring Cloud AWS Dependencies Spring Cloud AWS Dependencies diff --git a/spring-cloud-aws-integration-test/pom.xml b/spring-cloud-aws-integration-test/pom.xml index 12bab49d6..120a07357 100644 --- a/spring-cloud-aws-integration-test/pom.xml +++ b/spring-cloud-aws-integration-test/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-integration-test diff --git a/spring-cloud-aws-jdbc/pom.xml b/spring-cloud-aws-jdbc/pom.xml index 5c889bfed..b71b94a90 100644 --- a/spring-cloud-aws-jdbc/pom.xml +++ b/spring-cloud-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-jdbc diff --git a/spring-cloud-aws-messaging/pom.xml b/spring-cloud-aws-messaging/pom.xml index 69d8b7ff8..e436bd438 100644 --- a/spring-cloud-aws-messaging/pom.xml +++ b/spring-cloud-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-messaging diff --git a/spring-cloud-aws-parameter-store-config/pom.xml b/spring-cloud-aws-parameter-store-config/pom.xml index 744a6c757..f1b066530 100644 --- a/spring-cloud-aws-parameter-store-config/pom.xml +++ b/spring-cloud-aws-parameter-store-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-parameter-store-config diff --git a/spring-cloud-aws-secrets-manager-config/pom.xml b/spring-cloud-aws-secrets-manager-config/pom.xml index 679544a27..753e6e77a 100644 --- a/spring-cloud-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-aws-secrets-manager-config/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-secrets-manager-config diff --git a/spring-cloud-starter-aws-jdbc/pom.xml b/spring-cloud-starter-aws-jdbc/pom.xml index aa2b15db8..d50b9894c 100644 --- a/spring-cloud-starter-aws-jdbc/pom.xml +++ b/spring-cloud-starter-aws-jdbc/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws-jdbc Spring Cloud AWS JDBC Starter diff --git a/spring-cloud-starter-aws-messaging/pom.xml b/spring-cloud-starter-aws-messaging/pom.xml index 973545469..0ebca94d1 100644 --- a/spring-cloud-starter-aws-messaging/pom.xml +++ b/spring-cloud-starter-aws-messaging/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws-messaging Spring Cloud AWS Messaging Starter diff --git a/spring-cloud-starter-aws-parameter-store-config/pom.xml b/spring-cloud-starter-aws-parameter-store-config/pom.xml index 2da9b7979..61d5e904b 100644 --- a/spring-cloud-starter-aws-parameter-store-config/pom.xml +++ b/spring-cloud-starter-aws-parameter-store-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws-parameter-store-config Spring Cloud AWS Parameter Store Configuration Starter diff --git a/spring-cloud-starter-aws-secrets-manager-config/pom.xml b/spring-cloud-starter-aws-secrets-manager-config/pom.xml index 8dcbffa49..6705062dc 100644 --- a/spring-cloud-starter-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-starter-aws-secrets-manager-config/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws-secrets-manager-config Spring Cloud AWS Secrets Manager Configuration Starter diff --git a/spring-cloud-starter-aws/pom.xml b/spring-cloud-starter-aws/pom.xml index 25a771de1..e926c0032 100644 --- a/spring-cloud-starter-aws/pom.xml +++ b/spring-cloud-starter-aws/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.2.2.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws Spring Cloud AWS Starter From e540b7ca9ee314ac99a73746f3e241daba8424c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Jako=C5=A1a?= Date: Wed, 27 Mar 2019 12:21:49 +0100 Subject: [PATCH 06/47] Update of documentation regarding supported DB engines that Amazon RDS can use to create read replicas. Closes gh-458 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 74544d65d..23c92b98f 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -1741,7 +1741,8 @@ outlines all properties for a data source using `test` as the instance identifie === Read-replica configuration -Amazon RDS allows to use https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html[MySQL read-replica] +Amazon RDS allows to use MySQL, MariaDB, Oracle, PostgreSQL and +Microsoft SQL Server https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html[read-replica] instances to increase the overall throughput of the database by offloading read data access to one or more read-replica slaves while maintaining the data in one master database. From 37b1251b8e53807ac54481358c29cfbee35d03c1 Mon Sep 17 00:00:00 2001 From: Luram Archanjo Date: Sat, 30 May 2020 10:08:14 -0300 Subject: [PATCH 07/47] Fix "Sending a message" reference documentation code samples. Closes gh-558 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 23c92b98f..8c3b6851e 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -952,7 +952,7 @@ be resolved against the SQS API. The send method that takes no destination argum [source,java,index=0] ---- -import com.amazonaws.services.sqs.AmazonSQS; +import com.amazonaws.services.sqs.AmazonSQSAsync; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; import org.springframework.messaging.support.MessageBuilder; @@ -962,8 +962,8 @@ public class SqsQueueSender { private final QueueMessagingTemplate queueMessagingTemplate; @Autowired - public SqsQueueSender(AmazonSQS amazonSqs) { - this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs); + public SqsQueueSender(AmazonSQSAsync amazonSQSAsync) { + this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSQSAsync); } public void send(String message) { @@ -973,7 +973,7 @@ public class SqsQueueSender { ---- This example uses the `MessageBuilder` class to create a message with a string payload. The `QueueMessagingTemplate` is -constructed by passing a reference to the `AmazonSQS` client. The destination in the send method is a string value that +constructed by passing a reference to the `AmazonSQSAsync` client. The destination in the send method is a string value that must match the queue name defined on AWS. This value will be resolved at runtime by the Amazon SQS client. Optionally a `ResourceIdResolver` implementation can be passed to the `QueueMessagingTemplate` constructor to resolve resources by logical name when running inside a CloudFormation stack (see <> for more information about @@ -1003,7 +1003,7 @@ With the messaging namespace a `QueueMessagingTemplate` can be defined in an XML ---- -In this example the messaging namespace handler constructs a new `QueueMessagingTemplate`. The `AmazonSQS` client +In this example the messaging namespace handler constructs a new `QueueMessagingTemplate`. The `AmazonSQSAsync` client is automatically created and passed to the template's constructor based on the provided credentials. If the application runs inside a configured CloudFormation stack a `ResourceIdResolver` is passed to the constructor (see <> for more information about resource name resolution). From c935e726e54114b2f8ff4a9b0dced7108d32a492 Mon Sep 17 00:00:00 2001 From: kingbbode Date: Fri, 1 May 2020 17:27:46 +0900 Subject: [PATCH 08/47] Fixes SNS auto configuration when Spring WebMvc is not on the classpath. Fixes gh-503 --- .../annotation/SnsWebConfiguration.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java index 04099c96f..99d7ee4f5 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java @@ -20,8 +20,8 @@ import com.amazonaws.services.sns.AmazonSNS; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.context.annotation.ConditionalOnClass; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -33,16 +33,17 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass("org.springframework.web.servlet.config.annotation.WebMvcConfigurer") -public class SnsWebConfiguration implements WebMvcConfigurer { - - @Autowired - private AmazonSNS amazonSns; - - @Override - public void addArgumentResolvers( - List argumentResolvers) { - argumentResolvers - .add(getNotificationHandlerMethodArgumentResolver(this.amazonSns)); +public class SnsWebConfiguration { + + @Bean + public WebMvcConfigurer snsWebMvcConfigurer(AmazonSNS amazonSns) { + return new WebMvcConfigurer() { + @Override + public void addArgumentResolvers( + List argumentResolvers) { + argumentResolvers + .add(getNotificationHandlerMethodArgumentResolver(amazonSns)); + } + }; } - } From 5f5d8bc615ea44aea0eea1f272c36085df1ad17a Mon Sep 17 00:00:00 2001 From: Senthil Panneerselvam Date: Wed, 22 Apr 2020 15:40:49 +0530 Subject: [PATCH 09/47] Remove the misleading property in documentation of spring-cloud-aws-rds. Fixes gh-355 Closes gh-544 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 8c3b6851e..cb6e0c66a 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -1717,10 +1717,6 @@ outlines all properties for a data source using `test` as the instance identifie |example |description -|cloud.aws.rds.test -| -|The configuration property that configures a data source with the name test - |cloud.aws.rds.test.password |verySecret |The password for the db instance test From e805878a9268f721c2593a868877895098c39304 Mon Sep 17 00:00:00 2001 From: Lukasz Nyrc Date: Tue, 18 Jun 2019 17:15:39 +0200 Subject: [PATCH 10/47] Rename config properties in ContextCredentialsAutoConfiguration to kebab case to enable Spring Boot relaxed binding. Fixes gh-406 Closes gh-407 --- .../ContextCredentialsAutoConfiguration.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java index 54de7ec89..9e0ea5fdb 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java @@ -83,12 +83,12 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, } Boolean useDefaultCredentialsChain = this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".useDefaultAwsCredentialsChain", + AWS_CREDENTIALS_PROPERTY_PREFIX + ".use-default-aws-credentials-chain", Boolean.class, false); String accessKey = this.environment - .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".accessKey"); + .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"); String secretKey = this.environment - .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".secretKey"); + .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".secret-key"); if (useDefaultCredentialsChain && (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(secretKey))) { registerDefaultAWSCredentialsProvider(registry); @@ -96,15 +96,15 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, else { registerCredentialsProvider(registry, accessKey, secretKey, this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".instanceProfile", + AWS_CREDENTIALS_PROPERTY_PREFIX + ".instance-profile", Boolean.class, true) && !this.environment.containsProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".accessKey"), + AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".profileName", + AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-name", DEFAULT_PROFILE_NAME), this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".profilePath")); + AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-path")); } } From 4c110144dc3eaeeb23bafb669e65b326061bb3c3 Mon Sep 17 00:00:00 2001 From: tac-yacht Date: Sat, 28 Mar 2020 21:15:52 +0900 Subject: [PATCH 11/47] Add tests for relaxed binding support in "cloud.aws.credentials". Fixes gh-406 Closes gh-536 --- .../ContextCredentialsAutoConfiguration.java | 2 +- ...ntextCredentialsAutoConfigurationTest.java | 156 ++++++++++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java index 9e0ea5fdb..524bc0b9d 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java @@ -99,7 +99,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, AWS_CREDENTIALS_PROPERTY_PREFIX + ".instance-profile", Boolean.class, true) && !this.environment.containsProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), + AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), this.environment.getProperty( AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-name", DEFAULT_PROFILE_NAME), diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java index 6589656f7..24fe26e9b 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java @@ -104,6 +104,29 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr .isEqualTo("testSecretKey"); } + @Test + public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider_existAccessKeyAndSecretKey() { + // @checkstyle:on + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues + .of("cloud.aws.credentials.access-key:testAccessKey", + "cloud.aws.credentials.secret-key:testSecretKey", + "cloud.aws.credentials.use-default-aws-credentials-chain:true") + .applyTo(this.context); + this.context.refresh(); + + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) + .isEqualTo("testAccessKey"); + assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) + .isEqualTo("testSecretKey"); + } + @Test public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { this.context = new AnnotationConfigApplicationContext(); @@ -121,6 +144,23 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr .isAssignableFrom(DefaultAWSCredentialsProviderChain.class)).isTrue(); } + @Test + public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.credentials.use-default-aws-credentials-chain:true") + .applyTo(this.context); + this.context.refresh(); + + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + assertThat(awsCredentialsProvider.getClass() + .isAssignableFrom(DefaultAWSCredentialsProviderChain.class)).isTrue(); + } + // @checkstyle:off @Test public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { @@ -152,6 +192,37 @@ public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStatic } + // @checkstyle:off + @Test + public void credentialsProvider_dashSeparatedAccessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { + // @checkstyle:on + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.credentials.access-key:foo", + "cloud.aws.credentials.secret-key:bar").applyTo(this.context); + this.context.refresh(); + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProviderChain.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders.size()).isEqualTo(2); + assertThat(AWSStaticCredentialsProvider.class + .isInstance(credentialsProviders.get(0))).isTrue(); + assertThat( + ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) + .isTrue(); + + assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) + .isEqualTo("foo"); + assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) + .isEqualTo("bar"); + + } + @Test public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { this.context = new AnnotationConfigApplicationContext(); @@ -175,6 +246,29 @@ public void credentialsProvider_instanceProfileConfigured_configuresInstanceProf .isTrue(); } + @Test + public void credentialsProvider_dashSeparatedInstanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.credentials.instance-profile") + .applyTo(this.context); + this.context.refresh(); + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders.size()).isEqualTo(2); + assertThat(EC2ContainerCredentialsProviderWrapper.class + .isInstance(credentialsProviders.get(0))).isTrue(); + assertThat( + ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) + .isTrue(); + } + @Test public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() { this.context = new AnnotationConfigApplicationContext(); @@ -202,6 +296,33 @@ public void credentialsProvider_profileNameConfigured_configuresProfileCredentia .isEqualTo("test"); } + @Test + public void credentialsProvider_dashSeparatedProfileNameConfigured_configuresProfileCredentialsProvider() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.credentials.profile-name:test") + .applyTo(this.context); + this.context.refresh(); + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders.size()).isEqualTo(2); + assertThat(EC2ContainerCredentialsProviderWrapper.class + .isInstance(credentialsProviders.get(0))).isTrue(); + assertThat( + ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) + .isTrue(); + + assertThat( + ReflectionTestUtils.getField(credentialsProviders.get(1), "profileName")) + .isEqualTo("test"); + } + @Test public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() throws IOException { @@ -237,4 +358,39 @@ public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCr .isEqualTo("testSecretKey"); } + @Test + public void credentialsProvider_dashSeparatedProfileNameAndPathConfigured_configuresProfileCredentialsProvider() + throws IOException { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextCredentialsAutoConfiguration.class); + TestPropertyValues + .of("cloud.aws.credentials.profile-name:customProfile", + "cloud.aws.credentials.profile-path:" + new ClassPathResource( + getClass().getSimpleName() + "-profile", getClass()) + .getFile().getAbsolutePath()) + .applyTo(this.context); + this.context.refresh(); + AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders.size()).isEqualTo(2); + assertThat(EC2ContainerCredentialsProviderWrapper.class + .isInstance(credentialsProviders.get(0))).isTrue(); + assertThat( + ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) + .isTrue(); + + ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders + .get(1); + assertThat(provider.getCredentials().getAWSAccessKeyId()) + .isEqualTo("testAccessKey"); + assertThat(provider.getCredentials().getAWSSecretKey()) + .isEqualTo("testSecretKey"); + } + } From 6e3f32da7ea29078b9958f5912fcd845d2af8c77 Mon Sep 17 00:00:00 2001 From: Bernardo Martins Date: Wed, 13 Mar 2019 23:27:30 +0000 Subject: [PATCH 12/47] Allow ConditionalOnAwsCloudEnvironment to be used on method level. Fixes gh-389 Closes gh-424 --- .../OnAwsCloudEnvironmentCondition.java | 3 +- .../OnAwsCloudEnvironmentConditionTest.java | 116 ++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentCondition.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentCondition.java index 8fb3b96e8..9207034f9 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentCondition.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentCondition.java @@ -24,12 +24,13 @@ /** * @author Agim Emruli * @author Gleb Schukin + * @author Bernardo Martins */ public class OnAwsCloudEnvironmentCondition implements ConfigurationCondition { @Override public ConfigurationPhase getConfigurationPhase() { - return ConfigurationPhase.PARSE_CONFIGURATION; + return ConfigurationPhase.REGISTER_BEAN; } @Override diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java new file mode 100644 index 000000000..91e7c9812 --- /dev/null +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.context.annotation; + +import org.junit.Test; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Bernardo Martins + */ +public class OnAwsCloudEnvironmentConditionTest { + + @Test + public void condition_methodAnnotation_shouldNotCreateBeanFoo() { + // Arrange & Act + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + ConfigWithConditionalOnAwsCloudEnvironmentAnnotatedBean.class); + + // Assert + assertThat(applicationContext.containsBean("foo")).isFalse(); + } + + @Test + public void condition_typeAnnotation_shouldNotCreateBeanFoo() { + // Arrange & Act + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + ConfigWithConditionalOnAwsCloudEnvironmentAnnotation.class); + + // Assert + assertThat(applicationContext.containsBean("foo")).isFalse(); + } + + @Test + public void condition_methodAnnotation_shouldCreateBeanFoo() { + // Arrange & Act + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotatedBean.class); + + // Assert + assertThat(applicationContext.containsBean("foo")).isTrue(); + } + + @Test + public void condition_typeAnnotation_shouldCreateBeanFoo() { + // Arrange & Act + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotation.class); + + // Assert + assertThat(applicationContext.containsBean("foo")).isTrue(); + } + + @Configuration + protected static class ConfigWithConditionalOnAwsCloudEnvironmentAnnotatedBean { + + @Bean + @ConditionalOnAwsCloudEnvironment + public String foo() { + return "foo"; + } + + } + + @Configuration + @ConditionalOnAwsCloudEnvironment + protected static class ConfigWithConditionalOnAwsCloudEnvironmentAnnotation { + + @Bean + public String foo() { + return "foo"; + } + + } + + @Configuration + protected static class ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotatedBean { + + @Bean + @ConditionalOnMissingAwsCloudEnvironment + public String foo() { + return "foo"; + } + + } + + @Configuration + @ConditionalOnMissingAwsCloudEnvironment + protected static class ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotation { + + @Bean + public String foo() { + return "foo"; + } + + } + +} From e72a3d252209b38d4da8f56ef069a2e16abc086b Mon Sep 17 00:00:00 2001 From: Bernardo Martins Date: Thu, 14 Mar 2019 01:31:17 +0000 Subject: [PATCH 13/47] Set CloudWatchProperties default batch size to API max. Fixes gh-349 Closes gh-425 --- .../metrics/CloudWatchProperties.java | 7 ++ .../metrics/CloudWatchPropertiesTest.java | 70 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchProperties.java index ea4d73c82..4502845de 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchProperties.java @@ -24,17 +24,24 @@ * * @author Jon Schneider * @author Dawid Kublik + * @author Bernardo Martins * @since 2.0.0 */ @ConfigurationProperties(prefix = "management.metrics.export.cloudwatch") public class CloudWatchProperties extends StepRegistryProperties { + private static final int DEFAULT_BATCH_SIZE = 20; + /** * The namespace which will be used when sending metrics to CloudWatch. This property * is needed and must not be null. */ private String namespace = ""; + public CloudWatchProperties() { + setBatchSize(DEFAULT_BATCH_SIZE); + } + public String getNamespace() { return this.namespace; } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java new file mode 100644 index 000000000..c8944214a --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.autoconfigure.metrics; + +import java.util.Properties; + +import org.junit.Test; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.PropertiesPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Bernardo Martins + */ +public class CloudWatchPropertiesTest { + + @Test + public void properties_notSet_shouldHaveDefaultValues() { + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + CloudWatchPropertiesConfiguration.class); + + CloudWatchProperties cloudWatchProperties = applicationContext + .getBean(CloudWatchProperties.class); + assertThat(cloudWatchProperties.getNamespace()).isEqualTo(""); + assertThat(cloudWatchProperties.getBatchSize()).isEqualTo(20); + } + + @Test + public void properties_set_shouldOverrideValues() { + Properties properties = new Properties(); + properties.setProperty("management.metrics.export.cloudwatch.namespace", "test"); + properties.setProperty("management.metrics.export.cloudwatch.batch-size", "5"); + + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + applicationContext.getEnvironment().getPropertySources() + .addLast(new PropertiesPropertySource("test", properties)); + applicationContext.register(CloudWatchPropertiesConfiguration.class); + applicationContext.refresh(); + + CloudWatchProperties cloudWatchProperties = applicationContext + .getBean(CloudWatchProperties.class); + assertThat(cloudWatchProperties.getNamespace()).isEqualTo("test"); + assertThat(cloudWatchProperties.getBatchSize()).isEqualTo(5); + } + + @Configuration + @EnableConfigurationProperties(CloudWatchProperties.class) + protected static class CloudWatchPropertiesConfiguration { + + } + +} From 159200b9d418cbcf178a8d090a166e560426abe7 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 31 May 2020 11:29:15 +0200 Subject: [PATCH 14/47] Add option to use default AWS region provider chain. Fixes gh-553 Fixes gh-120 Closes gh-559 Closes gh-560 --- docs/src/main/asciidoc/_configprops.adoc | 11 ++--- docs/src/main/asciidoc/spring-cloud-aws.adoc | 4 ++ .../ContextCredentialsAutoConfiguration.java | 10 +++-- ...ontextRegionProviderAutoConfiguration.java | 17 +++++--- .../properties/AwsRegionProperties.java | 15 +++++++ ...ntextCredentialsAutoConfigurationTest.java | 3 +- ...xtRegionProviderAutoConfigurationTest.java | 23 +++++++++++ .../ContextRegionConfigurationRegistrar.java | 5 ++- .../annotation/EnableContextRegion.java | 20 ++++++++-- .../support/ContextConfigurationUtils.java | 8 ++-- ...ntextRegionConfigurationRegistrarTest.java | 21 ++++++++++ ...DefaultAwsRegionProviderChainDelegate.java | 40 +++++++++++++++++++ .../annotation/SnsWebConfiguration.java | 1 + 13 files changed, 156 insertions(+), 22 deletions(-) create mode 100644 spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/region/DefaultAwsRegionProviderChainDelegate.java diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index a6a2e0356..af4519d60 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -1,18 +1,18 @@ |=== |Name | Default | Description -|aws.paramstore.default-context | application | +|aws.paramstore.default-context | application | |aws.paramstore.enabled | true | Is AWS Parameter Store support enabled. |aws.paramstore.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings. |aws.paramstore.name | | Alternative to spring.application.name to use in looking up values in AWS Parameter Store. |aws.paramstore.prefix | /config | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config". -|aws.paramstore.profile-separator | _ | -|aws.secretsmanager.default-context | application | +|aws.paramstore.profile-separator | _ | +|aws.secretsmanager.default-context | application | |aws.secretsmanager.enabled | true | Is AWS Secrets Manager support enabled. |aws.secretsmanager.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings. |aws.secretsmanager.name | | Alternative to spring.application.name to use in looking up values in AWS Secrets Manager. |aws.secretsmanager.prefix | /secret | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config". -|aws.secretsmanager.profile-separator | _ | +|aws.secretsmanager.profile-separator | _ | |cloud.aws.credentials.access-key | | The access key to be used with a static provider. |cloud.aws.credentials.instance-profile | true | Configures an instance profile credentials provider with no further configuration. |cloud.aws.credentials.profile-name | | The AWS profile name. @@ -23,7 +23,8 @@ |cloud.aws.loader.max-pool-size | | The maximum pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize(int) |cloud.aws.loader.queue-capacity | | The maximum queue capacity for backed up S3 requests. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity(int) |cloud.aws.region.auto | true | Enables automatic region detection based on the EC2 meta data service. -|cloud.aws.region.static | | +|cloud.aws.region.use-default-aws-region-chain | false | Use the DefaultAwsRegion Chain instead of configuring a custom region provider chain. +|cloud.aws.region.static | | |cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application. |cloud.aws.stack.name | myStackName | The name of the manually configured stack name that will be used to retrieve the resources. diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index cb6e0c66a..6c9e42ae9 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -315,6 +315,10 @@ The properties to configure the region are shown below |true |Enables automatic region detection based on the EC2 meta data service +|cloud.aws.region.useDefaultAwsRegionChain +|true +|Use the DefaultAWSRegion Chain instead of configuring a custom region chain + |cloud.aws.region.static |eu-west-1 |Configures a static region for the application. Possible regions are (currently) us-east-1, us-west-1, us-west-2, diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java index 524bc0b9d..56fd92d6a 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java @@ -82,9 +82,11 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, return; } - Boolean useDefaultCredentialsChain = this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".use-default-aws-credentials-chain", - Boolean.class, false); + Boolean useDefaultCredentialsChain = this.environment + .getProperty( + AWS_CREDENTIALS_PROPERTY_PREFIX + + ".use-default-aws-credentials-chain", + Boolean.class, false); String accessKey = this.environment .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"); String secretKey = this.environment @@ -99,7 +101,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, AWS_CREDENTIALS_PROPERTY_PREFIX + ".instance-profile", Boolean.class, true) && !this.environment.containsProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), + AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), this.environment.getProperty( AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-name", DEFAULT_PROFILE_NAME), diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java index c7521b847..ac2e8b686 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java @@ -70,12 +70,19 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, return; } - registerRegionProvider(registry, this.environment.getProperty( + boolean useDefaultRegionChain = this.environment.getProperty( + AWS_REGION_PROPERTIES_PREFIX + ".use-default-aws-region-chain", + Boolean.class, false); + + String staticRegion = this.environment + .getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static"); + + boolean autoDetect = this.environment.getProperty( AWS_REGION_PROPERTIES_PREFIX + ".auto", Boolean.class, true) - && !StringUtils.hasText(this.environment - .getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static")), - this.environment - .getProperty(AWS_REGION_PROPERTIES_PREFIX + ".static")); + && !StringUtils.hasText(staticRegion); + + registerRegionProvider(registry, autoDetect, useDefaultRegionChain, + staticRegion); } @Override diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionProperties.java index 4e4a23496..155c540af 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionProperties.java @@ -20,6 +20,7 @@ * Properties related to AWS region configuration. * * @author Tom Gianos + * @author Maciej Walkowiak * @since 2.0.2 * @see org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration */ @@ -30,6 +31,12 @@ public class AwsRegionProperties { */ private boolean auto = true; + /** + * Whether default AWS SDK region provider chain should be used when auto is set to + * true. + */ + private boolean useDefaultAwsRegionChain; + /** * Configures a static region for the application. Possible regions are (currently) * us-east-1, us-west-1, us-west-2, eu-west-1, eu-central-1, ap-southeast-1, @@ -60,4 +67,12 @@ public void setStatic(String staticRegion) { this.staticRegion = staticRegion; } + public boolean isUseDefaultAwsRegionChain() { + return useDefaultAwsRegionChain; + } + + public void setUseDefaultAwsRegionChain(boolean useDefaultAwsRegionChain) { + this.useDefaultAwsRegionChain = useDefaultAwsRegionChain; + } + } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java index 24fe26e9b..3f4ec3e35 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java @@ -148,7 +148,8 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { this.context = new AnnotationConfigApplicationContext(); this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.use-default-aws-credentials-chain:true") + TestPropertyValues + .of("cloud.aws.credentials.use-default-aws-credentials-chain:true") .applyTo(this.context); this.context.refresh(); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java index acfd35b43..745116481 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java @@ -21,16 +21,20 @@ import org.junit.After; import org.junit.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.cloud.aws.core.region.DefaultAwsRegionProviderChainDelegate; import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider; import org.springframework.cloud.aws.core.region.StaticRegionProvider; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Agim Emruli * @author Petromir Dzhunev + * @author Maciej Walkowiak */ public class ContextRegionProviderAutoConfigurationTest { @@ -93,4 +97,23 @@ public void regionProvider_staticRegionConfigured_staticRegionProviderWithConfig .isEqualTo(Region.getRegion(Regions.EU_WEST_1)); } + @Test + public void regionProvider_autoDetectionAndDefaultChainConfigured_DefaultAwsRegionProviderChainDelegateConfigured() { + // Arrange + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextRegionProviderAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.region.auto:true").applyTo(this.context); + TestPropertyValues.of("cloud.aws.region.useDefaultAwsRegionChain:true") + .applyTo(this.context); + + // Act + this.context.refresh(); + + // Assert + assertThat(this.context.getBean(DefaultAwsRegionProviderChainDelegate.class)) + .isNotNull(); + assertThatThrownBy(() -> this.context.getBean(Ec2MetadataRegionProvider.class)) + .isInstanceOf(NoSuchBeanDefinitionException.class); + } + } diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrar.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrar.java index 09e0b4182..7f9cb4591 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrar.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrar.java @@ -43,9 +43,12 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, + importingClassMetadata.getClassName()); boolean autoDetect = annotationAttributes.getBoolean("autoDetect"); + boolean useDefaultAwsRegionChain = annotationAttributes + .getBoolean("useDefaultAwsRegionChain"); String configuredRegion = annotationAttributes.getString("region"); - registerRegionProvider(registry, autoDetect, configuredRegion); + registerRegionProvider(registry, autoDetect, useDefaultAwsRegionChain, + configuredRegion); } } diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/EnableContextRegion.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/EnableContextRegion.java index 63eb5edf5..563c4a29b 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/EnableContextRegion.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/EnableContextRegion.java @@ -21,6 +21,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import com.amazonaws.regions.AwsRegionProviderChain; + import org.springframework.context.annotation.Import; /** @@ -29,11 +31,15 @@ * Service clients that are created inside the application context (by the Spring Cloud * AWS classes). A region can be either manually configured * {@link EnableContextRegion#region()} with a constant expression, dynamic expression - * (using a SpEL expression) or a place holder. The region can also be dynamically - * retrieved from the EC2 instance meta-data if the application context is running inside - * a EC2 instance by enabling the {@link EnableContextRegion#autoDetect()} attribute. + * (using a SpEL expression) or a place holder. If the application context is running + * inside a EC2 instance The region can also be dynamically retrieved from the EC2 + * instance meta-data by enabling the {@link EnableContextRegion#autoDetect()} attribute + * or from the default AWS SDK {@link AwsRegionProviderChain} by enabling + * {@link EnableContextRegion#autoDetect()} and + * {@link EnableContextRegion#useDefaultAwsRegionChain()}. * * @author Agim Emruli + * @author Maciej Walkowiak */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @@ -58,4 +64,12 @@ */ boolean autoDetect() default false; + /** + * Whether default AWS SDK region provider chain should be used when auto is set to + * true. + * @return - if default AWS SDK region provider chain should be used for region + * resolution. + */ + boolean useDefaultAwsRegionChain() default false; + } diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java index 144bafffb..461dd9e4e 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.ManagedList; import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; import org.springframework.cloud.aws.core.credentials.CredentialsProviderFactoryBean; +import org.springframework.cloud.aws.core.region.DefaultAwsRegionProviderChainDelegate; import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider; import org.springframework.cloud.aws.core.region.StaticRegionProvider; import org.springframework.util.StringUtils; @@ -55,7 +56,7 @@ private ContextConfigurationUtils() { } public static void registerRegionProvider(BeanDefinitionRegistry registry, - boolean autoDetect, String configuredRegion) { + boolean autoDetect, boolean useDefaultRegionChain, String configuredRegion) { if (autoDetect && StringUtils.hasText(configuredRegion)) { throw new IllegalArgumentException( "No region must be configured if autoDetect is defined as true"); @@ -64,8 +65,9 @@ public static void registerRegionProvider(BeanDefinitionRegistry registry, AbstractBeanDefinition beanDefinition; if (autoDetect) { - beanDefinition = BeanDefinitionBuilder - .genericBeanDefinition(Ec2MetadataRegionProvider.class) + beanDefinition = BeanDefinitionBuilder.genericBeanDefinition( + useDefaultRegionChain ? DefaultAwsRegionProviderChainDelegate.class + : Ec2MetadataRegionProvider.class) .getBeanDefinition(); } else if (StringUtils.hasText(configuredRegion)) { diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java index b24b7b0f8..51f8efbfa 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java @@ -82,6 +82,21 @@ public void regionProvider_withAutoDetectedRegion_dynamicRegionProviderConfigure assertThat(staticRegionProvider).isNotNull(); } + @Test + public void regionProvider_withAutoDetectedRegionAndDefaultChain_defaulAwsChainRegionProviderConfigured() + throws Exception { + // Arrange + this.context = new AnnotationConfigApplicationContext( + ApplicationConfigurationWithDynamicRegionProvider.class); + + // Act + Ec2MetadataRegionProvider staticRegionProvider = this.context + .getBean(Ec2MetadataRegionProvider.class); + + // Assert + assertThat(staticRegionProvider).isNotNull(); + } + @Test public void regionProvider_withExpressionConfiguredRegion_staticRegionProviderConfigured() throws Exception { @@ -219,4 +234,10 @@ static class ApplicationConfigurationWithWrongRegion { } + @Configuration(proxyBeanMethods = false) + @EnableContextRegion(autoDetect = true, useDefaultAwsRegionChain = true) + static class ApplicationConfigurationWithAutoDetectionAndDefaultChain { + + } + } diff --git a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/region/DefaultAwsRegionProviderChainDelegate.java b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/region/DefaultAwsRegionProviderChainDelegate.java new file mode 100644 index 000000000..0d7052ca7 --- /dev/null +++ b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/region/DefaultAwsRegionProviderChainDelegate.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.core.region; + +import com.amazonaws.regions.DefaultAwsRegionProviderChain; +import com.amazonaws.regions.Region; +import com.amazonaws.regions.RegionUtils; + +/** + * {@link RegionProvider} implementation that delegates to + * {@link DefaultAwsRegionProviderChain} enabling loading region configuration from + * environment variables, system properties, AWS profile, and instance metadata. + * + * @author Maciej Walkowiak + * @since 1.0 + */ +public class DefaultAwsRegionProviderChainDelegate implements RegionProvider { + + private final DefaultAwsRegionProviderChain delegate = new DefaultAwsRegionProviderChain(); + + @Override + public Region getRegion() { + return RegionUtils.getRegion(delegate.getRegion()); + } + +} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java index 99d7ee4f5..0e0ea3883 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsWebConfiguration.java @@ -46,4 +46,5 @@ public void addArgumentResolvers( } }; } + } From f6100dd272a085115e7711c5cff022dc1af6e106 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Thu, 27 Feb 2020 16:10:11 -0600 Subject: [PATCH 15/47] Add logging to AWSParameterStorePropertySource. Closes gh-529 Fixes gh-509 Fixes gh-527 Co-authored-by: Maciej Walkowiak --- docs/src/main/asciidoc/_configprops.adoc | 12 ++++++------ docs/src/main/asciidoc/spring-cloud-aws.adoc | 11 +++++++++++ .../aws/paramstore/AwsParamStorePropertySource.java | 7 +++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index af4519d60..fbe8c4024 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -1,18 +1,18 @@ |=== |Name | Default | Description -|aws.paramstore.default-context | application | +|aws.paramstore.default-context | application | |aws.paramstore.enabled | true | Is AWS Parameter Store support enabled. |aws.paramstore.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings. |aws.paramstore.name | | Alternative to spring.application.name to use in looking up values in AWS Parameter Store. |aws.paramstore.prefix | /config | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config". -|aws.paramstore.profile-separator | _ | -|aws.secretsmanager.default-context | application | +|aws.paramstore.profile-separator | _ | +|aws.secretsmanager.default-context | application | |aws.secretsmanager.enabled | true | Is AWS Secrets Manager support enabled. |aws.secretsmanager.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings. |aws.secretsmanager.name | | Alternative to spring.application.name to use in looking up values in AWS Secrets Manager. |aws.secretsmanager.prefix | /secret | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config". -|aws.secretsmanager.profile-separator | _ | +|aws.secretsmanager.profile-separator | _ | |cloud.aws.credentials.access-key | | The access key to be used with a static provider. |cloud.aws.credentials.instance-profile | true | Configures an instance profile credentials provider with no further configuration. |cloud.aws.credentials.profile-name | | The AWS profile name. @@ -23,8 +23,8 @@ |cloud.aws.loader.max-pool-size | | The maximum pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize(int) |cloud.aws.loader.queue-capacity | | The maximum queue capacity for backed up S3 requests. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity(int) |cloud.aws.region.auto | true | Enables automatic region detection based on the EC2 meta data service. -|cloud.aws.region.use-default-aws-region-chain | false | Use the DefaultAwsRegion Chain instead of configuring a custom region provider chain. -|cloud.aws.region.static | | +|cloud.aws.region.static | | +|cloud.aws.region.use-default-aws-region-chain | false | Whether default AWS SDK region provider chain should be used when auto is set to true. |cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application. |cloud.aws.stack.name | myStackName | The name of the manually configured stack name that will be used to retrieve the resources. diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 6c9e42ae9..70df3b5fb 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -664,6 +664,17 @@ You can configure the following settings in a Spring Cloud `bootstrap.properties |Can be used to disable the Parameter Store Configuration support even though the auto-configuration is on the classpath. |=== +[TIP] +==== +In order to find out which properties are retrieved from AWS Parameter Store on application startup, +turn on `DEBUG` logging on `org.springframework.cloud.aws.paramstore.AwsParamStorePropertySource` class. + +[source,indent=0] +---- +logging.level.org.springframework.cloud.aws.paramstore.AwsParamStorePropertySource=debug +---- +==== + === Integrating your Spring Cloud application with the AWS Secrets Manager Spring Cloud provides support for centralized configuration, which can be read and made available as a regular Spring diff --git a/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySource.java b/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySource.java index f63784884..68610c730 100644 --- a/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySource.java +++ b/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySource.java @@ -24,6 +24,8 @@ import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest; import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult; import com.amazonaws.services.simplesystemsmanagement.model.Parameter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.env.EnumerablePropertySource; @@ -37,6 +39,9 @@ public class AwsParamStorePropertySource extends EnumerablePropertySource { + private static final Logger LOGGER = LoggerFactory + .getLogger(AwsParamStorePropertySource.class); + private String context; private Map properties = new LinkedHashMap<>(); @@ -69,6 +74,8 @@ private void getParameters(GetParametersByPathRequest paramsRequest) { .getParametersByPath(paramsRequest); for (Parameter parameter : paramsResult.getParameters()) { String key = parameter.getName().replace(context, "").replace('/', '.'); + LOGGER.debug("Populating property retrieved from AWS Parameter Store: {}", + key); properties.put(key, parameter.getValue()); } if (paramsResult.getNextToken() != null) { From 6da992581b7d3f67f32a19acfa9db82134e255c0 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 31 May 2020 14:47:23 +0200 Subject: [PATCH 16/47] Update documentation on how to hide warning message logged by AWS SDK on application startup. Fixes gh-556 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 70df3b5fb..90c134e13 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -108,6 +108,18 @@ use of the modules. A typical XML configuration to use Spring Cloud AWS is outli ---- +[TIP] +==== +On application startup, for its internal purposes Spring Cloud AWS performs a check if application runs in AWS cloud environment +by using `EC2MetadataUtils` class provided by AWS SDK. Starting from version 1.11.678, AWS SDK logs a warning message with exception when this check is made outside of AWS environment. +This warning message can be hidden by setting `ERROR` logging level on `com.amazonaws.util.EC2MetadataUtils` class. + +[source,indent=0] +---- +logging.level.com.amazonaws.util.EC2MetadataUtils=error +---- +==== + ==== SDK credentials configuration In order to make calls to the Amazon Web Service the credentials must be configured for the the Amazon SDK. Spring Cloud AWS provides support to configure an application context specific credentials that are used for _each_ service call for requests done From 8caf8115e547ea58bd11f4b83a58ba54f8c5efe5 Mon Sep 17 00:00:00 2001 From: Thusitha Nuwan Date: Sun, 31 May 2020 20:41:59 +0800 Subject: [PATCH 17/47] Fix typo in the exception text Fixes gh-519 Closes gh-561 --- .../cloud/aws/messaging/AbstractContainerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java index a5025fa88..c8eb53594 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java @@ -47,7 +47,7 @@ public void tearDown() throws Exception { this.simpleMessageListenerContainer.stop(countDownLatch::countDown); if (!countDownLatch.await(15, TimeUnit.SECONDS)) { - throw new Exception("Couldn't stop container withing 15 seconds"); + throw new Exception("Couldn't stop container within 15 seconds"); } } } From 7a052a5984d5bd917231dc0e0897109e4604d18b Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 31 May 2020 22:25:00 +0200 Subject: [PATCH 18/47] Bump AWS Java SDK dependency version to 1.11.792. Fixes gh-482 --- spring-cloud-aws-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index f90132fdd..818948ec3 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -31,7 +31,7 @@ Spring Cloud AWS Dependencies Spring Cloud AWS Dependencies - 1.11.415 + 1.11.792 1.1.1 1.0.0 From f2ab80781ea20c207beed66b59612bfffa1eaae4 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 31 May 2020 22:34:45 +0200 Subject: [PATCH 19/47] Update reference documentation on how to upgrade AWS SDK dependency. --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 90c134e13..1cfe73d33 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -87,6 +87,26 @@ For milestones: ---- +=== Amazon SDK dependency version management + +Amazon SDK is released more frequently than Spring Cloud AWS. If you need to use newer version of AWS SDK than one configured by Spring Cloud AWS +add AWS SDK BOM to dependency management section making sure it is declared before any other BOM dependency that configures AWS SDK dependencies. + +[source,xml,indent=0] +---- + + + + com.amazonaws + aws-java-sdk-bom + ${aws-java-sdk.version} + pom + import + + + +---- + === Amazon SDK configuration The Spring Cloud AWS configuration is currently done using custom elements provided by Spring Cloud AWS namespaces. JavaConfig will be supported soon. The configuration setup is done directly in Spring XML configuration files From 58e636d3aa4bbfba0d303d3dae00dbc8f80b74ce Mon Sep 17 00:00:00 2001 From: giova333 Date: Mon, 1 Jun 2020 10:43:21 +0300 Subject: [PATCH 20/47] Fix S3 object key encoding in `SimpleStorageResource.getURL`. Fixes gh-483 Closes gh-562 --- .../cloud/aws/core/io/s3/SimpleStorageResource.java | 6 +++++- .../aws/core/io/s3/SimpleStorageResourceTest.java | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java index 0c58764a1..c41725d48 100644 --- a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java +++ b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java @@ -24,6 +24,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -139,8 +141,10 @@ public String getFilename() throws IllegalStateException { @Override public URL getURL() throws IOException { Region region = this.amazonS3.getRegion().toAWSRegion(); + String encodedObjectName = URLEncoder.encode(this.objectName, + StandardCharsets.UTF_8.toString()); return new URL("https", region.getServiceEndpoint(AmazonS3Client.S3_SERVICE_NAME), - "/" + this.bucketName + "/" + this.objectName); + "/" + this.bucketName + "/" + encodedObjectName); } @Override diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java index 6549927c5..e4e94aa07 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URI; import java.net.URL; import java.util.Date; @@ -297,4 +298,15 @@ public void writeFile_forNewFile_writesFileContent() throws Exception { // Assert } + @Test + public void getUri_encodes_objectName() throws Exception { + AmazonS3 s3 = mock(AmazonS3.class); + when(s3.getRegion()).thenReturn(Region.US_West_2); + SimpleStorageResource resource = new SimpleStorageResource(s3, "bucketName", + "some/[objectName]", new SyncTaskExecutor()); + + assertThat(resource.getURI()).isEqualTo(new URI( + "https://s3.us-west-2.amazonaws.com/bucketName/some%2F%5BobjectName%5D")); + } + } From deb9088be6d3b7f01218ef96b74c3981678a26e2 Mon Sep 17 00:00:00 2001 From: MD Sayem Ahmed Date: Fri, 29 Mar 2019 03:20:47 +0100 Subject: [PATCH 21/47] Fix duplicate error logging when processing exception thrown in SQS listener. This commit fixes this issue by delegating exception processing to AbstractMethodMessageHandler only when there is a configured handler. If there is none, exception is logged. Fixes gh-394 Closes gh-465 Co-authored-by: Maciej Walkowiak --- .../listener/QueueMessageHandler.java | 11 ++++- .../SimpleMessageListenerContainer.java | 9 +--- .../listener/QueueMessageHandlerTest.java | 44 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java index 168d1c9a8..f4cf151c5 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java @@ -52,6 +52,7 @@ import org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; +import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; import org.springframework.util.ClassUtils; import org.springframework.util.comparator.ComparableComparator; import org.springframework.validation.Errors; @@ -233,7 +234,15 @@ protected void handleNoMatch(Set ts, String lookupDestinatio @Override protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message message) { - super.processHandlerMethodException(handlerMethod, ex, message); + InvocableHandlerMethod exceptionHandlerMethod = getExceptionHandlerMethod( + handlerMethod, ex); + if (exceptionHandlerMethod != null) { + super.processHandlerMethodException(handlerMethod, ex, message); + } + else { + this.logger.error("An exception occurred while invoking the handler method", + ex); + } throw new MessagingException( "An exception occurred while invoking the handler method", ex); } diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainer.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainer.java index 48765ad7b..cb55be6d5 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainer.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainer.java @@ -418,7 +418,7 @@ public void run() { applyDeletionPolicyOnSuccess(receiptHandle); } catch (MessagingException messagingException) { - applyDeletionPolicyOnError(receiptHandle, messagingException); + applyDeletionPolicyOnError(receiptHandle); } } @@ -430,17 +430,12 @@ private void applyDeletionPolicyOnSuccess(String receiptHandle) { } } - private void applyDeletionPolicyOnError(String receiptHandle, - MessagingException messagingException) { + private void applyDeletionPolicyOnError(String receiptHandle) { if (this.deletionPolicy == SqsMessageDeletionPolicy.ALWAYS || (this.deletionPolicy == SqsMessageDeletionPolicy.NO_REDRIVE && !this.hasRedrivePolicy)) { deleteMessage(receiptHandle); } - else if (this.deletionPolicy == SqsMessageDeletionPolicy.ON_SUCCESS) { - getLogger().error("Exception encountered while processing message.", - messagingException); - } } private void deleteMessage(String receiptHandle) { diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java index 61f28165e..6f55b1aef 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java @@ -70,6 +70,7 @@ import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -566,6 +567,40 @@ public void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_ .containsAll(Arrays.asList("queueOne", "queueTwo"))).isTrue(); } + @Test + public void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustBeLogged() { + // Arrange + StaticApplicationContext applicationContext = new StaticApplicationContext(); + applicationContext.registerSingleton("sqsListenerWithoutMessageExceptionHandler", + SqsListenerWithoutMessageExceptionHandler.class); + applicationContext.registerBeanDefinition("queueMessageHandler", + getQueueMessageHandlerBeanDefinition()); + applicationContext.refresh(); + MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class); + + LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + ListAppender appender = new ListAppender<>(); + appender.start(); + Logger log = logContext.getLogger(QueueMessageHandler.class); + log.setLevel(Level.ERROR); + log.addAppender(appender); + appender.setContext(log.getLoggerContext()); + + // Act + try { + messageHandler.handleMessage(MessageBuilder.withPayload("testContent") + .setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive") + .build()); + fail(); + } + catch (MessagingException e) { + // ignore + } + + // Assert + assertThat(appender.list).hasSize(1); + } + @SuppressWarnings("UnusedDeclaration") private static class IncomingMessageHandler { @@ -604,6 +639,15 @@ private String getLastReceivedMessage() { } + private static class SqsListenerWithoutMessageExceptionHandler { + + @SqsListener("receive") + public String receive(String value) { + throw new RuntimeException("test exception"); + } + + } + private static class IncomingMessageHandlerWithMultipleQueueNames { private String lastReceivedMessage; From 76df24cd2797d2eab5ab8df5bd2b0a54f36203ec Mon Sep 17 00:00:00 2001 From: Anthony Foulfoin Date: Tue, 25 Jun 2019 18:20:50 +0200 Subject: [PATCH 22/47] Allow to specify PropertySource name returned by AwsSecretsManagerPropertySourceLocator. Fixes gh-472 Closes gh-473 --- ...wsSecretsManagerPropertySourceLocator.java | 13 ++-- ...cretsManagerPropertySourceLocatorTest.java | 71 +++++++++++++++++++ 2 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java diff --git a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java index b59da682a..aea23d3c2 100644 --- a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java +++ b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java @@ -43,6 +43,8 @@ */ public class AwsSecretsManagerPropertySourceLocator implements PropertySourceLocator { + private String propertySourceName; + private AWSSecretsManager smClient; private AwsSecretsManagerProperties properties; @@ -51,12 +53,16 @@ public class AwsSecretsManagerPropertySourceLocator implements PropertySourceLoc private Log logger = LogFactory.getLog(getClass()); - public AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient, - AwsSecretsManagerProperties properties) { + public AwsSecretsManagerPropertySourceLocator(String propertySourceName, AWSSecretsManager smClient, AwsSecretsManagerProperties properties) { + this.propertySourceName = propertySourceName; this.smClient = smClient; this.properties = properties; } + public AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient, AwsSecretsManagerProperties properties) { + this("aws-secrets-manager", smClient, properties); + } + public List getContexts() { return contexts; } @@ -89,8 +95,7 @@ public PropertySource locate(Environment environment) { Collections.reverse(this.contexts); - CompositePropertySource composite = new CompositePropertySource( - "aws-secrets-manager"); + CompositePropertySource composite = new CompositePropertySource(this.propertySourceName); for (String propertySourceContext : this.contexts) { try { diff --git a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java new file mode 100644 index 000000000..d487fb32a --- /dev/null +++ b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.secretsmanager; + +import com.amazonaws.services.secretsmanager.AWSSecretsManager; +import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest; +import com.amazonaws.services.secretsmanager.model.GetSecretValueResult; +import org.junit.Test; + +import org.springframework.core.env.PropertySource; +import org.springframework.mock.env.MockEnvironment; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Unit test for {@link AwsSecretsManagerPropertySourceLocator}. + * + * @author Anthony Foulfoin + */ +public class AwsSecretsManagerPropertySourceLocatorTest { + + private AWSSecretsManager smClient = mock(AWSSecretsManager.class); + + private MockEnvironment env = new MockEnvironment(); + + @Test + public void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecifiedName() { + GetSecretValueResult secretValueResult = new GetSecretValueResult(); + secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); + when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult); + + AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); + AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator("my-name", smClient, properties); + + PropertySource propertySource = locator.locate(env); + + assertThat(propertySource.getName()).isEqualTo("my-name"); + } + + @Test + public void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() { + GetSecretValueResult secretValueResult = new GetSecretValueResult(); + secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); + when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult); + + AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); + AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(smClient, properties); + + PropertySource propertySource = locator.locate(env); + + assertThat(propertySource.getName()).isEqualTo("aws-secrets-manager"); + } + +} From eb4d65ad1544ff0502fbf112e80f18a7d8e900ad Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sat, 6 Jun 2020 20:59:15 +0200 Subject: [PATCH 23/47] Add a dependency to JUnit 4. Spring Boot 2.4 has moved from providing automatic support for JUnit 4. For now we must declare it explicitly and in the future migrate to JUnit 5. --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 3724cc666..94f767b64 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,11 @@ spring-boot-starter-test test + + junit + junit + test + From f61178ddf2b0be4e297b3551b448e509b2680d16 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sat, 6 Jun 2020 22:41:17 +0200 Subject: [PATCH 24/47] Document default credentials chain for auto-configuration. Fixes gh-470 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 1cfe73d33..619d324ad 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -307,25 +307,40 @@ Spring Boot provides a standard way to define properties with property file or Y AWS provides support to configure the credential information with the Spring Boot application configuration files. Spring Cloud AWS provides the following properties to configure the credentials setup for the whole application. +Unless `cloud.aws.credentials.use-default-aws-credentials-chain` is set to `true`, Spring Cloud AWS configures following +credentials chain: + +1. `AWSStaticCredentialsProvider` if `cloud.aws.credentials.access-key` is provided +2. `EC2ContainerCredentialsProviderWrapper` unless `cloud.aws.credentials.instance-profile` is set to `false` +3. `ProfileCredentialsProvider` + [cols="3*", options="header"] |=== |property |example |description -|cloud.aws.credentials.accessKey +|cloud.aws.credentials.access-key |AKIAIOSFODNN7EXAMPLE |The access key to be used with a static provider -|cloud.aws.credentials.secretKey +|cloud.aws.credentials.secret-key |wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |The secret key to be used with a static provider -|cloud.aws.credentials.instanceProfile +|cloud.aws.credentials.instance-profile |true |Configures an instance profile credentials provider with no further configuration -|cloud.aws.credentials.useDefaultAwsCredentialsChain +|cloud.aws.credentials.profile-name +|default +|The name of a configuration profile in the specified configuration file + +|cloud.aws.credentials.profile-path +|`~/.aws/credentials` +|The file path where the profile configuration file is located. Defaults to `~/.aws/credentials` if value is not provided + +|cloud.aws.credentials.use-default-aws-credentials-chain |true |Use the DefaultAWSCredentials Chain instead of configuring a custom credentials chain |=== @@ -347,7 +362,7 @@ The properties to configure the region are shown below |true |Enables automatic region detection based on the EC2 meta data service -|cloud.aws.region.useDefaultAwsRegionChain +|cloud.aws.region.use-default-aws-region-chain |true |Use the DefaultAWSRegion Chain instead of configuring a custom region chain From 211990cfb814387451b3bdfe91f13647ad502068 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 7 Jun 2020 00:08:09 +0200 Subject: [PATCH 25/47] Add CloudWatch integration documentation to the reference. Fixes gh-402 --- docs/src/main/asciidoc/spring-cloud-aws.adoc | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index 619d324ad..b2deccfe9 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -2334,6 +2334,41 @@ public class SimpleResourceLoadingBean { } } ---- +== CloudWatch Metrics +Spring Cloud AWS provides Spring Boot auto-configuration for Micrometer CloudWatch integration. +To send metrics to CloudWatch add a dependency to `spring-cloud-aws-actuator` module: + +[source,xml,indent=0] +---- + + org.springframework.cloud + spring-cloud-aws-actuator + +---- + +Additionally CloudWatch integration requires a value provided for `management.metrics.export.cloudwatch.namespace` configuration property. + +Following configuration properties are available to configure CloudWatch integration: + +[cols="3*", options="header"] +|=== +|property +|default +|description + +|management.metrics.export.cloudwatch.namespace +| +|The namespace which will be used when sending metrics to CloudWatch. This property is needed and must not be null. + +|management.metrics.export.cloudwatch.enabled +|true +|If CloudWatch integration should be enabled. This property should be likely set to `false` for a local development profile. + +|management.metrics.export.cloudwatch.step +|1m +|The interval at which metrics are sent to CloudWatch. The default is 1 minute. +|=== + == Configuration properties To see the list of all Spring Cloud AWS related configuration properties please check link:appendix.html[the Appendix page]. From 2a59abfe230d6d5a9bab11eadb1cefd5710feb69 Mon Sep 17 00:00:00 2001 From: Thusitha Nuwan Date: Sat, 6 Jun 2020 22:15:55 +0800 Subject: [PATCH 26/47] Add a method to get S3 URI from a SimpleStorageResource. Fixes gh-361 Closes gh-565 --- .../aws/core/io/s3/SimpleStorageResource.java | 11 +++++++++++ .../aws/core/io/s3/SimpleStorageResourceTest.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java index c41725d48..aeffbd19d 100644 --- a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java +++ b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResource.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -147,6 +149,15 @@ public URL getURL() throws IOException { "/" + this.bucketName + "/" + encodedObjectName); } + public URI getS3Uri() { + try { + return new URI("s3", "//" + this.bucketName + "/" + this.objectName, null); + } + catch (URISyntaxException e) { + throw new RuntimeException("Failed to resolve s3:// uri", e); + } + } + @Override public File getFile() throws IOException { throw new UnsupportedOperationException( diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java index e4e94aa07..1363f07be 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java @@ -232,6 +232,21 @@ public void getUrl_existingObject_returnsUrlWithS3Prefix() throws Exception { } + @Test + public void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception { + + AmazonS3Client amazonS3 = mock(AmazonS3Client.class); + + // Act + SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3, + "bucket", "object", new SyncTaskExecutor()); + + // Assert + assertThat(simpleStorageResource.getS3Uri()) + .isEqualTo(new URI("s3://bucket/object")); + + } + @Test public void getFile_existingObject_throwsMeaningFullException() throws Exception { From 647375b43e13dd09114d7b2a3d8cbfd26a6bacda Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 7 Jun 2020 22:06:14 +0200 Subject: [PATCH 27/47] Fix StackResourceRegistry creation when CloudFormation support is turned off. Fixes gh-496 --- docs/src/main/asciidoc/_configprops.adoc | 2 +- .../ContextStackAutoConfiguration.java | 48 +++++++++------- .../properties/AwsStackProperties.java | 56 +++++++++++++++++++ ...itional-spring-configuration-metadata.json | 14 +---- .../ContextStackAutoConfigurationTest.java | 42 +++++++++++++- 5 files changed, 128 insertions(+), 34 deletions(-) create mode 100644 spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsStackProperties.java diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index fbe8c4024..5825aa564 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -26,6 +26,6 @@ |cloud.aws.region.static | | |cloud.aws.region.use-default-aws-region-chain | false | Whether default AWS SDK region provider chain should be used when auto is set to true. |cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application. -|cloud.aws.stack.name | myStackName | The name of the manually configured stack name that will be used to retrieve the resources. +|cloud.aws.stack.name | | The name of the manually configured stack name that will be used to retrieve the resources. |=== diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java index 4c9b7e069..4fcdc80c6 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java @@ -22,33 +22,38 @@ import com.amazonaws.services.ec2.AmazonEC2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.aws.autoconfigure.context.properties.AwsStackProperties; import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient; import org.springframework.cloud.aws.context.config.annotation.ContextDefaultConfigurationRegistrar; import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; import org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider; +import org.springframework.cloud.aws.core.env.stack.config.StackNameProvider; import org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean; import org.springframework.cloud.aws.core.env.stack.config.StaticStackNameProvider; import org.springframework.cloud.aws.core.region.RegionProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.core.env.Environment; -import org.springframework.util.StringUtils; /** * @author Agim Emruli + * @author Maciej Walkowiak */ @Configuration(proxyBeanMethods = false) @Import({ ContextCredentialsAutoConfiguration.class, ContextDefaultConfigurationRegistrar.class }) @ConditionalOnClass(name = "com.amazonaws.services.cloudformation.AmazonCloudFormation") +@EnableConfigurationProperties(AwsStackProperties.class) public class ContextStackAutoConfiguration { @Autowired - private Environment environment; + private AwsStackProperties properties; @Autowired(required = false) private AmazonEC2 amazonEC2; @@ -60,24 +65,29 @@ public class ContextStackAutoConfiguration { private AWSCredentialsProvider credentialsProvider; @Bean - @ConditionalOnMissingBean(StackResourceRegistry.class) - public StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean( - AmazonCloudFormation amazonCloudFormation) { - - if (StringUtils.hasText(environment.getProperty("cloud.aws.stack.name"))) { - return new StackResourceRegistryFactoryBean(amazonCloudFormation, - new StaticStackNameProvider( - this.environment.getProperty("cloud.aws.stack.name"))); - } + @ConditionalOnMissingBean + @ConditionalOnProperty("cloud.aws.stack.name") + public StackNameProvider staticStackNameProvider() { + return new StaticStackNameProvider(properties.getName()); + } - if (environment.getProperty("cloud.aws.stack.auto") == null || "true" - .equalsIgnoreCase(environment.getProperty("cloud.aws.stack.auto"))) { - return new StackResourceRegistryFactoryBean(amazonCloudFormation, - new AutoDetectingStackNameProvider(amazonCloudFormation, - this.amazonEC2)); - } + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(name = "cloud.aws.stack.auto", havingValue = "true", + matchIfMissing = true) + public StackNameProvider autoDetectingStackNameProvider( + AmazonCloudFormation amazonCloudFormation) { + return new AutoDetectingStackNameProvider(amazonCloudFormation, this.amazonEC2); + } - return null; + @Bean + @ConditionalOnMissingBean(StackResourceRegistry.class) + @ConditionalOnBean(StackNameProvider.class) + public StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean( + AmazonCloudFormation amazonCloudFormation, + StackNameProvider stackNameProvider) { + return new StackResourceRegistryFactoryBean(amazonCloudFormation, + stackNameProvider); } @Bean diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsStackProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsStackProperties.java new file mode 100644 index 000000000..76b32658a --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsStackProperties.java @@ -0,0 +1,56 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.autoconfigure.context.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Properties related to CloudFormation stack support. + * + * @author Maciej Walkowiak + */ +@ConfigurationProperties("cloud.aws.stack") +public class AwsStackProperties { + + /** + * Enables the automatic stack name detection for the application. + */ + private boolean auto = true; + + /** + * The name of the manually configured stack name that will be used to retrieve the + * resources. + */ + private String name; + + public boolean isAuto() { + return auto; + } + + public void setAuto(boolean auto) { + this.auto = auto; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index f0caeee00..6990c081f 100644 --- a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1,17 +1,5 @@ { "properties": [ - { - "defaultValue": "true", - "name": "cloud.aws.stack.auto", - "description": "Enables the automatic stack name detection for the application.", - "type": "java.lang.Boolean" - }, - { - "defaultValue": "myStackName", - "name": "cloud.aws.stack.name", - "description": "The name of the manually configured stack name that will be used to retrieve the resources.", - "type": "java.lang.String" - }, { "defaultValue": "", "name": "management.metrics.export.cloudwatch.namespace", @@ -25,4 +13,4 @@ "type": "java.lang.Boolean" } ] -} \ No newline at end of file +} diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java index 1e8718156..f326f0ae2 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java @@ -32,16 +32,20 @@ import org.junit.Test; import org.mockito.Mockito; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; +import org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider; +import org.springframework.cloud.aws.core.env.stack.config.StaticStackNameProvider; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ContextStackAutoConfigurationTest { @@ -92,7 +96,8 @@ public void stackRegistry_manualConfigurationEnabled_returnsAutoConfiguredStackR this.context = new AnnotationConfigApplicationContext(); this.context.register(ManualConfigurationStackRegistryTestConfiguration.class); this.context.register(ContextStackAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.stack.name:manualStackName") + TestPropertyValues + .of("cloud.aws.stack.name:manualStackName", "cloud.aws.stack.auto:true") .applyTo(this.context); // Act @@ -102,6 +107,27 @@ public void stackRegistry_manualConfigurationEnabled_returnsAutoConfiguredStackR assertThat(this.context.getBean(StackResourceRegistry.class)).isNotNull(); } + @Test + public void stackRegistry_manualConfigurationEnabledAndStackNameProvided_returnsStaticStackNameProvider() + throws Exception { + // Arrange + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ManualConfigurationStackRegistryTestConfiguration.class); + this.context.register(ContextStackAutoConfiguration.class); + TestPropertyValues + .of("cloud.aws.stack.name:manualStackName", "cloud.aws.stack.auto:true") + .applyTo(this.context); + + // Act + this.context.refresh(); + + // Assert + assertThat(this.context.getBean(StaticStackNameProvider.class)).isNotNull(); + assertThatThrownBy( + () -> this.context.getBean(AutoDetectingStackNameProvider.class)) + .isInstanceOf(NoSuchBeanDefinitionException.class); + } + @Test public void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfiguredBean() throws Exception { @@ -118,6 +144,20 @@ public void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfigure .isTrue(); } + @Test + public void stackResourceRegistryFactoryBean_isNotCreatedWhenStackNameAbsentAndStackAutoFalse() { + // Arrange + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextStackAutoConfiguration.class); + TestPropertyValues.of("cloud.aws.stack.auto:false").applyTo(this.context); + // Act + this.context.refresh(); + + // Assert + assertThatThrownBy(() -> this.context.getBean("stackResourceRegistryFactoryBean")) + .isInstanceOf(NoSuchBeanDefinitionException.class); + } + @Configuration(proxyBeanMethods = false) static class AutoConfigurationStackRegistryTestConfiguration { From 38c7e6a567151d3f41803af0106b03aab94f4879 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Mon, 1 Jun 2020 15:03:56 +0200 Subject: [PATCH 28/47] Drop XML support in all modules and integration tests. Fixes gh-567 Closes gh-575 --- .../config/xml/CacheBeanDefinitionParser.java | 172 ------ .../config/xml/CacheNamespaceHandler.java | 31 -- ...ontextCredentialsBeanDefinitionParser.java | 183 ------- ...ataPropertySourceBeanDefinitionParser.java | 77 --- .../config/xml/ContextNamespaceHandler.java | 46 -- .../ContextRegionBeanDefinitionParser.java | 106 ---- ...extResourceLoaderBeanDefinitionParser.java | 81 --- ...tackConfigurationBeanDefinitionParser.java | 140 ----- .../mail/config/xml/MailNamespaceHandler.java | 32 -- ...impleEmailServiceBeanDefinitionParser.java | 58 --- .../main/resources/META-INF/spring.handlers | 18 - .../main/resources/META-INF/spring.schemas | 24 - .../config/xml/spring-cloud-aws-cache-1.0.xsd | 111 ---- .../config/xml/spring-cloud-aws-cache-1.2.xsd | 111 ---- .../xml/spring-cloud-aws-context-1.0.xsd | 357 ------------- .../xml/spring-cloud-aws-context-1.2.xsd | 357 ------------- .../config/xml/spring-cloud-aws-mail-1.0.xsd | 68 --- .../config/xml/spring-cloud-aws-mail-1.2.xsd | 68 --- .../xml/CacheBeanDefinitionParserTest.java | 386 -------------- .../xml/CacheSchemaWithoutVersionTest.java | 41 -- ...xtCredentialsBeanDefinitionParserTest.java | 207 -------- ...ropertySourceBeanDefinitionParserTest.java | 182 ------- ...ContextRegionBeanDefinitionParserTest.java | 182 ------- ...esourceLoaderBeanDefinitionParserTest.java | 178 ------- .../xml/ContextSchemaWithoutVersionTest.java | 41 -- ...ConfigurationBeanDefinitionParserTest.java | 355 ------------- .../xml/MailSchemaWithoutVersionTest.java | 41 -- ...eEmailServiceBeanDefinitionParserTest.java | 129 ----- ...onParserTest-cacheConfigWithExpiration.xml | 29 -- ...heBeanDefinitionParserTest-customCache.xml | 47 -- ...DefinitionParserTest-elastiCacheConfig.xml | 32 -- ...Test-elastiCacheConfigRegionConfigured.xml | 30 -- ...rTest-elastiCacheConfigStackConfigured.xml | 30 -- ...CacheConfigWithCustomElastiCacheClient.xml | 34 -- ...nDefinitionParserTest-mixedCacheConfig.xml | 34 -- .../xml/CacheSchemaWithoutVersionTest.xml | 29 -- ...ntialsBeanDefinitionParserTest-context.xml | 31 -- ...redentialsBeanDefinitionParserTest-profile | 9 - ...nParserTest-profileCredentialsProvider.xml | 29 -- ...est-profileCredentialsProviderWithFile.xml | 35 -- ...initionParserTest-testMultipleElements.xml | 33 -- ...itionParserTest-testWithEmptyAccessKey.xml | 29 -- ...itionParserTest-testWithEmptySecretKey.xml | 29 -- ...finitionParserTest-testWithExpressions.xml | 38 -- ...finitionParserTest-testWithPlaceHolder.xml | 35 -- ...SourceBeanDefinitionParserTest-context.xml | 28 - ...rTest-customAttributeAndValueSeparator.xml | 28 - ...anDefinitionParserTest-customEc2Client.xml | 31 -- ...ceBeanDefinitionParserTest-userTagsMap.xml | 28 - ...RegionBeanDefinitionParserTest-context.xml | 26 - ...DefinitionParserTest-testAutoDetection.xml | 26 - ...-testAutoDetectionWithConfiguredRegion.xml | 27 - ...ionParserTest-testCustomRegionProvider.xml | 31 -- ...idRegionProviderConfigurationSpecified.xml | 27 - ...erTest-testTwoRegionProviderConfigured.xml | 29 -- ...efinitionParserTest-testWithExpression.xml | 34 -- ...finitionParserTest-testWithPlaceHolder.xml | 38 -- ...LoaderBeanDefinitionParserTest-context.xml | 35 -- ...ionParserTest-withCustomRegionProvider.xml | 39 -- ...efinitionParserTest-withCustomS3Client.xml | 37 -- ...itionParserTest-withCustomTaskExecutor.xml | 40 -- ...initionParserTest-withRegionConfigured.xml | 34 -- .../xml/ContextSchemaWithoutVersionTest.xml | 30 -- ...finitionParserTest-autoDetectStackName.xml | 27 - ...itionParserTest-custom-region-provider.xml | 38 -- ...BeanDefinitionParserTest-custom-region.xml | 32 -- ...anDefinitionParserTest-staticStackName.xml | 27 - ...serTest-withCustomCloudFormationClient.xml | 35 -- .../xml/MailSchemaWithoutVersionTest.xml | 28 - ...erviceBeanDefinitionParserTest-context.xml | 34 -- ...ServiceBeanDefinitionParserTest-region.xml | 34 -- ...eanDefinitionParserTest-regionProvider.xml | 39 -- ...iceBeanDefinitionParserTest-ses-client.xml | 37 -- .../xml/XmlWebserviceConfigurationUtils.java | 84 --- .../aws/cache/XmlElastiCacheAwsTest.java | 27 - .../XmlPathMatchingResourceLoaderAwsTest.java | 28 - .../support/io/XmlResourceLoaderAwsTest.java | 31 -- ...nEc2InstanceDataPropertySourceAwsTest.java | 28 - .../stack/XmlStackConfigurationAwsTest.java | 27 - .../jdbc/XmlDataSourceFactoryBeanAwsTest.java | 40 -- .../cloud/aws/mail/XmlMailSenderAwsTest.java | 27 - .../XmlMessageListenerContainerAwsTest.java | 27 - ...ationMessagingTemplateIntegrationTest.java | 28 - .../aws/messaging/XmlQueueListenerTest.java | 27 - ...QueueMessagingTemplateIntegrationTest.java | 28 - .../resources/Integration-test-context.xml | 58 --- .../cache/XmlElastiCacheAwsTest-context.xml | 40 -- ...hMatchingResourceLoaderAwsTest-context.xml | 35 -- .../io/XmlResourceLoaderAwsTest-context.xml | 35 -- ...anceUserTagsFactoryBeanAwsTest-context.xml | 31 -- ...tanceDataPropertySourceAwsTest-context.xml | 33 -- .../StackResourceUserTagsAwsTest-context.xml | 24 - .../XmlStackConfigurationAwsTest-context.xml | 23 - ...mlDataSourceFactoryBeanAwsTest-context.xml | 65 --- .../aws/mail/XmlMailSenderAwsTest-context.xml | 36 -- ...essageListenerContainerAwsTest-context.xml | 38 -- ...ssagingTemplateIntegrationTest-context.xml | 38 -- .../XmlQueueListenerTest-context.xml | 46 -- ...ssagingTemplateIntegrationTest-context.xml | 43 -- ...azonRdsDataSourceBeanDefinitionParser.java | 205 -------- ...sRetryInterceptorBeanDefinitionParser.java | 154 ------ .../jdbc/config/xml/JdbcNamespaceHandler.java | 40 -- .../main/resources/META-INF/spring.handlers | 16 - .../main/resources/META-INF/spring.schemas | 18 - .../config/xml/spring-cloud-aws-jdbc-1.0.xsd | 450 ---------------- .../config/xml/spring-cloud-aws-jdbc-1.2.xsd | 450 ---------------- ...RdsDataSourceBeanDefinitionParserTest.java | 489 ------------------ ...ryInterceptorBeanDefinitionParserTest.java | 143 ----- .../xml/JdbcSchemaWithoutVersionTest.java | 41 -- .../aws/jdbc/config/xml/SampleValidator.java | 33 -- ...DefinitionParserTest-customRdsInstance.xml | 47 -- ...eBeanDefinitionParserTest-customRegion.xml | 36 -- ...initionParserTest-customRegionProvider.xml | 41 -- ...rserTest-customRegionProviderAndRegion.xml | 41 -- ...nitionParserTest-defaultPoolAttributes.xml | 37 -- ...DefinitionParserTest-fullConfiguration.xml | 51 -- ...SourceBeanDefinitionParserTest-minimal.xml | 36 -- ...BeanDefinitionParserTest-noCredentials.xml | 29 -- ...eanDefinitionParserTest-poolAttributes.xml | 48 -- ...efinitionParserTest-readReplicaEnabled.xml | 37 -- ...ourceBeanDefinitionParserTest-userTags.xml | 37 -- ...finitionParserTest-customBackOffPolicy.xml | 38 -- ...anDefinitionParserTest-customRdsClient.xml | 40 -- ...rBeanDefinitionParserTest-customRegion.xml | 36 -- ...initionParserTest-customRegionProvider.xml | 42 -- ...efinitionParserTest-maxNumberOfRetries.xml | 36 -- ...ceptorBeanDefinitionParserTest-minimal.xml | 35 -- .../xml/JdbcSchemaWithoutVersionTest.xml | 30 -- ...ivenQueueListenerBeanDefinitionParser.java | 237 --------- .../BufferedSqsClientBeanDefinitionUtils.java | 73 --- .../config/xml/MessagingNamespaceHandler.java | 46 -- ...nArgumentResolverBeanDefinitionParser.java | 46 -- ...MessagingTemplateBeanDefinitionParser.java | 59 --- ...MessagingTemplateBeanDefinitionParser.java | 66 --- .../SqsAsyncClientBeanDefinitionParser.java | 60 --- .../main/resources/META-INF/spring.handlers | 16 - .../main/resources/META-INF/spring.schemas | 18 - .../xml/spring-cloud-aws-messaging-1.0.xsd | 346 ------------- .../xml/spring-cloud-aws-messaging-1.2.xsd | 337 ------------ ...QueueListenerBeanDefinitionParserTest.java | 408 --------------- .../xml/MessagingSchemaWithoutSchemaTest.java | 41 -- ...umentResolverBeanDefinitionParserTest.java | 107 ---- ...agingTemplateBeanDefinitionParserTest.java | 177 ------- ...agingTemplateBeanDefinitionParserTest.java | 224 -------- ...qsAsyncClientBeanDefinitionParserTest.java | 142 ----- ...lexNotificationEndpointControllerTest.java | 20 +- .../NotificationEndpointControllerTest.java | 20 +- ...BeanDefinitionParserTest-back-off-time.xml | 35 -- ...eanDefinitionParserTest-context-region.xml | 37 -- ...DefinitionParserTest-custom-amazon-sqs.xml | 37 -- ...onParserTest-custom-argument-resolvers.xml | 41 -- ...ParserTest-custom-destination-resolver.xml | 40 -- ...DefinitionParserTest-custom-properties.xml | 38 -- ...itionParserTest-custom-region-provider.xml | 40 -- ...BeanDefinitionParserTest-custom-region.xml | 35 -- ...arserTest-custom-return-value-handlers.xml | 41 -- ...initionParserTest-custom-task-executor.xml | 37 -- ...stenerBeanDefinitionParserTest-minimal.xml | 35 -- ...rserTest-with-send-to-message-template.xml | 41 -- .../xml/MessagingSchemaWithoutSchemaTest.xml | 29 -- ...rBeanDefinitionParserTest-customRegion.xml | 36 -- ...initionParserTest-customRegionProvider.xml | 40 -- ...anDefinitionParserTest-customSnsClient.xml | 37 -- ...solverBeanDefinitionParserTest-minimal.xml | 35 -- ...DefinitionParserTest-custom-amazon-sns.xml | 37 -- ...itionParserTest-custom-region-provider.xml | 40 -- ...BeanDefinitionParserTest-custom-region.xml | 36 -- ...mplateBeanDefinitionParserTest-minimal.xml | 35 -- ...ionParserTest-with-default-destination.xml | 36 -- ...DefinitionParserTest-custom-amazon-sqs.xml | 38 -- ...nDefinitionParserTest-custom-converter.xml | 38 -- ...itionParserTest-custom-region-provider.xml | 40 -- ...BeanDefinitionParserTest-custom-region.xml | 36 -- ...mplateBeanDefinitionParserTest-minimal.xml | 35 -- ...efinitionParserTest-multiple-templates.xml | 37 -- ...ionParserTest-with-default-destination.xml | 38 -- ...itionParserTest-custom-region-provider.xml | 40 -- ...BeanDefinitionParserTest-custom-region.xml | 35 -- ...initionParserTest-custom-task-executor.xml | 43 -- ...ClientBeanDefinitionParserTest-minimal.xml | 35 -- ...tBeanDefinitionParserTest-not-buffered.xml | 35 -- ...ficationEndpointControllerTest-context.xml | 44 -- ...ficationEndpointControllerTest-context.xml | 43 -- 183 files changed, 38 insertions(+), 12657 deletions(-) delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheNamespaceHandler.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextNamespaceHandler.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/MailNamespaceHandler.java delete mode 100644 spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-context/src/main/resources/META-INF/spring.handlers delete mode 100644 spring-cloud-aws-context/src/main/resources/META-INF/spring.schemas delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.0.xsd delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.0.xsd delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.0.xsd delete mode 100644 spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.java delete mode 100644 spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-cacheConfigWithExpiration.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-customCache.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfig.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigRegionConfigured.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigStackConfigured.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigWithCustomElastiCacheClient.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-mixedCacheConfig.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-context.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profile delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProvider.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProviderWithFile.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testMultipleElements.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptyAccessKey.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptySecretKey.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithExpressions.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithPlaceHolder.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-context.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customAttributeAndValueSeparator.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customEc2Client.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-userTagsMap.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-context.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetection.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetectionWithConfiguredRegion.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testCustomRegionProvider.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testNoValidRegionProviderConfigurationSpecified.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testTwoRegionProviderConfigured.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithExpression.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithPlaceHolder.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-context.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomRegionProvider.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomS3Client.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomTaskExecutor.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withRegionConfigured.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-autoDetectStackName.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region-provider.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-staticStackName.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-withCustomCloudFormationClient.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-context.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-region.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-regionProvider.xml delete mode 100644 spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-ses-client.xml delete mode 100644 spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/config/xml/XmlWebserviceConfigurationUtils.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueListenerTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest.java delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/Integration-test-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueListenerTest-context.xml delete mode 100644 spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest-context.xml delete mode 100644 spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcNamespaceHandler.java delete mode 100644 spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.handlers delete mode 100644 spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.schemas delete mode 100644 spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.0.xsd delete mode 100644 spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd delete mode 100644 spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.java delete mode 100644 spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/SampleValidator.java delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRdsInstance.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegion.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProvider.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProviderAndRegion.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-defaultPoolAttributes.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-fullConfiguration.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-noCredentials.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-poolAttributes.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-readReplicaEnabled.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-userTags.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customBackOffPolicy.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRdsClient.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegion.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegionProvider.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-maxNumberOfRetries.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.xml delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/BufferedSqsClientBeanDefinitionUtils.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/MessagingNamespaceHandler.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParser.java delete mode 100644 spring-cloud-aws-messaging/src/main/resources/META-INF/spring.handlers delete mode 100644 spring-cloud-aws-messaging/src/main/resources/META-INF/spring.schemas delete mode 100644 spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.0.xsd delete mode 100644 spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-back-off-time.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-context-region.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-argument-resolvers.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-destination-resolver.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-properties.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region-provider.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-return-value-handlers.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-task-executor.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-with-send-to-message-template.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegion.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegionProvider.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-amazon-sns.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-amazon-sqs.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-converter.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-multiple-templates.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region-provider.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-task-executor.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-minimal.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-not-buffered.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml delete mode 100644 spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest-context.xml diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParser.java deleted file mode 100644 index 1d6ef19d8..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParser.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.cache.config.xml; - -import java.util.List; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * Parser for the {@code } element. - * - * @author Alain Sahli - * @author Agim Emruli - * @since 1.0 - */ -class CacheBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - - private static final String CACHE_MANAGER = "cacheManager"; - - private static final String CACHE_CLUSTER_ELEMENT_NAME = "cache-cluster"; - - private static final String CACHE_REF_ELEMENT_NAME = "cache-ref"; - - private static final String ELASTICACHE_FACTORY_BEAN = "org.springframework.cloud.aws.cache.ElastiCacheFactoryBean"; - - // @checkstyle:off - private static final String ELASTI_CACHE_CLIENT_CLASS_NAME = "com.amazonaws.services.elasticache.AmazonElastiCacheClient"; - - // @checkstyle:on - - // @checkstyle:off - private static final String MEMCACHED_FACTORY_CLASS_NAME = "org.springframework.cloud.aws.cache.memcached.MemcachedCacheFactory"; - - // @checkstyle:on - - // @checkstyle:off - private static final String REDIS_CONNECTION_FACTORY_CLASS_NAME = "org.springframework.cloud.aws.cache.redis.RedisCacheFactory"; - - // @checkstyle:on - - private static String getRequiredAttribute(String attributeName, Element source, - ParserContext parserContext) { - if (StringUtils.hasText(source.getAttribute(attributeName))) { - return source.getAttribute(attributeName); - } - else { - parserContext.getReaderContext() - .error("Attribute '" + attributeName + "' is required", source); - return null; - } - } - - private static ManagedList createDefaultCacheFactories( - Element element, ParserContext parserContext) { - ManagedList result = new ManagedList<>(); - result.setSource(parserContext.extractSource(element)); - if (ClassUtils.isPresent("net.spy.memcached.MemcachedClient", - parserContext.getReaderContext().getBeanClassLoader())) { - result.add(getCacheFactory(MEMCACHED_FACTORY_CLASS_NAME, element)); - } - - if (ClassUtils.isPresent( - "org.springframework.data.redis.connection.RedisConnectionFactory", - parserContext.getReaderContext().getBeanClassLoader())) { - result.add(getCacheFactory(REDIS_CONNECTION_FACTORY_CLASS_NAME, element)); - } - return result; - } - - private static BeanDefinition createElastiCacheFactoryBean(Element source, - ParserContext parserContext, String clusterId, - ManagedList cacheFactories) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(ELASTICACHE_FACTORY_BEAN); - beanDefinitionBuilder.addConstructorArgReference( - getCustomClientOrDefaultClientBeanName(source, parserContext, - "amazon-elasti-cache", ELASTI_CACHE_CLIENT_CLASS_NAME)); - beanDefinitionBuilder.addConstructorArgValue(clusterId); - beanDefinitionBuilder.addConstructorArgReference(GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry())); - beanDefinitionBuilder.addConstructorArgValue(cacheFactories); - return beanDefinitionBuilder.getBeanDefinition(); - } - - private static BeanDefinition getCacheFactory(String className, Element element) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .genericBeanDefinition(className); - if (StringUtils.hasText(element.getAttribute("expiration"))) { - builder.addPropertyValue("expiryTime", element.getAttribute("expiration")); - } - return builder.getBeanDefinition(); - } - - @Override - protected String getBeanClassName(Element element) { - return "org.springframework.cache.support.SimpleCacheManager"; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - if (parserContext.getRegistry().containsBeanDefinition(CACHE_MANAGER)) { - parserContext.getReaderContext() - .error("Only one cache manager can be defined", element); - } - - builder.addPropertyValue("caches", createCacheCollection(element, parserContext)); - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return CACHE_MANAGER; - } - - private ManagedList createCacheCollection(Element element, - ParserContext parserContext) { - ManagedList caches = new ManagedList<>(); - List cacheElements = DomUtils.getChildElements(element); - - for (Element cacheElement : cacheElements) { - String elementName = cacheElement.getLocalName(); - - switch (elementName) { - case CACHE_REF_ELEMENT_NAME: - caches.add(new RuntimeBeanReference(cacheElement.getAttribute("ref"))); - break; - case CACHE_CLUSTER_ELEMENT_NAME: - String cacheClusterId = getRequiredAttribute("name", cacheElement, - parserContext); - caches.add(createElastiCacheFactoryBean(cacheElement, parserContext, - cacheClusterId, - createDefaultCacheFactories(cacheElement, parserContext))); - break; - default: - parserContext.getReaderContext().error("Unknown element detected", - parserContext.extractSource(cacheElement)); - } - } - return caches; - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheNamespaceHandler.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheNamespaceHandler.java deleted file mode 100644 index de238d55a..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/xml/CacheNamespaceHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.cache.config.xml; - -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; - -/** - * @author Agim Emruli - */ -public class CacheNamespaceHandler extends NamespaceHandlerSupport { - - @Override - public void init() { - registerBeanDefinitionParser("cache-manager", new CacheBeanDefinitionParser()); - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParser.java deleted file mode 100644 index 40ca942c8..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParser.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import java.util.ArrayList; -import java.util.List; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.core.credentials.CredentialsProviderFactoryBean; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; - -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.replaceDefaultCredentialsProvider; - -/** - * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} implementation which - * parses the <context-credentials/> Element. - * - * @author Agim Emruli - * @since 1.0 - */ -class ContextCredentialsBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - - // @checkstyle:off - private static final String STATIC_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME = "com.amazonaws.auth.AWSStaticCredentialsProvider"; - - // @checkstyle:on - - // @checkstyle:off - private static final String INSTANCE_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME = "com.amazonaws.auth.InstanceProfileCredentialsProvider"; - - // @checkstyle:on - - // @checkstyle:off - private static final String PROFILE_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME = "com.amazonaws.auth.profile.ProfileCredentialsProvider"; - - // @checkstyle:on - - private static final String ACCESS_KEY_ATTRIBUTE_NAME = "access-key"; - - private static final String SECRET_KEY_ATTRIBUTE_NAME = "secret-key"; - - private static BeanDefinition getCredentialsProvider( - String credentialsProviderClassName, Object... constructorArg) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(credentialsProviderClassName); - for (Object o : constructorArg) { - beanDefinitionBuilder.addConstructorArgValue(o); - } - - return beanDefinitionBuilder.getBeanDefinition(); - } - - /** - * Creates a bean definition for the credentials object. This methods creates a bean - * definition instead of the direct implementation to allow property place holder to - * change any place holder used for the access or secret key. - * @param credentialsProviderElement - The element that contains the credentials - * attributes ACCESS_KEY_ATTRIBUTE_NAME and SECRET_KEY_ATTRIBUTE_NAME - * @param parserContext - Used to report any errors if there is no - * ACCESS_KEY_ATTRIBUTE_NAME or SECRET_KEY_ATTRIBUTE_NAME available with a valid value - * @return - the bean definition with an - * {@link com.amazonaws.auth.BasicAWSCredentials} class - */ - private static BeanDefinition getCredentials(Element credentialsProviderElement, - ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .rootBeanDefinition("com.amazonaws.auth.BasicAWSCredentials"); - builder.addConstructorArgValue(getAttributeValue(ACCESS_KEY_ATTRIBUTE_NAME, - credentialsProviderElement, parserContext)); - builder.addConstructorArgValue(getAttributeValue(SECRET_KEY_ATTRIBUTE_NAME, - credentialsProviderElement, parserContext)); - return builder.getBeanDefinition(); - } - - private static List getProfileConfiguration(Element element) { - List constructorArguments = new ArrayList<>(2); - if (StringUtils.hasText(element.getAttribute("profilePath"))) { - constructorArguments.add(element.getAttribute("profilePath")); - } - - if (StringUtils.hasText(element.getAttribute("profileName"))) { - constructorArguments.add(element.getAttribute("profileName")); - } - return constructorArguments; - } - - /** - * Returns the attribute value and reports an error if the attribute value is null or - * empty. Normally the reported error leads into an exception which will be thrown - * through the {@link org.springframework.beans.factory.parsing.ProblemReporter} - * implementation. - * @param attribute - The name of the attribute which will be valuated - * @param element - The element that contains the attribute - * @param parserContext - The parser context used to report errors - * @return - The attribute value - */ - private static String getAttributeValue(String attribute, Element element, - ParserContext parserContext) { - String attributeValue = element.getAttribute(attribute); - if (!StringUtils.hasText(attributeValue)) { - parserContext.getReaderContext().error( - "The '" + attribute + "' attribute must not be empty", element); - } - return attributeValue; - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME; - } - - @Override - protected Class getBeanClass(Element element) { - return CredentialsProviderFactoryBean.class; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - if (parserContext.getRegistry().containsBeanDefinition( - CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME)) { - parserContext.getReaderContext() - .error("Multiple detected. " - + "The is only allowed once per application context", - element); - } - - List elements = DomUtils.getChildElements(element); - ManagedList credentialsProviders = new ManagedList<>( - elements.size()); - - for (Element credentialsProviderElement : elements) { - if ("simple-credentials".equals(credentialsProviderElement.getLocalName())) { - credentialsProviders.add(getCredentialsProvider( - STATIC_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME, - getCredentials(credentialsProviderElement, parserContext))); - } - - if ("instance-profile-credentials" - .equals(credentialsProviderElement.getLocalName())) { - credentialsProviders.add(getCredentialsProvider( - INSTANCE_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME)); - } - - if ("profile-credentials".equals(credentialsProviderElement.getLocalName())) { - credentialsProviders.add(getCredentialsProvider( - PROFILE_CREDENTIALS_PROVIDER_BEAN_CLASS_NAME, - getProfileConfiguration(credentialsProviderElement).toArray())); - } - } - - builder.addConstructorArgValue(credentialsProviders); - - replaceDefaultCredentialsProvider(parserContext.getRegistry(), - CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME); - - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParser.java deleted file mode 100644 index 89fce190f..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParser.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.support.ContextConfigurationUtils; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment; -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * @author Agim Emruli - */ -class ContextInstanceDataPropertySourceBeanDefinitionParser - extends AbstractBeanDefinitionParser { - - // @checkstyle:off - private static final String USER_TAGS_BEAN_CLASS_NAME = "org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceUserTagsFactoryBean"; - - // @checkstyle:on - - private static final String EC2_CLIENT_CLASS_NAME = "com.amazonaws.services.ec2.AmazonEC2Client"; - - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext parserContext) { - - if (StringUtils.hasText(element.getAttribute("user-tags-map"))) { - BeanDefinitionBuilder userTagsBuilder = BeanDefinitionBuilder - .genericBeanDefinition(USER_TAGS_BEAN_CLASS_NAME); - - userTagsBuilder.addConstructorArgReference( - getCustomClientOrDefaultClientBeanName(element, parserContext, - "amazon-ec2", EC2_CLIENT_CLASS_NAME)); - - if (StringUtils.hasText(element.getAttribute("instance-id-provider"))) { - userTagsBuilder.addConstructorArgReference( - element.getAttribute("instance-id-provider")); - } - BeanDefinitionReaderUtils.registerBeanDefinition( - new BeanDefinitionHolder(userTagsBuilder.getBeanDefinition(), - element.getAttribute("user-tags-map")), - parserContext.getRegistry()); - } - - if (isRunningOnCloudEnvironment()) { - ContextConfigurationUtils.registerInstanceDataPropertySource( - parserContext.getRegistry(), element.getAttribute("value-separator"), - element.getAttribute("attribute-separator")); - } - - return null; - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextNamespaceHandler.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextNamespaceHandler.java deleted file mode 100644 index cf2f43fa9..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextNamespaceHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; - -/** - * {@link org.springframework.beans.factory.xml.NamespaceHandler} implementation for the - * Spring Cloud AWS context namespace. - * - * @author Agim Emruli - * @since 1.0 - */ -@RuntimeUse -public class ContextNamespaceHandler extends NamespaceHandlerSupport { - - @Override - public void init() { - registerBeanDefinitionParser("context-credentials", - new ContextCredentialsBeanDefinitionParser()); - registerBeanDefinitionParser("context-resource-loader", - new ContextResourceLoaderBeanDefinitionParser()); - registerBeanDefinitionParser("context-region", - new ContextRegionBeanDefinitionParser()); - registerBeanDefinitionParser("context-instance-data", - new ContextInstanceDataPropertySourceBeanDefinitionParser()); - registerBeanDefinitionParser("stack-configuration", - new StackConfigurationBeanDefinitionParser()); - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParser.java deleted file mode 100644 index 637d7ecfe..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParser.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.replaceDefaultRegionProvider; - -/** - * Context region provider bean definition parser. - * - * @author Agim Emruli - */ -public class ContextRegionBeanDefinitionParser extends AbstractBeanDefinitionParser { - - static final String CONTEXT_REGION_PROVIDER_BEAN_NAME = "regionProvider"; - - private static boolean isAutoDetect(Element element) { - return StringUtils.hasText(element.getAttribute("auto-detect")) && Boolean.TRUE - .toString().equalsIgnoreCase(element.getAttribute("auto-detect")); - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return CONTEXT_REGION_PROVIDER_BEAN_NAME; - } - - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext parserContext) { - if (parserContext.getRegistry() - .containsBeanDefinition(CONTEXT_REGION_PROVIDER_BEAN_NAME)) { - parserContext.getReaderContext() - .error("Multiple elements detected. " - + "The element is only allowed once per application context", - element); - } - - if (isAutoDetect(element) && (StringUtils.hasText(element.getAttribute("region")) - || StringUtils.hasText(element.getAttribute("region-provider")))) { - parserContext.getReaderContext().error( - "The attribute 'auto-detect' can only be enabled without a region or region-provider specified", - element); - return null; - } - - if (!isAutoDetect(element) && !StringUtils.hasText(element.getAttribute("region")) - && !StringUtils.hasText(element.getAttribute("region-provider"))) { - parserContext.getReaderContext().error( - "Either auto-detect must be enabled, or a region or region-provider must be specified", - element); - return null; - } - - // Replace the default region provider with this one - replaceDefaultRegionProvider(parserContext.getRegistry(), - CONTEXT_REGION_PROVIDER_BEAN_NAME); - - if (StringUtils.hasText(element.getAttribute("region-provider"))) { - parserContext.getRegistry().registerAlias( - element.getAttribute("region-provider"), - CONTEXT_REGION_PROVIDER_BEAN_NAME); - return null; - } - else if (StringUtils.hasText(element.getAttribute("region"))) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.cloud.aws.core.region.StaticRegionProvider"); - builder.addConstructorArgValue(element.getAttribute("region")); - return builder.getBeanDefinition(); - } - else if (isAutoDetect(element)) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider"); - return builder.getBeanDefinition(); - } - return null; - } - - @Override - protected boolean shouldGenerateId() { - return false; - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParser.java deleted file mode 100644 index 511089f4a..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParser.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.core.Conventions; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * Parser for the {@code } element. - * - * @author Agim Emruli - * @author Alain Sahli - * @since 1.0 - */ -@SuppressWarnings({ "UnusedDeclaration", "WeakerAccess" }) -public class ContextResourceLoaderBeanDefinitionParser - extends AbstractSimpleBeanDefinitionParser { - - private static final String AMAZON_S3_CLIENT_CLASS_NAME = "com.amazonaws.services.s3.AmazonS3Client"; - - // @checkstyle:off - private static final String RESOURCE_LOADER_BEAN_POST_PROCESSOR = "org.springframework.cloud.aws.context.support.io.SimpleStorageProtocolResolverConfigurer"; - - // @checkstyle:on - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - - BeanDefinitionBuilder resolverBuilder = BeanDefinitionBuilder - .genericBeanDefinition( - "org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver"); - resolverBuilder.addConstructorArgReference(getCustomClientOrDefaultClientBeanName( - element, parserContext, "amazon-s3", AMAZON_S3_CLIENT_CLASS_NAME)); - - if (StringUtils.hasText(element.getAttribute("task-executor"))) { - resolverBuilder.addPropertyReference( - Conventions.attributeNameToPropertyName("task-executor"), - element.getAttribute("task-executor")); - } - - builder.addConstructorArgValue(resolverBuilder.getBeanDefinition()); - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return BeanDefinitionReaderUtils.generateBeanName(definition, - parserContext.getRegistry(), false); - } - - @Override - protected String getBeanClassName(Element element) { - return RESOURCE_LOADER_BEAN_POST_PROCESSOR; - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParser.java deleted file mode 100644 index b668440a4..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParser.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.core.env.stack.config.StackResourceUserTagsFactoryBean; -import org.springframework.util.StringUtils; - -import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition; -import static org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils.registerResourceIdResolverBeanIfNeeded; -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * Parser for the {@code } element. - * - * @author Christian Stettler - * @author Agim Emruli - */ -class StackConfigurationBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser { - - // @checkstyle:off - private static final String STACK_RESOURCE_REGISTRY_FACTORY_BEAN_CLASS_NAME = "org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean"; - - private static final String STATIC_STACK_NAME_PROVIDER_CLASS_NAME = "org.springframework.cloud.aws.core.env.stack.config.StaticStackNameProvider"; - - private static final String AUTO_DETECTING_STACK_NAME_PROVIDER_CLASS_NAME = "org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider"; - - private static final String INSTANCE_ID_PROVIDER_CLASS_NAME = "org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceIdProvider"; - - private static final String CLOUD_FORMATION_CLIENT_CLASS_NAME = "com.amazonaws.services.cloudformation.AmazonCloudFormationClient"; - - // @checkstyle:on - - private static final String EC2_CLIENT_CLASS_NAME = "com.amazonaws.services.ec2.AmazonEC2Client"; - - private static final String STACK_NAME_ATTRIBUTE_NAME = "stack-name"; - - private static AbstractBeanDefinition buildStaticStackNameProviderBeanDefinition( - String stackName) { - BeanDefinitionBuilder staticStackNameProviderBeanDefinitionBuilder = genericBeanDefinition( - STATIC_STACK_NAME_PROVIDER_CLASS_NAME); - staticStackNameProviderBeanDefinitionBuilder.addConstructorArgValue(stackName); - - return staticStackNameProviderBeanDefinitionBuilder.getBeanDefinition(); - } - - private static AbstractBeanDefinition buildAutoDetectingStackNameProviderBeanDefinition( - String amazonCloudFormationClientBeanName, String amazonEc2ClientBeanName) { - BeanDefinitionBuilder autoDetectingStackNameProviderBeanDefinitionBuilder = genericBeanDefinition( - AUTO_DETECTING_STACK_NAME_PROVIDER_CLASS_NAME); - autoDetectingStackNameProviderBeanDefinitionBuilder - .addConstructorArgReference(amazonCloudFormationClientBeanName); - autoDetectingStackNameProviderBeanDefinitionBuilder - .addConstructorArgReference(amazonEc2ClientBeanName); - autoDetectingStackNameProviderBeanDefinitionBuilder - .addConstructorArgValue(buildInstanceIdProviderBeanDefinition()); - - return autoDetectingStackNameProviderBeanDefinitionBuilder.getBeanDefinition(); - } - - private static AbstractBeanDefinition buildInstanceIdProviderBeanDefinition() { - BeanDefinitionBuilder instanceIdProviderBeanDefinitionBuilder = genericBeanDefinition( - INSTANCE_ID_PROVIDER_CLASS_NAME); - - return instanceIdProviderBeanDefinitionBuilder.getBeanDefinition(); - } - - private static void buildAndRegisterStackUserTagsIfNeeded(Element element, - ParserContext parserContext, String cloudformationBeanName, - BeanDefinition stackNameProvider) { - if (StringUtils.hasText(element.getAttribute("user-tags-map"))) { - BeanDefinitionBuilder builder = genericBeanDefinition( - StackResourceUserTagsFactoryBean.class); - builder.addConstructorArgReference(cloudformationBeanName); - builder.addConstructorArgValue(stackNameProvider); - parserContext.getRegistry().registerBeanDefinition( - element.getAttribute("user-tags-map"), builder.getBeanDefinition()); - } - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - registerResourceIdResolverBeanIfNeeded(parserContext.getRegistry()); - - String amazonCloudFormationClientBeanName = getCustomClientOrDefaultClientBeanName( - element, parserContext, "amazon-cloud-formation", - CLOUD_FORMATION_CLIENT_CLASS_NAME); - String amazonEc2ClientBeanName = getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-ec2", EC2_CLIENT_CLASS_NAME); - String stackName = element.getAttribute(STACK_NAME_ATTRIBUTE_NAME); - - builder.addConstructorArgReference(amazonCloudFormationClientBeanName); - AbstractBeanDefinition stackNameProviderBeanDefinition = StringUtils - .isEmpty(stackName) - ? buildAutoDetectingStackNameProviderBeanDefinition( - amazonCloudFormationClientBeanName, - amazonEc2ClientBeanName) - : buildStaticStackNameProviderBeanDefinition(stackName); - builder.addConstructorArgValue(stackNameProviderBeanDefinition); - - buildAndRegisterStackUserTagsIfNeeded(element, parserContext, - amazonCloudFormationClientBeanName, stackNameProviderBeanDefinition); - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return element.hasAttribute(STACK_NAME_ATTRIBUTE_NAME) - ? element.getAttribute(STACK_NAME_ATTRIBUTE_NAME) - : parserContext.getReaderContext().generateBeanName(definition); - } - - @Override - protected String getBeanClassName(Element element) { - return STACK_RESOURCE_REGISTRY_FACTORY_BEAN_CLASS_NAME; - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/MailNamespaceHandler.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/MailNamespaceHandler.java deleted file mode 100644 index 18dad1c78..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/MailNamespaceHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.mail.config.xml; - -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; - -/** - * @author Agim Emruli - */ -public class MailNamespaceHandler extends NamespaceHandlerSupport { - - @Override - public void init() { - registerBeanDefinitionParser("mail-sender", - new SimpleEmailServiceBeanDefinitionParser()); - } - -} diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParser.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParser.java deleted file mode 100644 index 581b31ac4..000000000 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParser.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.mail.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.util.ClassUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * @author Agim Emruli - */ -class SimpleEmailServiceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - - private static final boolean JAVA_MAIL_PRESENT = ClassUtils.isPresent( - "javax.mail.Session", - SimpleEmailServiceBeanDefinitionParser.class.getClassLoader()); - - // @checkstyle:off - private static final String SIMPLE_EMAIL_CLIENT_CLASS_NAME = "com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient"; - - // @checkstyle:on - - @Override - protected String getBeanClassName(Element element) { - if (JAVA_MAIL_PRESENT) { - return "org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceJavaMailSender"; - } - - return "org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceMailSender"; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - builder.addConstructorArgReference(getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-ses", SIMPLE_EMAIL_CLIENT_CLASS_NAME)); - } - -} diff --git a/spring-cloud-aws-context/src/main/resources/META-INF/spring.handlers b/spring-cloud-aws-context/src/main/resources/META-INF/spring.handlers deleted file mode 100644 index cde86022e..000000000 --- a/spring-cloud-aws-context/src/main/resources/META-INF/spring.handlers +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/context=org.springframework.cloud.aws.context.config.xml.ContextNamespaceHandler -http\://www.springframework.org/schema/cloud/aws/cache=org.springframework.cloud.aws.cache.config.xml.CacheNamespaceHandler -http\://www.springframework.org/schema/cloud/aws/mail=org.springframework.cloud.aws.mail.config.xml.MailNamespaceHandler diff --git a/spring-cloud-aws-context/src/main/resources/META-INF/spring.schemas b/spring-cloud-aws-context/src/main/resources/META-INF/spring.schemas deleted file mode 100644 index dd2aed551..000000000 --- a/spring-cloud-aws-context/src/main/resources/META-INF/spring.schemas +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.0.xsd=org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.0.xsd -http\://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.2.xsd=org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd=org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/cache/spring-cloud-aws-cache-1.0.xsd=org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.0.xsd -http\://www.springframework.org/schema/cloud/aws/cache/spring-cloud-aws-cache-1.2.xsd=org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/cache/spring-cloud-aws-cache.xsd=org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/mail/spring-cloud-aws-mail-1.0.xsd=org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.0.xsd -http\://www.springframework.org/schema/cloud/aws/mail/spring-cloud-aws-mail-1.2.xsd=org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/mail/spring-cloud-aws-mail.xsd=org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.0.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.0.xsd deleted file mode 100644 index 2b6f593c8..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.0.xsd +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - Configures a cache manager based on SpyMemcached that uses the AWS - ElastiCache service. - - - - - - - - - - - The id of the cache manager - - - - - - - - - - - Defines optionally the expiration time in seconds of a cache entry. - Otherwise an expiration of '0' - is assumed - - - - - - - - - - - - - Defines the cache cluster name - - - - - - - Reference to an externally configured - com.amazonaws.services.elasticache.AmazonElastiCache - instance - - - - - - - - - - - - - - - - - A reference to a bean that implements the - org.springframework.cache.Cache interface. - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd deleted file mode 100644 index 2b6f593c8..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/cache/config/xml/spring-cloud-aws-cache-1.2.xsd +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - Configures a cache manager based on SpyMemcached that uses the AWS - ElastiCache service. - - - - - - - - - - - The id of the cache manager - - - - - - - - - - - Defines optionally the expiration time in seconds of a cache entry. - Otherwise an expiration of '0' - is assumed - - - - - - - - - - - - - Defines the cache cluster name - - - - - - - Reference to an externally configured - com.amazonaws.services.elasticache.AmazonElastiCache - instance - - - - - - - - - - - - - - - - - A reference to a bean that implements the - org.springframework.cache.Cache interface. - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.0.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.0.xsd deleted file mode 100644 index 74986e779..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.0.xsd +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - Simple credentials which can be used to configure the static - credentials. This credentials - can be either hard-coded in the XML (not recommended), - evaluated through an EL expression or - replaced by a property place holder variable. - - - - - - - This credentials will be fetched through the particular - instance profile. So there is no - need to define any additional information. NOTE: In order to - use the instance profile - credentials, the application context must run inside an EC2 - instance. - - - - - - - Profile based credentials provider that allows to configure - the profiles inside an - AWS SDK specific configuration file using different profile - names. - - - - - - - Configures the profile name used by the profile - credentials provider. The profile - name is specified according to the profile file - format. - - - - - - - Allows to configure the profile path. By default the - profile file will be read - inside - the users directory in the folder .aws/credentials . - - - - - - - - - - - - - Configures a resource loader that supports amazon S3 resources to be - loaded by the application context - resource loader. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Defines that the region should be auto detected - through the EC2 meta data - - - - - - - - - - - - - - - - - - - - - - Instance id provider, by default the instance id is - taken from the instance - meta-data. Might be changed with another strategy - - - - - - - - - - - Reference to a custom Amazon EC2 client bean if - user tags should be retrieved - from EC2 meta-data. This attribute is ignored if there is no - user-tags-map attribute configured - - - - - - - - - - - Value separator used to separate the values inside - the user data (same default - like property place holders default) - - - - - - Attribute separator used to separate the attributes - inside the global user data - string - - - - - - - - - - Attribute group that can be used by components which are region aware. - This group - allows users to configure the particular region. - - - - - The region that will be used, must be one of the valid - regions. - - - - - - - - - - - - - - - - - - Exposed map that contains all user tags to be accessed - via EL expression - - - - - - - - - - The access key used to make the request. An access key is assigned to - one account or IAM user. - - - - - - - - - - - - The secret key which is assigned for the particular access key. - - - - - - - - - - - - - - Configures an Amazon Cloud Formation stack and enables lookup of physical - ids by logical ids for - resources defined in the specified stack. - - - - - - - - - - - - - - The name of the stack to be configured. The corresponding stack - must exist and must be - available. If no stack name is configured, the stack name is - automatically detected - based on the stack the current Amazon EC2 instance is part of. - - - - - - - A reference to an externally configured AmazonCloudFormation - client, to be used to retrieve - stack information from the CloudFormation service. - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd deleted file mode 100644 index 74986e779..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/context/config/xml/spring-cloud-aws-context-1.2.xsd +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - Simple credentials which can be used to configure the static - credentials. This credentials - can be either hard-coded in the XML (not recommended), - evaluated through an EL expression or - replaced by a property place holder variable. - - - - - - - This credentials will be fetched through the particular - instance profile. So there is no - need to define any additional information. NOTE: In order to - use the instance profile - credentials, the application context must run inside an EC2 - instance. - - - - - - - Profile based credentials provider that allows to configure - the profiles inside an - AWS SDK specific configuration file using different profile - names. - - - - - - - Configures the profile name used by the profile - credentials provider. The profile - name is specified according to the profile file - format. - - - - - - - Allows to configure the profile path. By default the - profile file will be read - inside - the users directory in the folder .aws/credentials . - - - - - - - - - - - - - Configures a resource loader that supports amazon S3 resources to be - loaded by the application context - resource loader. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Defines that the region should be auto detected - through the EC2 meta data - - - - - - - - - - - - - - - - - - - - - - Instance id provider, by default the instance id is - taken from the instance - meta-data. Might be changed with another strategy - - - - - - - - - - - Reference to a custom Amazon EC2 client bean if - user tags should be retrieved - from EC2 meta-data. This attribute is ignored if there is no - user-tags-map attribute configured - - - - - - - - - - - Value separator used to separate the values inside - the user data (same default - like property place holders default) - - - - - - Attribute separator used to separate the attributes - inside the global user data - string - - - - - - - - - - Attribute group that can be used by components which are region aware. - This group - allows users to configure the particular region. - - - - - The region that will be used, must be one of the valid - regions. - - - - - - - - - - - - - - - - - - Exposed map that contains all user tags to be accessed - via EL expression - - - - - - - - - - The access key used to make the request. An access key is assigned to - one account or IAM user. - - - - - - - - - - - - The secret key which is assigned for the particular access key. - - - - - - - - - - - - - - Configures an Amazon Cloud Formation stack and enables lookup of physical - ids by logical ids for - resources defined in the specified stack. - - - - - - - - - - - - - - The name of the stack to be configured. The corresponding stack - must exist and must be - available. If no stack name is configured, the stack name is - automatically detected - based on the stack the current Amazon EC2 instance is part of. - - - - - - - A reference to an externally configured AmazonCloudFormation - client, to be used to retrieve - stack information from the CloudFormation service. - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.0.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.0.xsd deleted file mode 100644 index a8f8d750e..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.0.xsd +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - Configures a mail sender for Amazon Simple Mail Service - - - - - - - - - - - - The id of the mail sender - - - - - - - - Reference to an externally configured AmazonSimpleEmailService - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd b/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd deleted file mode 100644 index a8f8d750e..000000000 --- a/spring-cloud-aws-context/src/main/resources/org/springframework/cloud/aws/mail/config/xml/spring-cloud-aws-mail-1.2.xsd +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - Configures a mail sender for Amazon Simple Mail Service - - - - - - - - - - - - The id of the mail sender - - - - - - - - Reference to an externally configured AmazonSimpleEmailService - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest.java deleted file mode 100644 index efc9db2c3..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.cache.config.xml; - -import com.amazonaws.services.elasticache.AmazonElastiCache; -import com.amazonaws.services.elasticache.AmazonElastiCacheClient; -import com.amazonaws.services.elasticache.model.CacheCluster; -import com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest; -import com.amazonaws.services.elasticache.model.DescribeCacheClustersResult; -import com.amazonaws.services.elasticache.model.Endpoint; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cloud.aws.cache.config.TestMemcacheServer; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.cloud.aws.core.env.ResourceIdResolver; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -/** - * @author Agim Emruli - */ -public class CacheBeanDefinitionParserTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @BeforeClass - public static void setupMemcachedServerAndClient() throws Exception { - // Get next free port for the test server - int availableTcpPort = TestMemcacheServer.startServer(); - - // Set the port as system property to easily fetch it in the Spring config - System.setProperty("memcachedPort", String.valueOf(availableTcpPort)); - } - - @AfterClass - public static void tearDownMemcachedServerAndClient() throws Exception { - TestMemcacheServer.stopServer(); - System.clearProperty("memcachedPort"); - } - - @Test - public void parseInternal_cacheConfigWithExpiration_returnsConfiguredCacheThatRespectExpiration() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Register a mock object which will be used to replay service calls - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-cacheConfigWithExpiration.xml", - getClass())); - - AmazonElastiCache client = beanFactory.getBean( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - AmazonElastiCache.class); - - // Replay invocation that will be called - DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest() - .withCacheClusterId("memcached"); - memcached.setShowCacheNodeInfo(true); - - when(client.describeCacheClusters(memcached)).thenReturn( - new DescribeCacheClustersResult().withCacheClusters(new CacheCluster() - .withCacheClusterId("memcached") - .withConfigurationEndpoint(new Endpoint().withAddress("localhost") - .withPort(Integer - .parseInt(System.getProperty("memcachedPort")))) - .withCacheClusterStatus("available").withEngine("memcached"))); - - // Act - CacheManager cacheManager = beanFactory.getBean(CacheManager.class); - Cache cache = cacheManager.getCache("memcached"); - cache.put("foo", "bar"); - Thread.sleep(2000); - - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(cache).isNotNull(); - assertThat(cache.get("foo")).isNull(); - } - - @Test - public void parseInternal_customCache_returnsCacheManagerWithCustomCache() - throws Exception { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customCache.xml", getClass()); - - // Act - CacheManager cacheManager = applicationContext.getBean(CacheManager.class); - Cache cache = cacheManager.getCache("memc"); - cache.put("foo", "bar"); - cache.evict("foo"); - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(cache).isNotNull(); - } - - @Test - public void parseInternal_mixedCacheConfig_returnsBothCaches() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Register a mock object which will be used to replay service calls - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - BeanDefinitionBuilder cacheBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - cacheBuilder.setFactoryMethod("mock"); - cacheBuilder.addConstructorArgValue(AmazonElastiCache.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - cacheBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-mixedCacheConfig.xml", getClass())); - - AmazonElastiCache client = beanFactory.getBean( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - AmazonElastiCache.class); - - // Replay invocation that will be called - - DescribeCacheClustersRequest memcached1 = new DescribeCacheClustersRequest() - .withCacheClusterId("memcached"); - memcached1.setShowCacheNodeInfo(true); - - when(client.describeCacheClusters(memcached1)).thenReturn( - new DescribeCacheClustersResult().withCacheClusters(new CacheCluster() - .withCacheClusterId("memcached") - .withConfigurationEndpoint(new Endpoint().withAddress("localhost") - .withPort(Integer - .parseInt(System.getProperty("memcachedPort")))) - .withCacheClusterStatus("available").withEngine("memcached"))); - - Cache cache = beanFactory.getBean("memc", Cache.class); - when(cache.getName()).thenReturn("memc"); - - // Act - CacheManager cacheManager = beanFactory.getBean(CacheManager.class); - Cache memc = cacheManager.getCache("memc"); - Cache memcached = cacheManager.getCache("memcached"); - - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(memcached).isNotNull(); - - memc.put("foo", "bar"); - memc.evict("foo"); - - memcached.put("foo", "bar"); - memcached.evict("foo"); - } - - @Test - public void parseInternal_clusterCacheConfiguration_returnsConfiguredClusterCache() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Register a mock object which will be used to replay service calls - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - // Load xml file - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-elastiCacheConfig.xml", getClass())); - - AmazonElastiCache client = beanFactory.getBean( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - AmazonElastiCache.class); - - // Replay invocation that will be called - DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest() - .withCacheClusterId("memcached"); - memcached.setShowCacheNodeInfo(true); - - when(client.describeCacheClusters(memcached)).thenReturn( - new DescribeCacheClustersResult().withCacheClusters(new CacheCluster() - .withCacheClusterId("memcached") - .withConfigurationEndpoint(new Endpoint().withAddress("localhost") - .withPort(Integer - .parseInt(System.getProperty("memcachedPort")))) - .withCacheClusterStatus("available").withEngine("memcached"))); - - // Act - CacheManager cacheManager = beanFactory.getBean(CacheManager.class); - Cache cache = cacheManager.getCache("memcached"); - cache.put("foo", "bar"); - cache.evict("foo"); - - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(cache).isNotNull(); - } - - @Test - public void parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Register a mock object which will be used to replay service calls - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - BeanDefinitionBuilder resourceIdBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - resourceIdBuilder.setFactoryMethod("mock"); - resourceIdBuilder.addConstructorArgValue(ResourceIdResolver.class); - beanFactory.registerBeanDefinition( - GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, - resourceIdBuilder.getBeanDefinition()); - - // Load xml file - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-elastiCacheConfigStackConfigured.xml", - getClass())); - - AmazonElastiCache client = beanFactory.getBean( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName()), - AmazonElastiCache.class); - - ResourceIdResolver resourceIdResolver = beanFactory.getBean( - GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, - ResourceIdResolver.class); - - when(resourceIdResolver.resolveToPhysicalResourceId("testMemcached")) - .thenReturn("memcached"); - - // Replay invocation that will be called - DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest() - .withCacheClusterId("memcached"); - memcached.setShowCacheNodeInfo(true); - - when(client.describeCacheClusters(memcached)).thenReturn( - new DescribeCacheClustersResult().withCacheClusters(new CacheCluster() - .withCacheClusterId("memcached") - .withConfigurationEndpoint(new Endpoint().withAddress("localhost") - .withPort(Integer - .parseInt(System.getProperty("memcachedPort")))) - .withCacheClusterStatus("available").withEngine("memcached"))); - - // Act - CacheManager cacheManager = beanFactory.getBean(CacheManager.class); - Cache cache = cacheManager.getCache("testMemcached"); - cache.put("foo", "bar"); - cache.evict("foo"); - - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(cache).isNotNull(); - } - - @Test - public void parseInternal_clusterCacheConfigurationWithRegion_returnsConfiguredClusterCacheWithRegion() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Load xml file - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-elastiCacheConfigRegionConfigured.xml", - getClass())); - - // Act - BeanDefinition beanDefinition = beanFactory - .getBeanDefinition(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonElastiCacheClient.class.getName())); - - // Assert - assertThat(beanDefinition).isNotNull(); - assertThat(beanDefinition.getPropertyValues().get("customRegion")).isNotNull(); - } - - @Test - public void parseInternal_clusterCacheConfigurationWithCustomElastiCacheClient_returnsConfigurationWithCustomClient() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - // Load xml file - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() - + "-elastiCacheConfigWithCustomElastiCacheClient.xml", - getClass())); - - AmazonElastiCache amazonElastiCacheMock = beanFactory.getBean("customClient", - AmazonElastiCache.class); - - DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest() - .withCacheClusterId("memcached"); - memcached.setShowCacheNodeInfo(true); - - when(amazonElastiCacheMock.describeCacheClusters(memcached)).thenReturn( - new DescribeCacheClustersResult().withCacheClusters(new CacheCluster() - .withCacheClusterId("memcached") - .withConfigurationEndpoint(new Endpoint().withAddress("localhost") - .withPort(Integer - .parseInt(System.getProperty("memcachedPort")))) - .withCacheClusterStatus("available").withEngine("memcached"))); - - // Act - CacheManager cacheManager = beanFactory.getBean(CacheManager.class); - Cache cache = cacheManager.getCache("memcached"); - cache.put("foo", "bar"); - cache.evict("foo"); - - // Assert - assertThat(cacheManager).isNotNull(); - assertThat(cache).isNotNull(); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.java deleted file mode 100644 index 9d89d2245..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.cache.config.xml; - -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; - -/** - * @author Alain Sahli - */ -public class CacheSchemaWithoutVersionTest { - - @Test - public void cacheXsd_withoutVersion_shouldNotThrowAnException() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act & Assert - reader.loadBeanDefinitions( - new ClassPathResource(getClass().getSimpleName() + ".xml", getClass())); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest.java deleted file mode 100644 index cbb44fcaa..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.amazonaws.auth.AWSCredentials; -import com.amazonaws.auth.AWSCredentialsProvider; -import com.amazonaws.auth.AWSCredentialsProviderChain; -import com.amazonaws.auth.AWSStaticCredentialsProvider; -import com.amazonaws.auth.InstanceProfileCredentialsProvider; -import com.amazonaws.auth.profile.ProfileCredentialsProvider; -import org.apache.http.client.CredentialsProvider; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.io.ClassPathResource; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link ContextCredentialsBeanDefinitionParser}. - * - * @author Agim Emruli - */ -public class ContextCredentialsBeanDefinitionParserTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - - @Test - public void testCreateBeanDefinition() throws Exception { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-context.xml", getClass()); - - // Check that the result of the factory bean is available - AWSCredentialsProvider awsCredentialsProvider = applicationContext - .getBean(AWSCredentialsProvider.class); - - assertThat(AWSCredentialsProviderChain.class.isInstance(awsCredentialsProvider)) - .isTrue(); - - // Using reflection to really test if the chain is stable - AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) awsCredentialsProvider; - - @SuppressWarnings("unchecked") - List providerChain = (List) ReflectionTestUtils - .getField(awsCredentialsProviderChain, "credentialsProviders"); - - assertThat(providerChain).isNotNull(); - assertThat(providerChain.size()).isEqualTo(2); - - assertThat( - InstanceProfileCredentialsProvider.class.isInstance(providerChain.get(0))) - .isTrue(); - assertThat(AWSStaticCredentialsProvider.class.isInstance(providerChain.get(1))) - .isTrue(); - - AWSStaticCredentialsProvider staticCredentialsProvider = (AWSStaticCredentialsProvider) providerChain - .get(1); - assertThat(staticCredentialsProvider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("staticAccessKey"); - assertThat(staticCredentialsProvider.getCredentials().getAWSSecretKey()) - .isEqualTo("staticSecretKey"); - - } - - @Test - public void testMultipleElements() throws Exception { - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException.expectMessage("only allowed once per"); - - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testMultipleElements.xml", getClass()); - } - - @Test - public void testWithEmptyAccessKey() throws Exception { - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException - .expectMessage("The 'access-key' attribute must not be empty"); - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithEmptyAccessKey.xml", getClass()); - } - - @Test - public void testWithEmptySecretKey() throws Exception { - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException - .expectMessage("The 'secret-key' attribute must not be empty"); - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithEmptySecretKey.xml", getClass()); - } - - @Test - public void testWithPlaceHolder() throws Exception { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithPlaceHolder.xml", getClass()); - - AWSCredentialsProvider awsCredentialsProvider = applicationContext - .getBean(AWSCredentialsProvider.class); - AWSCredentials credentials = awsCredentialsProvider.getCredentials(); - assertThat(credentials.getAWSAccessKeyId()).isEqualTo("foo"); - assertThat(credentials.getAWSSecretKey()).isEqualTo("bar"); - } - - @Test - public void testWithExpressions() throws Exception { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithExpressions.xml", getClass()); - - AWSCredentialsProvider awsCredentialsProvider = applicationContext - .getBean(AWSCredentialsProvider.class); - AWSCredentials credentials = awsCredentialsProvider.getCredentials(); - assertThat(credentials.getAWSAccessKeyId()).isEqualTo("foo"); - assertThat(credentials.getAWSSecretKey()).isEqualTo("bar"); - } - - @Test - public void parseBean_withProfileCredentialsProvider_createProfileCredentialsProvider() { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-profileCredentialsProvider.xml", - getClass()); - - AWSCredentialsProvider awsCredentialsProvider = applicationContext.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(1); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(0))) - .isTrue(); - - assertThat( - ReflectionTestUtils.getField(credentialsProviders.get(0), "profileName")) - .isEqualTo("test"); - } - - @Test - public void parseBean_withProfileCredentialsProviderAndProfileFile_createProfileCredentialsProvider() - throws IOException { - GenericApplicationContext applicationContext = new GenericApplicationContext(); - - Map secretAndAccessKeyMap = new HashMap<>(); - secretAndAccessKeyMap.put("profilePath", - new ClassPathResource(getClass().getSimpleName() + "-profile", getClass()) - .getFile().getAbsolutePath()); - - applicationContext.getEnvironment().getPropertySources() - .addLast(new MapPropertySource("test", secretAndAccessKeyMap)); - PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); - configurer.setPropertySources( - applicationContext.getEnvironment().getPropertySources()); - - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-profileCredentialsProviderWithFile.xml", - getClass())); - - applicationContext.refresh(); - - AWSCredentialsProvider provider = applicationContext.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(provider).isNotNull(); - - assertThat(provider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("testAccessKey"); - assertThat(provider.getCredentials().getAWSSecretKey()) - .isEqualTo("testSecretKey"); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest.java deleted file mode 100644 index 2567238c8..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import java.lang.reflect.Field; - -import com.amazonaws.services.ec2.AmazonEC2Client; -import com.sun.net.httpserver.HttpContext; -import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.BeanReference; -import org.springframework.beans.factory.config.ConstructorArgumentValues; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.context.MetaDataServer; -import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.ReflectionUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Agim Emruli - */ -public class ContextInstanceDataPropertySourceBeanDefinitionParserTest { - - @Test - public void parseInternal_singleElementDefined_beanDefinitionCreated() - throws Exception { - // Arrange - HttpServer httpServer = MetaDataServer.setupHttpServer(); - HttpContext instanceIdHttpContext = httpServer.createContext( - "/latest/meta-data/instance-id", - new MetaDataServer.HttpResponseWriterHandler("testInstanceId")); - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-context.xml", getClass())); - - // Assert - BeanFactoryPostProcessor postProcessor = beanFactory.getBean( - "AmazonEc2InstanceDataPropertySourcePostProcessor", - BeanFactoryPostProcessor.class); - assertThat(postProcessor).isNotNull(); - assertThat(beanFactory.getBeanDefinitionCount()).isEqualTo(1); - - httpServer.removeContext(instanceIdHttpContext); - } - - @Test - public void parseInternal_missingAwsCloudEnvironment_missingBeanDefinition() - throws Exception { - // Arrange - HttpServer httpServer = MetaDataServer.setupHttpServer(); - HttpContext instanceIdHttpContext = httpServer.createContext( - "/latest/meta-data/instance-id", - new MetaDataServer.HttpResponseWriterHandler(null)); - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-context.xml", getClass())); - - // Assert - assertThat(beanFactory - .containsBean("AmazonEc2InstanceDataPropertySourcePostProcessor")) - .isFalse(); - - httpServer.removeContext(instanceIdHttpContext); - } - - @Test - public void parseInternal_singleElementWithUserTagsMapDefined_userTagMapCreatedAlongWithPostProcessor() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-userTagsMap.xml", getClass())); - - // Assert - assertThat(beanFactory.containsBeanDefinition("myUserTags")).isTrue(); - assertThat(beanFactory - .containsBeanDefinition(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonEC2Client.class.getName()))).isTrue(); - } - - @Test - public void parseInternal_singleElementWithCustomAmazonEc2Client_userTagMapCreatedWithCustomEc2Client() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-customEc2Client.xml", getClass())); - - // Assert - assertThat(beanFactory.containsBeanDefinition("myUserTags")).isTrue(); - - ConstructorArgumentValues.ValueHolder valueHolder = beanFactory - .getBeanDefinition("myUserTags").getConstructorArgumentValues() - .getArgumentValue(0, BeanReference.class); - BeanReference beanReference = (BeanReference) valueHolder.getValue(); - assertThat(beanReference.getBeanName()).isEqualTo("amazonEC2Client"); - assertThat(beanFactory - .containsBeanDefinition(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonEC2Client.class.getName()))).isFalse(); - } - - // @checkstyle:off - @Test - public void parseInternal_singleElementWithCustomAttributeAndValueSeparator_postProcessorCreatedWithCustomAttributeAndValueSeparator() - throws Exception { - // @checkstyle:on - // Arrange - HttpServer httpServer = MetaDataServer.setupHttpServer(); - HttpContext instanceIdHttpContext = httpServer.createContext( - "/latest/meta-data/instance-id", - new MetaDataServer.HttpResponseWriterHandler("testInstanceId")); - HttpContext userDataHttpContext = httpServer.createContext("/latest/user-data", - new MetaDataServer.HttpResponseWriterHandler("a=b/c=d")); - - GenericApplicationContext applicationContext = new GenericApplicationContext(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-customAttributeAndValueSeparator.xml", - getClass())); - - applicationContext.refresh(); - - // Assert - assertThat(applicationContext.getEnvironment().getProperty("a")).isEqualTo("b"); - assertThat(applicationContext.getEnvironment().getProperty("c")).isEqualTo("d"); - - httpServer.removeContext(instanceIdHttpContext); - httpServer.removeContext(userDataHttpContext); - } - - @Before - public void restContextInstanceDataCondition() throws IllegalAccessException { - Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.class, - "isCloudEnvironment"); - assertThat(field).isNotNull(); - ReflectionUtils.makeAccessible(field); - field.set(null, null); - } - - @After - public void destroyMetaDataServer() throws Exception { - MetaDataServer.shutdownHttpServer(); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest.java deleted file mode 100644 index 4624158d8..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider; -import org.springframework.cloud.aws.core.region.RegionProvider; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Agim Emruli - */ -public class ContextRegionBeanDefinitionParserTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void parse_staticConfiguredRegion_createsStaticRegionProviderWithSpecifiedRegion() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-context.xml", getClass()); - - // Act - RegionProvider myRegionProvider = context.getBean( - ContextRegionBeanDefinitionParser.CONTEXT_REGION_PROVIDER_BEAN_NAME, - RegionProvider.class); - - // Assert - assertThat(myRegionProvider).isNotNull(); - assertThat(myRegionProvider.getRegion()) - .isEqualTo(Region.getRegion(Regions.SA_EAST_1)); - } - - @Test - public void parse_staticConfiguredRegion_createsStaticRegionProviderWithSpecifiedRegionAsExpression() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithExpression.xml", getClass()); - - // Act - RegionProvider myRegionProvider = context.getBean( - ContextRegionBeanDefinitionParser.CONTEXT_REGION_PROVIDER_BEAN_NAME, - RegionProvider.class); - - // Assert - assertThat(myRegionProvider).isNotNull(); - assertThat(myRegionProvider.getRegion()) - .isEqualTo(Region.getRegion(Regions.SA_EAST_1)); - } - - @Test - public void parse_staticConfiguredRegion_createsStaticRegionProviderWithSpecifiedRegionAsPlaceHolder() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testWithPlaceHolder.xml", getClass()); - - // Act - RegionProvider myRegionProvider = context.getBean( - ContextRegionBeanDefinitionParser.CONTEXT_REGION_PROVIDER_BEAN_NAME, - RegionProvider.class); - - // Assert - assertThat(myRegionProvider).isNotNull(); - assertThat(myRegionProvider.getRegion()) - .isEqualTo(Region.getRegion(Regions.SA_EAST_1)); - } - - @Test - public void parse_autoDetectRegion_returnEc2MetadataRegionProvider() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testAutoDetection.xml", getClass()); - - // Act - RegionProvider myRegionProvider = context.getBean( - ContextRegionBeanDefinitionParser.CONTEXT_REGION_PROVIDER_BEAN_NAME, - RegionProvider.class); - - // Assert - assertThat(myRegionProvider).isNotNull(); - assertThat(myRegionProvider instanceof Ec2MetadataRegionProvider).isTrue(); - } - - @Test - public void parse_customRegionProvider_returnAliasToCustomRegionProvider() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testCustomRegionProvider.xml", getClass()); - - // Act - RegionProvider defaultRegionProvider = context.getBean( - ContextRegionBeanDefinitionParser.CONTEXT_REGION_PROVIDER_BEAN_NAME, - RegionProvider.class); - RegionProvider myRegionProvider = context.getBean("myRegionProvider", - RegionProvider.class); - - // Assert - assertThat(defaultRegionProvider).isNotNull(); - assertThat(myRegionProvider).isNotNull(); - assertThat(myRegionProvider).isSameAs(defaultRegionProvider); - } - - @Test - public void parse_autoDetectionAndStaticRegionProvider_reportsError() - throws Exception { - // Arrange - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException.expectMessage( - "The attribute 'auto-detect' can only be enabled without a region or region-provider specified"); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testAutoDetectionWithConfiguredRegion.xml", - getClass()); - - // Assert - } - - @Test - public void parse_noValidRegionProviderConfigured_reportsError() throws Exception { - // Arrange - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException.expectMessage( - "Either auto-detect must be enabled, or a region or region-provider must be specified"); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() - + "-testNoValidRegionProviderConfigurationSpecified.xml", - getClass()); - - // Assert - } - - @Test - public void parse_twoRegionProviderConfigured_reportsError() throws Exception { - // Arrange - this.expectedException.expect(BeanDefinitionParsingException.class); - this.expectedException - .expectMessage("Multiple elements detected. " - + "The element is only allowed once per application context"); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-testTwoRegionProviderConfigured.xml", - getClass()); - - // Assert - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest.java deleted file mode 100644 index 22dd82faa..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3Client; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.springframework.aop.framework.Advised; -import org.springframework.aop.support.AopUtils; -import org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver; -import org.springframework.context.ResourceLoaderAware; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.ProtocolResolver; -import org.springframework.core.io.ResourceLoader; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Alain Sahli - * @author Agim Emruli - * @since 1.0 - */ -public class ContextResourceLoaderBeanDefinitionParserTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void parseInternal_defaultConfiguration_createsAmazonS3ClientWithoutRegionConfigured() { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-context.xml", getClass()); - - // Act - ResourceLoader resourceLoader = applicationContext - .getBean(ResourceLoaderBean.class).getResourceLoader(); - - // Assert - assertThat(DefaultResourceLoader.class.isInstance(resourceLoader)).isTrue(); - - DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) resourceLoader; - assertThat(SimpleStorageProtocolResolver.class.isInstance( - defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue(); - - } - - @Test - public void parseInternal_configurationWithRegion_createsAmazonS3ClientWithRegionConfigured() { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-withRegionConfigured.xml", getClass()); - - // Act - ResourceLoader resourceLoader = applicationContext - .getBean(ResourceLoaderBean.class).getResourceLoader(); - AmazonS3Client webServiceClient = applicationContext - .getBean(AmazonS3Client.class); - - // Assert - assertThat(webServiceClient.getRegion().toAWSRegion()) - .isEqualTo(Region.getRegion(Regions.EU_WEST_1)); - - assertThat(DefaultResourceLoader.class.isInstance(resourceLoader)).isTrue(); - DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) resourceLoader; - assertThat(SimpleStorageProtocolResolver.class.isInstance( - defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue(); - } - - @Test - public void parseInternal_configurationWithCustomRegionProvider_createsAmazonS3ClientWithRegionConfigured() { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-withCustomRegionProvider.xml", getClass()); - - // Act - ResourceLoader resourceLoader = applicationContext - .getBean(ResourceLoaderBean.class).getResourceLoader(); - AmazonS3Client webServiceClient = applicationContext - .getBean(AmazonS3Client.class); - - // Assert - assertThat(webServiceClient.getRegion().toAWSRegion()) - .isEqualTo(Region.getRegion(Regions.US_WEST_2)); - - assertThat(DefaultResourceLoader.class.isInstance(resourceLoader)).isTrue(); - DefaultResourceLoader defaultResourceLoader = (DefaultResourceLoader) resourceLoader; - assertThat(SimpleStorageProtocolResolver.class.isInstance( - defaultResourceLoader.getProtocolResolvers().iterator().next())).isTrue(); - } - - @Test - public void parseInternal_configurationWithCustomTaskExecutor_createsResourceLoaderWithCustomTaskExecutor() { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-withCustomTaskExecutor.xml", getClass()); - - // Act - - // Assert - assertThat(DefaultResourceLoader.class.isInstance(applicationContext)).isTrue(); - ProtocolResolver protocolResolver = applicationContext.getProtocolResolvers() - .iterator().next(); - assertThat(SimpleStorageProtocolResolver.class.isInstance(protocolResolver)) - .isTrue(); - - assertThat(ReflectionTestUtils.getField(protocolResolver, "taskExecutor")) - .isSameAs(applicationContext.getBean("taskExecutor")); - } - - @Test - public void parseInternal_configurationWithCustomAmazonS3Client_createResourceLoaderWithCustomS3Client() - throws Exception { - // Arrange - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-withCustomS3Client.xml", getClass()); - - // Act - assertThat(DefaultResourceLoader.class.isInstance(applicationContext)).isTrue(); - ProtocolResolver protocolResolver = applicationContext.getProtocolResolvers() - .iterator().next(); - assertThat(SimpleStorageProtocolResolver.class.isInstance(protocolResolver)) - .isTrue(); - - // Assert that the proxied AmazonS2 instances are the same as the customS3Client - // in the app context. - AmazonS3 customS3Client = applicationContext.getBean(AmazonS3.class); - - SimpleStorageProtocolResolver resourceLoader = (SimpleStorageProtocolResolver) protocolResolver; - AmazonS3 amazonS3FromResourceLoader = (AmazonS3) ReflectionTestUtils - .getField(resourceLoader, "amazonS3"); - - assertThat(AopUtils.isAopProxy(amazonS3FromResourceLoader)).isTrue(); - - Advised advised2 = (Advised) amazonS3FromResourceLoader; - AmazonS3 amazonS3WrappedInsideSimpleStorageResourceLoader = (AmazonS3) advised2 - .getTargetSource().getTarget(); - - assertThat(amazonS3WrappedInsideSimpleStorageResourceLoader) - .isSameAs(customS3Client); - } - - static class ResourceLoaderBean implements ResourceLoaderAware { - - private ResourceLoader resourceLoader; - - public ResourceLoader getResourceLoader() { - return this.resourceLoader; - } - - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.java deleted file mode 100644 index d4a170b58..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; - -/** - * @author Alain Sahli - */ -public class ContextSchemaWithoutVersionTest { - - @Test - public void contextXsd_withoutVersion_shouldNotThrowAnException() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act & Assert - reader.loadBeanDefinitions( - new ClassPathResource(getClass().getSimpleName() + ".xml", getClass())); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest.java deleted file mode 100644 index 2ab1dd604..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.config.xml; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.cloudformation.AmazonCloudFormation; -import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; -import com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest; -import com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult; -import com.amazonaws.services.cloudformation.model.DescribeStacksRequest; -import com.amazonaws.services.cloudformation.model.DescribeStacksResult; -import com.amazonaws.services.cloudformation.model.ListStackResourcesRequest; -import com.amazonaws.services.cloudformation.model.ListStackResourcesResult; -import com.amazonaws.services.cloudformation.model.Stack; -import com.amazonaws.services.cloudformation.model.StackResource; -import com.amazonaws.services.cloudformation.model.StackResourceSummary; -import com.sun.net.httpserver.HttpContext; -import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Test; -import org.mockito.Mockito; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.context.MetaDataServer; -import org.springframework.cloud.aws.core.env.ResourceIdResolver; -import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; -import org.springframework.context.support.GenericXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.getBeanName; - -/** - * @author Agim Emruli - * @author Alain Sahli - */ -public class StackConfigurationBeanDefinitionParserTest { - - // @checkstyle:off - @Test - public void parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient() - throws Exception { - // @checkstyle:on - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-withCustomCloudFormationClient.xml", - getClass())); - - AmazonCloudFormation amazonCloudFormationMock = beanFactory - .getBean(AmazonCloudFormation.class); - when(amazonCloudFormationMock.listStackResources( - new ListStackResourcesRequest().withStackName("test"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary())); - when(amazonCloudFormationMock - .describeStacks(new DescribeStacksRequest().withStackName("test"))) - .thenReturn(new DescribeStacksResult().withStacks(new Stack())); - - // Act - StackResourceRegistry stackResourceRegistry = beanFactory - .getBean(StackResourceRegistry.class); - - // Assert - assertThat(stackResourceRegistry).isNotNull(); - assertThat(beanFactory.containsBeanDefinition( - getBeanName(AmazonCloudFormationClient.class.getName()))).isFalse(); - verify(amazonCloudFormationMock, times(1)).listStackResources( - new ListStackResourcesRequest().withStackName("test")); - beanFactory.getBean("customStackTags"); - verify(amazonCloudFormationMock, times(1)) - .describeStacks(new DescribeStacksRequest().withStackName("test")); - } - - @Test - public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCustomRegion() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region.xml", getClass())); - - // Assert - AmazonCloudFormationClient amazonCloudFormation = registry - .getBean(AmazonCloudFormationClient.class); - assertThat( - ReflectionTestUtils.getField(amazonCloudFormation, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.SA_EAST_1) - .getServiceEndpoint("cloudformation")); - } - - @Test - public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientWithCustomRegionReturnedByProvider() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region-provider.xml", getClass())); - - // Assert - AmazonCloudFormationClient amazonCloudFormation = registry - .getBean(AmazonCloudFormationClient.class); - assertThat( - ReflectionTestUtils.getField(amazonCloudFormation, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.AP_SOUTHEAST_2) - .getServiceEndpoint("cloudformation")); - } - - @Test - public void resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed() { - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("IntegrationTestStack"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary())); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-staticStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - - // Act - ResourceIdResolver resourceIdResolver = applicationContext - .getBean(ResourceIdResolver.class); - - // Assert - assertThat(resourceIdResolver).isNotNull(); - } - - // @checkstyle:off - @Test - public void stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName() - throws Exception { - // @checkstyle:on - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("IntegrationTestStack"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary())); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-staticStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - - // Act - StackResourceRegistry staticStackNameProviderBasedStackResourceRegistry = applicationContext - .getBean("IntegrationTestStack", StackResourceRegistry.class); - - // Assert - assertThat(staticStackNameProviderBasedStackResourceRegistry).isNotNull(); - } - - // @checkstyle:off - @Test - public void stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName() - throws Exception { - // @checkstyle:on - // Arrange - HttpServer server = MetaDataServer.setupHttpServer(); - HttpContext httpContext = server.createContext("/latest/meta-data/instance-id", - new MetaDataServer.HttpResponseWriterHandler("foo")); - - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - - when(amazonCloudFormation.describeStackResources( - new DescribeStackResourcesRequest().withPhysicalResourceId("foo"))) - .thenReturn(new DescribeStackResourcesResult().withStackResources( - new StackResource().withStackName("test"))); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("test"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary())); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-autoDetectStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - - // Act - StackResourceRegistry autoDetectingStackNameProviderBasedStackResourceRegistry = applicationContext - .getBean( - "org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean#0", - StackResourceRegistry.class); - - // Assert - assertThat(autoDetectingStackNameProviderBasedStackResourceRegistry).isNotNull(); - - server.removeContext(httpContext); - } - - // @checkstyle:off - @Test - public void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() { - // @checkstyle:on - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("IntegrationTestStack"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary() - .withLogicalResourceId("EmptyBucket") - .withPhysicalResourceId( - "integrationteststack-emptybucket-foo"))); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-staticStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - - ResourceIdResolver resourceIdResolver = applicationContext - .getBean(ResourceIdResolver.class); - - // Act - String physicalResourceId = resourceIdResolver - .resolveToPhysicalResourceId("EmptyBucket"); - - // Assert - assertThat(physicalResourceId).startsWith("integrationteststack-emptybucket-"); - } - - // @checkstyle:off - @Test - public void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() - throws Exception { - // @checkstyle:on - // Arrange - HttpServer server = MetaDataServer.setupHttpServer(); - HttpContext httpContext = server.createContext("/latest/meta-data/instance-id", - new MetaDataServer.HttpResponseWriterHandler("foo")); - - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - when(amazonCloudFormation.describeStackResources( - new DescribeStackResourcesRequest().withPhysicalResourceId("foo"))) - .thenReturn(new DescribeStackResourcesResult().withStackResources( - new StackResource().withStackName("test"))); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("test"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary() - .withLogicalResourceId("EmptyBucket") - .withPhysicalResourceId( - "integrationteststack-emptybucket-foo"))); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-autoDetectStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - - ResourceIdResolver resourceIdResolver = applicationContext - .getBean(ResourceIdResolver.class); - - // Act - String physicalResourceId = resourceIdResolver - .resolveToPhysicalResourceId("EmptyBucket"); - - // Assert - assertThat(physicalResourceId).startsWith("integrationteststack-emptybucket-"); - - server.removeContext(httpContext); - } - - // @checkstyle:off - @Test - public void resourceIdResolverResolveToPhysicalResourceId_logicalResourceIdOfNonExistingResourceProvided_returnsLogicalResourceIdAsPhysicalResourceId() { - // @checkstyle:on - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - AmazonCloudFormation amazonCloudFormation = Mockito - .mock(AmazonCloudFormation.class); - - when(amazonCloudFormation.listStackResources( - new ListStackResourcesRequest().withStackName("IntegrationTestStack"))) - .thenReturn(new ListStackResourcesResult() - .withStackResourceSummaries(new StackResourceSummary())); - - applicationContext.load(new ClassPathResource( - getClass().getSimpleName() + "-staticStackName.xml", getClass())); - applicationContext.getBeanFactory().registerSingleton( - getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation); - - applicationContext.refresh(); - ResourceIdResolver resourceIdResolver = applicationContext - .getBean(ResourceIdResolver.class); - - // Act - String physicalResourceId = resourceIdResolver - .resolveToPhysicalResourceId("nonExistingLogicalResourceId"); - - // Assert - assertThat(physicalResourceId).isEqualTo("nonExistingLogicalResourceId"); - } - - @After - public void destroyMetaDataServer() throws Exception { - MetaDataServer.shutdownHttpServer(); - - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.java deleted file mode 100644 index fb016e554..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.mail.config.xml; - -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; - -/** - * @author Alain Sahli - */ -public class MailSchemaWithoutVersionTest { - - @Test - public void mailXsd_withoutVersion_shouldNotThrowAnException() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act & Assert - reader.loadBeanDefinitions( - new ClassPathResource(getClass().getSimpleName() + ".xml", getClass())); - } - -} diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest.java deleted file mode 100644 index df54e2a49..000000000 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.mail.config.xml; - -import java.lang.reflect.Field; -import java.net.URI; - -import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient; -import org.junit.Test; - -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.mail.MailSender; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.getBeanName; -import static org.springframework.util.ReflectionUtils.findField; -import static org.springframework.util.ReflectionUtils.makeAccessible; - -/** - * @author Agim Emruli - */ -public class SimpleEmailServiceBeanDefinitionParserTest { - - private static String getEndpointUrlFromWebserviceClient( - AmazonSimpleEmailServiceClient client) throws Exception { - Field field = findField(AmazonSimpleEmailServiceClient.class, "endpoint"); - makeAccessible(field); - URI endpointUri = (URI) field.get(client); - return endpointUri.toASCIIString(); - } - - @Test - public void parse_MailSenderWithMinimalConfiguration_createMailSenderWithJavaMail() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-context.xml", getClass()); - - // Act - AmazonSimpleEmailServiceClient emailService = context.getBean( - getBeanName(AmazonSimpleEmailServiceClient.class.getName()), - AmazonSimpleEmailServiceClient.class); - - MailSender mailSender = context.getBean(MailSender.class); - - // Assert - assertThat(getEndpointUrlFromWebserviceClient(emailService)) - .isEqualTo("https://email.us-west-2.amazonaws.com"); - - assertThat(mailSender instanceof JavaMailSender).isTrue(); - } - - @Test - public void parse_MailSenderWithRegionConfiguration_createMailSenderWithJavaMailAndRegion() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-region.xml", getClass()); - - // Act - AmazonSimpleEmailServiceClient emailService = context.getBean( - getBeanName(AmazonSimpleEmailServiceClient.class.getName()), - AmazonSimpleEmailServiceClient.class); - - MailSender mailSender = context.getBean(MailSender.class); - - // Assert - assertThat(getEndpointUrlFromWebserviceClient(emailService)) - .isEqualTo("https://email.eu-west-1.amazonaws.com"); - - assertThat(mailSender instanceof JavaMailSender).isTrue(); - } - - @Test - public void parse_MailSenderWithRegionProviderConfiguration_createMailSenderWithJavaMailAndRegionFromRegionProvider() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-regionProvider.xml", getClass()); - - // Act - AmazonSimpleEmailServiceClient emailService = context.getBean( - getBeanName(AmazonSimpleEmailServiceClient.class.getName()), - AmazonSimpleEmailServiceClient.class); - - MailSender mailSender = context.getBean(MailSender.class); - - // Assert - assertThat(getEndpointUrlFromWebserviceClient(emailService)) - .isEqualTo("https://email.ap-southeast-2.amazonaws.com"); - - assertThat(mailSender instanceof JavaMailSender).isTrue(); - } - - @Test - public void parse_MailSenderWithCustomSesClient_createMailSenderWithCustomSesClient() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-ses-client.xml", getClass()); - - // Act - AmazonSimpleEmailServiceClient emailService = context - .getBean("emailServiceClient", AmazonSimpleEmailServiceClient.class); - - MailSender mailSender = context.getBean(MailSender.class); - - // Assert - assertThat(ReflectionTestUtils.getField(mailSender, "emailService")) - .isSameAs(emailService); - } - -} diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-cacheConfigWithExpiration.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-cacheConfigWithExpiration.xml deleted file mode 100644 index ec05cbede..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-cacheConfigWithExpiration.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-customCache.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-customCache.xml deleted file mode 100644 index 99385d939..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-customCache.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfig.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfig.xml deleted file mode 100644 index 7a1f4cff3..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfig.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigRegionConfigured.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigRegionConfigured.xml deleted file mode 100644 index ca28e3b67..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigRegionConfigured.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigStackConfigured.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigStackConfigured.xml deleted file mode 100644 index 61e2ee59e..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigStackConfigured.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigWithCustomElastiCacheClient.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigWithCustomElastiCacheClient.xml deleted file mode 100644 index d19c1cedf..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-elastiCacheConfigWithCustomElastiCacheClient.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-mixedCacheConfig.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-mixedCacheConfig.xml deleted file mode 100644 index 100eed03c..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheBeanDefinitionParserTest-mixedCacheConfig.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.xml deleted file mode 100644 index 4f1c6c24f..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/cache/config/xml/CacheSchemaWithoutVersionTest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-context.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-context.xml deleted file mode 100644 index cb0db28c7..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-context.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profile b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profile deleted file mode 100644 index 575642206..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profile +++ /dev/null @@ -1,9 +0,0 @@ -[default] -aws_access_key_id=defaultKey -aws_secret_access_key=defaultKey -aws_session_token=defaultToken - -[customProfile] -aws_access_key_id=testAccessKey -aws_secret_access_key=testSecretKey -aws_session_token=testSessionToken diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProvider.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProvider.xml deleted file mode 100644 index fb6d364d0..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProvider.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProviderWithFile.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProviderWithFile.xml deleted file mode 100644 index f47e4403f..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-profileCredentialsProviderWithFile.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testMultipleElements.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testMultipleElements.xml deleted file mode 100644 index aebcd54fe..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testMultipleElements.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptyAccessKey.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptyAccessKey.xml deleted file mode 100644 index 7671c18f5..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptyAccessKey.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptySecretKey.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptySecretKey.xml deleted file mode 100644 index 028c6de08..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithEmptySecretKey.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithExpressions.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithExpressions.xml deleted file mode 100644 index 614870bc1..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithExpressions.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - foo - bar - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithPlaceHolder.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithPlaceHolder.xml deleted file mode 100644 index f21448b20..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextCredentialsBeanDefinitionParserTest-testWithPlaceHolder.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - foo - bar - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-context.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-context.xml deleted file mode 100644 index 536aa9e06..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-context.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customAttributeAndValueSeparator.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customAttributeAndValueSeparator.xml deleted file mode 100644 index 2dc5c5cf4..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customAttributeAndValueSeparator.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customEc2Client.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customEc2Client.xml deleted file mode 100644 index 04eb98f2e..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-customEc2Client.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-userTagsMap.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-userTagsMap.xml deleted file mode 100644 index 0589dfd5a..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextInstanceDataPropertySourceBeanDefinitionParserTest-userTagsMap.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-context.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-context.xml deleted file mode 100644 index 74034c0a1..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-context.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetection.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetection.xml deleted file mode 100644 index ac502fceb..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetection.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetectionWithConfiguredRegion.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetectionWithConfiguredRegion.xml deleted file mode 100644 index 81d4c1f27..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testAutoDetectionWithConfiguredRegion.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testCustomRegionProvider.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testCustomRegionProvider.xml deleted file mode 100644 index d13711223..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testCustomRegionProvider.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testNoValidRegionProviderConfigurationSpecified.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testNoValidRegionProviderConfigurationSpecified.xml deleted file mode 100644 index bfe34eafa..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testNoValidRegionProviderConfigurationSpecified.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testTwoRegionProviderConfigured.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testTwoRegionProviderConfigured.xml deleted file mode 100644 index b3887bee6..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testTwoRegionProviderConfigured.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithExpression.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithExpression.xml deleted file mode 100644 index 9eb07ed8f..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithExpression.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - sa-east-1 - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithPlaceHolder.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithPlaceHolder.xml deleted file mode 100644 index 9c8209eaa..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextRegionBeanDefinitionParserTest-testWithPlaceHolder.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - sa-east-1 - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-context.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-context.xml deleted file mode 100644 index 2d7f2ff9e..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomRegionProvider.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomRegionProvider.xml deleted file mode 100644 index 705afb2f2..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomRegionProvider.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomS3Client.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomS3Client.xml deleted file mode 100644 index 49679d7c9..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomS3Client.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomTaskExecutor.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomTaskExecutor.xml deleted file mode 100644 index 25e4b4af6..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withCustomTaskExecutor.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withRegionConfigured.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withRegionConfigured.xml deleted file mode 100644 index 71d44236b..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextResourceLoaderBeanDefinitionParserTest-withRegionConfigured.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.xml deleted file mode 100644 index ff385c956..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/ContextSchemaWithoutVersionTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-autoDetectStackName.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-autoDetectStackName.xml deleted file mode 100644 index 66be5555e..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-autoDetectStackName.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region-provider.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region-provider.xml deleted file mode 100644 index 482c49040..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region-provider.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region.xml deleted file mode 100644 index 972849357..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-custom-region.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-staticStackName.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-staticStackName.xml deleted file mode 100644 index 282d4d553..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-staticStackName.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-withCustomCloudFormationClient.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-withCustomCloudFormationClient.xml deleted file mode 100644 index 70e7256d3..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/context/config/xml/StackConfigurationBeanDefinitionParserTest-withCustomCloudFormationClient.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.xml deleted file mode 100644 index 02703a0e6..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/MailSchemaWithoutVersionTest.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-context.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-context.xml deleted file mode 100644 index 4d747b13b..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-context.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-region.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-region.xml deleted file mode 100644 index 01b0b1a92..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-region.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-regionProvider.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-regionProvider.xml deleted file mode 100644 index e026f40a6..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-regionProvider.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-ses-client.xml b/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-ses-client.xml deleted file mode 100644 index 739472ffb..000000000 --- a/spring-cloud-aws-context/src/test/resources/org/springframework/cloud/aws/mail/config/xml/SimpleEmailServiceBeanDefinitionParserTest-ses-client.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/config/xml/XmlWebserviceConfigurationUtils.java b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/config/xml/XmlWebserviceConfigurationUtils.java deleted file mode 100644 index 9c0ee03fb..000000000 --- a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/config/xml/XmlWebserviceConfigurationUtils.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.core.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.getAmazonWebserviceClientBeanDefinition; -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.registerAmazonWebserviceClient; - -/** - * @author Agim Emruli - */ -public final class XmlWebserviceConfigurationUtils { - - private static final String REGION_ATTRIBUTE_NAME = "region"; - - private static final String REGION_PROVIDER_ATTRIBUTE_NAME = "region-provider"; - - private XmlWebserviceConfigurationUtils() { - // Avoid instantiation - } - - public static String getCustomClientOrDefaultClientBeanName(Element element, - ParserContext parserContext, String customClientAttributeName, - String serviceClassName) { - if (StringUtils.hasText(element.getAttribute(customClientAttributeName))) { - return element.getAttribute(customClientAttributeName); - } - else { - return parseAndRegisterDefaultAmazonWebserviceClient(element, parserContext, - serviceClassName).getBeanName(); - } - } - - public static AbstractBeanDefinition parseCustomClientElement(Element element, - ParserContext parserContext, String serviceClassName) { - Object source = parserContext.extractSource(element); - try { - return getAmazonWebserviceClientBeanDefinition(source, serviceClassName, - element.getAttribute(REGION_PROVIDER_ATTRIBUTE_NAME), - element.getAttribute(REGION_ATTRIBUTE_NAME), - parserContext.getRegistry()); - } - catch (Exception e) { - parserContext.getReaderContext().error(e.getMessage(), source, e); - return null; - } - } - - private static BeanDefinitionHolder parseAndRegisterDefaultAmazonWebserviceClient( - Element element, ParserContext parserContext, String serviceClassName) { - Object source = parserContext.extractSource(element); - try { - return registerAmazonWebserviceClient(source, parserContext.getRegistry(), - serviceClassName, - element.getAttribute(REGION_PROVIDER_ATTRIBUTE_NAME), - element.getAttribute(REGION_ATTRIBUTE_NAME)); - } - catch (Exception e) { - parserContext.getReaderContext().error(e.getMessage(), source, e); - return null; - } - } - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest.java deleted file mode 100644 index f52ec8477..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.cache; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlElastiCacheAwsTest extends ElastiCacheAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest.java deleted file mode 100644 index 97149d87e..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.context.support.io; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlPathMatchingResourceLoaderAwsTest - extends PathMatchingResourceLoaderAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest.java deleted file mode 100644 index fc3a687b0..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// CHECKSTYLE:OFF -// Checkstyle is disabled because in test 'testUploadBigFileAndCompareChecksum' -// there is a needed while loop without a statement inside. - -package org.springframework.cloud.aws.context.support.io; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlResourceLoaderAwsTest extends ResourceLoaderAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest.java deleted file mode 100644 index 078e85d39..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.core.env.ec2; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlAmazonEc2InstanceDataPropertySourceAwsTest - extends AmazonEc2InstanceDataPropertySourceAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest.java deleted file mode 100644 index 9c7778100..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.core.env.stack; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlStackConfigurationAwsTest extends StackConfigurationAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest.java deleted file mode 100644 index 9f0562202..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc; - -import org.junit.Test; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.test.context.ContextConfiguration; - -import static org.junit.Assert.assertEquals; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlDataSourceFactoryBeanAwsTest extends DataSourceFactoryBeanAwsTest { - - @Value("#{dbTags['aws:cloudformation:logical-id']}") - private String dbLogicalName; - - @Test - public void testDatabaseInstanceUserProperties() throws Exception { - assertEquals("RdsSingleMicroInstance", this.dbLogicalName); - } - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest.java deleted file mode 100644 index 6168dbce1..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.mail; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Agim Emruli - */ -@ContextConfiguration -public class XmlMailSenderAwsTest extends MailSenderAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest.java deleted file mode 100644 index a17ca815a..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Alain Sahli - */ -@ContextConfiguration -public class XmlMessageListenerContainerAwsTest extends MessageListenerContainerAwsTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest.java deleted file mode 100644 index 9621cfe48..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Alain Sahli - */ -@ContextConfiguration -public class XmlNotificationMessagingTemplateIntegrationTest - extends NotificationMessagingTemplateIntegrationTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueListenerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueListenerTest.java deleted file mode 100644 index 22f2c85e3..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueListenerTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Alain Sahli - */ -@ContextConfiguration -public class XmlQueueListenerTest extends QueueListenerTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest.java deleted file mode 100644 index 5db7d7567..000000000 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Alain Sahli - */ -@ContextConfiguration -public class XmlQueueMessagingTemplateIntegrationTest - extends QueueMessagingTemplateIntegrationTest { - -} diff --git a/spring-cloud-aws-integration-test/src/test/resources/Integration-test-context.xml b/spring-cloud-aws-integration-test/src/test/resources/Integration-test-context.xml deleted file mode 100644 index 8e4f6c80c..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/Integration-test-context.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest-context.xml deleted file mode 100644 index c8c5d578d..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/cache/XmlElastiCacheAwsTest-context.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest-context.xml deleted file mode 100644 index 566b18fa1..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlPathMatchingResourceLoaderAwsTest-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest-context.xml deleted file mode 100644 index 566b18fa1..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/context/support/io/XmlResourceLoaderAwsTest-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest-context.xml deleted file mode 100644 index b91443b5d..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest-context.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest-context.xml deleted file mode 100644 index ebbdbf007..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/ec2/XmlAmazonEc2InstanceDataPropertySourceAwsTest-context.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest-context.xml deleted file mode 100644 index be860235b..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest-context.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest-context.xml deleted file mode 100644 index 416563044..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/core/env/stack/XmlStackConfigurationAwsTest-context.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest-context.xml deleted file mode 100644 index 812738e29..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/jdbc/XmlDataSourceFactoryBeanAwsTest-context.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest-context.xml deleted file mode 100644 index 572fbd2e3..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/mail/XmlMailSenderAwsTest-context.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest-context.xml deleted file mode 100644 index c000d09a1..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlMessageListenerContainerAwsTest-context.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest-context.xml deleted file mode 100644 index 19873dbe4..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlNotificationMessagingTemplateIntegrationTest-context.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueListenerTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueListenerTest-context.xml deleted file mode 100644 index f5fdffc4d..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueListenerTest-context.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest-context.xml b/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest-context.xml deleted file mode 100644 index 2eabea042..000000000 --- a/spring-cloud-aws-integration-test/src/test/resources/org/springframework/cloud/aws/messaging/XmlQueueMessagingTemplateIntegrationTest-context.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParser.java b/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParser.java deleted file mode 100644 index 78e37b7c9..000000000 --- a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParser.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.MethodInvokingFactoryBean; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.cloud.aws.jdbc.datasource.TomcatJdbcDataSourceFactory; -import org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean; -import org.springframework.cloud.aws.jdbc.rds.AmazonRdsReadReplicaAwareDataSourceFactoryBean; -import org.springframework.core.Conventions; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} parser - * implementation for the datasource element. Parses the element and constructs a fully - * configured {@link AmazonRdsDataSourceFactoryBean} bean definition. Also creates a bean - * definition for the {@link com.amazonaws.services.rds.AmazonRDSClient} if there is not - * already an existing one this application context. - * - * @author Agim Emruli - * @since 1.0 - */ -class AmazonRdsDataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser { - - static final String DB_INSTANCE_IDENTIFIER = "db-instance-identifier"; - - private static final String AMAZON_RDS_CLIENT_CLASS_NAME = "com.amazonaws.services.rds.AmazonRDSClient"; - - // @checkstyle:off - private static final String IDENTITY_MANAGEMENT_CLIENT_CLASS_NAME = "com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient"; - - // @checkstyle:on - - // @checkstyle:off - private static final String USER_TAG_FACTORY_BEAN_CLASS_NAME = "org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceUserTagsFactoryBean"; - - // @checkstyle:on - - private static final String USERNAME = "username"; - - private static final String PASSWORD = "password"; - - private static final String DATABASE_NAME = "database-name"; - - /** - * Creates a {@link org.springframework.cloud.aws.jdbc.datasource.DataSourceFactory} - * implementation. Uses the TomcatJdbcDataSourceFactory implementation and passes all - * pool attributes from the xml directly to the class (through setting the bean - * properties). - * @param element - The datasource element which may contain a pool-attributes element - * @return - fully configured bean definition for the DataSourceFactory - */ - private static AbstractBeanDefinition createDataSourceFactoryBeanDefinition( - Element element) { - BeanDefinitionBuilder datasourceFactoryBuilder = BeanDefinitionBuilder - .rootBeanDefinition(TomcatJdbcDataSourceFactory.class); - Element poolAttributes = DomUtils.getChildElementByTagName(element, - "pool-attributes"); - if (poolAttributes != null) { - NamedNodeMap attributes = poolAttributes.getAttributes(); - for (int i = 0, x = attributes.getLength(); i < x; i++) { - Node item = attributes.item(i); - datasourceFactoryBuilder.addPropertyValue(item.getNodeName(), - item.getNodeValue()); - } - } - - return datasourceFactoryBuilder.getBeanDefinition(); - } - - private static void registerUserTagsMapIfNecessary(Element element, - ParserContext parserContext, String rdsClientBeanName) { - if (!StringUtils.hasText(element.getAttribute("user-tags-map"))) { - return; - } - - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .genericBeanDefinition(USER_TAG_FACTORY_BEAN_CLASS_NAME); - builder.addConstructorArgReference(rdsClientBeanName); - builder.addConstructorArgValue(element.getAttribute(DB_INSTANCE_IDENTIFIER)); - builder.addConstructorArgReference(getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-identity-management", - IDENTITY_MANAGEMENT_CLIENT_CLASS_NAME)); - - // Use custom region-provider of data source - if (StringUtils.hasText(element.getAttribute("region"))) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .genericBeanDefinition("com.amazonaws.regions.Region"); - beanDefinitionBuilder.setFactoryMethod("getRegion"); - beanDefinitionBuilder.addConstructorArgValue(element.getAttribute("region")); - builder.addPropertyValue("region", beanDefinitionBuilder.getBeanDefinition()); - } - else { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .genericBeanDefinition(MethodInvokingFactoryBean.class); - if (StringUtils.hasText(element.getAttribute("region-provider"))) { - beanDefinitionBuilder.addPropertyValue("targetObject", - new RuntimeBeanReference( - element.getAttribute("region-provider"))); - } - else { - beanDefinitionBuilder.addPropertyValue("targetObject", - new RuntimeBeanReference(AmazonWebserviceClientConfigurationUtils - .getRegionProviderBeanName(parserContext.getRegistry()))); - } - beanDefinitionBuilder.addPropertyValue("targetMethod", "getRegion"); - builder.addPropertyValue("region", beanDefinitionBuilder.getBeanDefinition()); - } - - String resourceResolverBeanName = GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry()); - builder.addPropertyReference("resourceIdResolver", resourceResolverBeanName); - - parserContext.getRegistry().registerBeanDefinition( - element.getAttribute("user-tags-map"), builder.getBeanDefinition()); - } - - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext parserContext) { - BeanDefinitionBuilder datasourceBuilder = getBeanDefinitionBuilderForDataSource( - element); - - // Constructor (mandatory) args - String amazonRdsClientBeanName = getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-rds", AMAZON_RDS_CLIENT_CLASS_NAME); - datasourceBuilder.addConstructorArgReference(amazonRdsClientBeanName); - datasourceBuilder - .addConstructorArgValue(element.getAttribute(DB_INSTANCE_IDENTIFIER)); - datasourceBuilder.addConstructorArgValue(element.getAttribute(PASSWORD)); - - // optional args - if (StringUtils.hasText(element.getAttribute(USERNAME))) { - datasourceBuilder.addPropertyValue(USERNAME, element.getAttribute(USERNAME)); - } - - if (StringUtils.hasText(element.getAttribute(DATABASE_NAME))) { - datasourceBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(DATABASE_NAME), - element.getAttribute(DATABASE_NAME)); - } - - datasourceBuilder.addPropertyValue("dataSourceFactory", - createDataSourceFactoryBeanDefinition(element)); - - // Register registry to enable cloud formation support - String resourceResolverBeanName = GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry()); - datasourceBuilder.addPropertyReference("resourceIdResolver", - resourceResolverBeanName); - - registerUserTagsMapIfNecessary(element, parserContext, amazonRdsClientBeanName); - - return datasourceBuilder.getBeanDefinition(); - } - - private BeanDefinitionBuilder getBeanDefinitionBuilderForDataSource(Element element) { - BeanDefinitionBuilder datasourceBuilder; - if (Boolean.TRUE.toString() - .equalsIgnoreCase(element.getAttribute("read-replica-support"))) { - datasourceBuilder = BeanDefinitionBuilder.rootBeanDefinition( - AmazonRdsReadReplicaAwareDataSourceFactoryBean.class); - } - else { - datasourceBuilder = BeanDefinitionBuilder - .rootBeanDefinition(AmazonRdsDataSourceFactoryBean.class); - } - return datasourceBuilder; - } - - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, - ParserContext parserContext) throws BeanDefinitionStoreException { - return element.getAttribute(DB_INSTANCE_IDENTIFIER); - } - -} diff --git a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParser.java b/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParser.java deleted file mode 100644 index 26e29baa5..000000000 --- a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParser.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.jdbc.retry.DatabaseInstanceStatusRetryPolicy; -import org.springframework.cloud.aws.jdbc.retry.RdbmsRetryOperationsInterceptor; -import org.springframework.cloud.aws.jdbc.retry.SqlRetryPolicy; -import org.springframework.core.Conventions; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} implementation for - * the retry-interceptor element. This parser produces a - * {@link org.aopalliance.intercept.MethodInterceptor} which can be used by advice to - * intercept method calls and retry their particular operation. - * - * @author Agim Emruli - * @since 1.0 - */ -class AmazonRdsRetryInterceptorBeanDefinitionParser - extends AbstractSingleBeanDefinitionParser { - - /** - * Class name for the RetryTemplate. String because retry support is optional. - */ - private static final String RETRY_OPERATIONS_CLASS_NAME = "org.springframework.retry.support.RetryTemplate"; - - /** - * Class name used for the policy, which is a composition of two policies (database - * instance status and SQL error code). - */ - // @checkstyle:off - private static final String COMPOSITE_RETRY_POLICY_CLASS_NAME = "org.springframework.retry.policy.CompositeRetryPolicy"; - - // @checkstyle:on - - /** - * Attribute name for the number of retries that should be done. - */ - private static final String MAX_NUMBER_OF_RETRIES = "max-number-of-retries"; - - /** - * Attribute name to a custom back off policy. - */ - private static final String BACK_OFF_POLICY = "back-off-policy"; - - private static final String AMAZON_RDS_CLIENT_CLASS_NAME = "com.amazonaws.services.rds.AmazonRDSClient"; - - /** - * Builds the RetryOperation {@link BeanDefinition} with its collaborators. - * @param element - retry-interceptor Element - * @param parserContext - ParserContext used to query the - * {@link org.springframework.beans.factory.support.BeanDefinitionRegistry} - * @return Configured but non registered bean definition - */ - private static BeanDefinition buildRetryOperationDefinition(Element element, - ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .rootBeanDefinition(RETRY_OPERATIONS_CLASS_NAME); - builder.addPropertyValue("retryPolicy", - buildRetryPolicyDefinition(element, parserContext)); - - if (StringUtils.hasText(element.getAttribute(BACK_OFF_POLICY))) { - String backOffPolicyBeanName = element.getAttribute(BACK_OFF_POLICY); - builder.addPropertyReference( - Conventions.attributeNameToPropertyName(BACK_OFF_POLICY), - backOffPolicyBeanName); - } - - return builder.getBeanDefinition(); - } - - private static BeanDefinition buildRetryPolicyDefinition(Element element, - ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .rootBeanDefinition(COMPOSITE_RETRY_POLICY_CLASS_NAME); - - ManagedList policies = new ManagedList<>(2); - policies.add(buildDatabaseInstancePolicy(element, parserContext)); - policies.add(buildSQLRetryPolicy(element)); - - builder.addPropertyValue("policies", policies); - - return builder.getBeanDefinition(); - } - - private static BeanDefinition buildDatabaseInstancePolicy(Element element, - ParserContext parserContext) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(DatabaseInstanceStatusRetryPolicy.class); - - String amazonRdsClientBeanName = getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-rds", AMAZON_RDS_CLIENT_CLASS_NAME); - - beanDefinitionBuilder.addConstructorArgReference(amazonRdsClientBeanName); - beanDefinitionBuilder.addConstructorArgValue(element.getAttribute( - AmazonRdsDataSourceBeanDefinitionParser.DB_INSTANCE_IDENTIFIER)); - - String resourceIdResolverBeanName = GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry()); - beanDefinitionBuilder.addPropertyReference("resourceIdResolver", - resourceIdResolverBeanName); - - return beanDefinitionBuilder.getBeanDefinition(); - } - - private static BeanDefinition buildSQLRetryPolicy(Element element) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(SqlRetryPolicy.class); - if (StringUtils.hasText(element.getAttribute(MAX_NUMBER_OF_RETRIES))) { - beanDefinitionBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(MAX_NUMBER_OF_RETRIES), - element.getAttribute(MAX_NUMBER_OF_RETRIES)); - } - return beanDefinitionBuilder.getBeanDefinition(); - } - - @Override - protected Class getBeanClass(Element element) { - return RdbmsRetryOperationsInterceptor.class; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - builder.addPropertyValue("retryOperations", - buildRetryOperationDefinition(element, parserContext)); - } - -} diff --git a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcNamespaceHandler.java b/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcNamespaceHandler.java deleted file mode 100644 index b2e496846..000000000 --- a/spring-cloud-aws-jdbc/src/main/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcNamespaceHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; - -/** - * {@link org.springframework.beans.factory.xml.NamespaceHandler} implementation for the - * Spring Cloud AWS jdbc namespace. - * - * @author Agim Emruli - * @since 1.0 - */ -@RuntimeUse -public class JdbcNamespaceHandler extends NamespaceHandlerSupport { - - @Override - public void init() { - registerBeanDefinitionParser("data-source", - new AmazonRdsDataSourceBeanDefinitionParser()); - registerBeanDefinitionParser("retry-interceptor", - new AmazonRdsRetryInterceptorBeanDefinitionParser()); - } - -} diff --git a/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.handlers b/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.handlers deleted file mode 100644 index 9527e8ee9..000000000 --- a/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.handlers +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/jdbc=org.springframework.cloud.aws.jdbc.config.xml.JdbcNamespaceHandler diff --git a/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.schemas b/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.schemas deleted file mode 100644 index b9a641228..000000000 --- a/spring-cloud-aws-jdbc/src/main/resources/META-INF/spring.schemas +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/jdbc/spring-cloud-aws-jdbc-1.0.xsd=org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.0.xsd -http\://www.springframework.org/schema/cloud/aws/jdbc/spring-cloud-aws-jdbc-1.2.xsd=org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/jdbc/spring-cloud-aws-jdbc.xsd=org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd diff --git a/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.0.xsd b/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.0.xsd deleted file mode 100644 index cf8edb0c7..000000000 --- a/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.0.xsd +++ /dev/null @@ -1,450 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - The pool properties used for the underlying connection pool - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - element. - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The default auto-commit state of connections created by this pool. - - - - - - - The default read-only state of connections created by this pool. If - not set then the setReadOnly - method will not be called. - - - - - - - The default TransactionIsolation state of connections created by this - pool. If not set, - the method will not be called and it defaults to the JDBC driver. - - - - - - - - - - - - - - - - The default TransactionIsolation names of connections created by this - pool. If not set, - the method will not be called and it defaults to the JDBC driver. - - - - - - - - - - - - - - - - The default catalog of connections created by this pool. - - - - - - - The maximum number of active connections that can be allocated from - this pool at the same time. - - - - - - - The maximum number of active connections that can be allocated from - this pool at the same time. - - - - - - - The maximum number of connections that should be kept in the pool at - all times. Default value is - maxActive:100 Idle connections are checked periodically (if enabled) - and connections that been idle - for longer than minEvictableIdleTimeMillis will be released. (also see - testWhileIdle) - - - - - - - The initial number of connections that are created when the pool is - started. - - - - - - - The maximum number of milliseconds that the pool will wait (when there - are no available connections) - for a connection to be returned before throwing an exception. - - - - - - - The indication of whether objects will be validated before being - borrowed from the pool. If the - object fails to validate, it will be dropped from the pool, and we - will attempt to borrow another. - NOTE - for a true value to have any effect, the validationQuery - attribute must be set to a non-null - string. In order to have a more efficient validation, see - validationInterval. - - - - - - - The indication of whether objects will be validated before being - returned to the pool. NOTE - for a - true value to have any effect, the validationQuery parameter must be - set to a non-null string. - - - - - - - The indication of whether objects will be validated by the idle object - evictor (if any). If an - object fails to validate, it will be dropped from the pool. NOTE - for - a true value to have any - effect, the validationQuery attribute must be set to a non-null - string. This attribute has to be set - in order for the pool cleaner/test thread is to run (also see - timeBetweenEvictionRunsMillis) - - - - - - - The SQL query that will be used to validate connections from this pool - before returning them to the - caller. If specified, this query does not have to return any data, it - just can't throw a - SQLException. The default value is null. Example values are SELECT - 1(mysql), select 1 from - dual(oracle), SELECT 1(MS Sql Server) - - - - - - - The name of a class which implements the - org.apache.tomcat.jdbc.pool.Validator interface and - provides a no-arg constructor (may be implicit). If specified, the - class will be used to create a - Validator instance which is then used instead of any validation query - to validate connections. The - default value is null. An example value is - com.company.project.SimpleValidator. - - - - - - - The number of milliseconds to sleep between runs of the idle - connection validation/cleaner thread. - This value should not be set under 1 second. It dictates how often we - check for idle, abandoned - connections, and how often we validate idle connections. - - - - - - - The minimum amount of time an object may sit idle in the pool before - it is eligible for eviction. - - - - - - - Flag to remove abandoned connections if they exceed the - removeAbandonedTimeout. If set to true a - connection is considered abandoned and eligible for removal if it has - been in use longer than the - removeAbandonedTimeout Setting this to true can recover db connections - from applications that fail - to close a connection. See also logAbandoned. - - - - - - - Timeout in seconds before an abandoned(in use) connection can be - removed. The default value is 60 - (seconds). The value should be set to the longest running query your - applications might have. - - - - - - - Flag to log stack traces for application code which abandoned a - Connection. Logging of abandoned - Connections adds overhead for every Connection borrow because a stack - trace has to be generated. - - - - - - - The connection properties that will be sent to our JDBC driver when - establishing new connections. - Format of the string must be [propertyName=property;]* - - - - - - - A custom query to be run when a connection is first created. - - - - - diff --git a/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd b/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd deleted file mode 100644 index cf8edb0c7..000000000 --- a/spring-cloud-aws-jdbc/src/main/resources/org/springframework/cloud/aws/jdbc/config/xml/spring-cloud-aws-jdbc-1.2.xsd +++ /dev/null @@ -1,450 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - The pool properties used for the underlying connection pool - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - element. - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The default auto-commit state of connections created by this pool. - - - - - - - The default read-only state of connections created by this pool. If - not set then the setReadOnly - method will not be called. - - - - - - - The default TransactionIsolation state of connections created by this - pool. If not set, - the method will not be called and it defaults to the JDBC driver. - - - - - - - - - - - - - - - - The default TransactionIsolation names of connections created by this - pool. If not set, - the method will not be called and it defaults to the JDBC driver. - - - - - - - - - - - - - - - - The default catalog of connections created by this pool. - - - - - - - The maximum number of active connections that can be allocated from - this pool at the same time. - - - - - - - The maximum number of active connections that can be allocated from - this pool at the same time. - - - - - - - The maximum number of connections that should be kept in the pool at - all times. Default value is - maxActive:100 Idle connections are checked periodically (if enabled) - and connections that been idle - for longer than minEvictableIdleTimeMillis will be released. (also see - testWhileIdle) - - - - - - - The initial number of connections that are created when the pool is - started. - - - - - - - The maximum number of milliseconds that the pool will wait (when there - are no available connections) - for a connection to be returned before throwing an exception. - - - - - - - The indication of whether objects will be validated before being - borrowed from the pool. If the - object fails to validate, it will be dropped from the pool, and we - will attempt to borrow another. - NOTE - for a true value to have any effect, the validationQuery - attribute must be set to a non-null - string. In order to have a more efficient validation, see - validationInterval. - - - - - - - The indication of whether objects will be validated before being - returned to the pool. NOTE - for a - true value to have any effect, the validationQuery parameter must be - set to a non-null string. - - - - - - - The indication of whether objects will be validated by the idle object - evictor (if any). If an - object fails to validate, it will be dropped from the pool. NOTE - for - a true value to have any - effect, the validationQuery attribute must be set to a non-null - string. This attribute has to be set - in order for the pool cleaner/test thread is to run (also see - timeBetweenEvictionRunsMillis) - - - - - - - The SQL query that will be used to validate connections from this pool - before returning them to the - caller. If specified, this query does not have to return any data, it - just can't throw a - SQLException. The default value is null. Example values are SELECT - 1(mysql), select 1 from - dual(oracle), SELECT 1(MS Sql Server) - - - - - - - The name of a class which implements the - org.apache.tomcat.jdbc.pool.Validator interface and - provides a no-arg constructor (may be implicit). If specified, the - class will be used to create a - Validator instance which is then used instead of any validation query - to validate connections. The - default value is null. An example value is - com.company.project.SimpleValidator. - - - - - - - The number of milliseconds to sleep between runs of the idle - connection validation/cleaner thread. - This value should not be set under 1 second. It dictates how often we - check for idle, abandoned - connections, and how often we validate idle connections. - - - - - - - The minimum amount of time an object may sit idle in the pool before - it is eligible for eviction. - - - - - - - Flag to remove abandoned connections if they exceed the - removeAbandonedTimeout. If set to true a - connection is considered abandoned and eligible for removal if it has - been in use longer than the - removeAbandonedTimeout Setting this to true can recover db connections - from applications that fail - to close a connection. See also logAbandoned. - - - - - - - Timeout in seconds before an abandoned(in use) connection can be - removed. The default value is 60 - (seconds). The value should be set to the longest running query your - applications might have. - - - - - - - Flag to log stack traces for application code which abandoned a - Connection. Logging of abandoned - Connections adds overhead for every Connection borrow because a stack - trace has to be generated. - - - - - - - The connection properties that will be sent to our JDBC driver when - establishing new connections. - Format of the string must be [propertyName=property;]* - - - - - - - A custom query to be run when a connection is first created. - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest.java deleted file mode 100644 index ee7a100ac..000000000 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest.java +++ /dev/null @@ -1,489 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import java.util.Date; -import java.util.Map; - -import javax.sql.DataSource; - -import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; -import com.amazonaws.services.identitymanagement.model.GetUserResult; -import com.amazonaws.services.identitymanagement.model.User; -import com.amazonaws.services.rds.AmazonRDS; -import com.amazonaws.services.rds.AmazonRDSClient; -import com.amazonaws.services.rds.model.DBInstance; -import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; -import com.amazonaws.services.rds.model.DescribeDBInstancesResult; -import com.amazonaws.services.rds.model.Endpoint; -import com.amazonaws.services.rds.model.ListTagsForResourceRequest; -import com.amazonaws.services.rds.model.ListTagsForResourceResult; -import com.amazonaws.services.rds.model.Tag; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.springframework.beans.BeanWrapper; -import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.beans.PropertyValue; -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.cloud.aws.jdbc.rds.AmazonRdsReadReplicaAwareDataSourceFactoryBean; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -/** - * Tests for the {@link AmazonRdsDataSourceBeanDefinitionParser} bean definition parser. - * - * @author Agim Emruli - * @since 1.0 - */ -public class AmazonRdsDataSourceBeanDefinitionParserTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - - @Test - public void parseInternal_minimalConfiguration_createsBeanDefinitionWithoutReadReplicas() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-minimal.xml", getClass())); - - AmazonRDS client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), AmazonRDS.class); - - when(client.describeDBInstances( - new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) - .thenReturn(new DescribeDBInstancesResult().withDBInstances( - new DBInstance().withDBInstanceStatus("available") - .withDBName("test") - .withDBInstanceIdentifier("test") - .withEngine("mysql").withMasterUsername("admin") - .withEndpoint(new Endpoint() - .withAddress("localhost").withPort(3306)) - .withReadReplicaDBInstanceIdentifiers("read1"))); - - // Act - DataSource dataSource = beanFactory.getBean(DataSource.class); - - // Assert - assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue(); - } - - @Test - public void parseInternal_readReplicaSupportEnabled_configuresReadReplicaEnabledFactoryBean() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-readReplicaEnabled.xml", getClass())); - - // Act - BeanDefinition beanDefinition = beanFactory.getBeanDefinition("test"); - - // Assert - assertThat(beanDefinition.getBeanClassName()).isEqualTo( - AmazonRdsReadReplicaAwareDataSourceFactoryBean.class.getName()); - } - - @Test - public void parseInternal_noCredentialsDefined_returnsClientWithDefaultCredentialsProvider() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-noCredentials.xml", getClass())); - - AmazonRDS client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), AmazonRDS.class); - - when(client.describeDBInstances( - new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) - .thenReturn(new DescribeDBInstancesResult().withDBInstances( - new DBInstance().withDBInstanceStatus("available") - .withDBName("test") - .withDBInstanceIdentifier("test") - .withEngine("mysql").withMasterUsername("admin") - .withEndpoint(new Endpoint() - .withAddress("localhost").withPort(3306)) - .withReadReplicaDBInstanceIdentifiers("read1"))); - - // Act - DataSource dataSource = beanFactory.getBean(DataSource.class); - - // Assert - assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue(); - } - - @Test - public void parseInternal_fullConfiguration_createsBeanDefinitionWithoutReadReplicas() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-fullConfiguration.xml", getClass())); - - AmazonRDS client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), AmazonRDS.class); - - when(client.describeDBInstances( - new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) - .thenReturn( - new DescribeDBInstancesResult().withDBInstances( - new DBInstance().withDBInstanceStatus("available") - .withDBName("test") - .withDBInstanceIdentifier("test") - .withEngine("mysql") - .withEndpoint(new Endpoint() - .withAddress("localhost") - .withPort(3306)))); - - BeanDefinition definition = beanFactory.getBeanDefinition("test"); - assertThat(definition.getConstructorArgumentValues() - .getArgumentValue(1, String.class).getValue()).isEqualTo("test"); - assertThat(definition.getConstructorArgumentValues() - .getArgumentValue(2, String.class).getValue()).isEqualTo("password"); - assertThat(definition.getPropertyValues().getPropertyValue("username").getValue()) - .isEqualTo("myUser"); - assertThat(definition.getPropertyValues().getPropertyValue("databaseName") - .getValue()).isEqualTo("fooDb"); - - DataSource dataSource = beanFactory.getBean(DataSource.class); - - // Assert - assertThat(dataSource).isNotNull(); - assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue(); - } - - @Test - public void parseInternal_dataSourceWithConfiguredPoolAttributes_poolAttributesConfigured() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-poolAttributes.xml", getClass())); - - BeanDefinition definition = beanFactory.getBeanDefinition("test"); - - // Act - BeanDefinition dataSourceFactory = (BeanDefinition) definition.getPropertyValues() - .getPropertyValue("dataSourceFactory").getValue(); - - // Assert - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("connectionProperties").getValue()) - .isEqualTo("foo=bar"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("defaultAutoCommit").getValue()) - .isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("defaultCatalog").getValue()).isEqualTo("mySchema"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("defaultReadOnly").getValue()) - .isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("defaultTransactionIsolation").getValue()) - .isEqualTo("2"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("initialSize") - .getValue()).isEqualTo("10"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("initSQL") - .getValue()).isEqualTo("SET CURRENT SCHEMA"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("logAbandoned") - .getValue()).isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("maxActive") - .getValue()).isEqualTo("10"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("maxIdle") - .getValue()).isEqualTo("5"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("maxWait") - .getValue()).isEqualTo("10000"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("minEvictableIdleTimeMillis").getValue()) - .isEqualTo("60000"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("minIdle") - .getValue()).isEqualTo("20"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("removeAbandonedTimeout").getValue()).isEqualTo("61"); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("testOnBorrow") - .getValue()).isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("testOnReturn") - .getValue()).isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues().getPropertyValue("testWhileIdle") - .getValue()).isEqualTo(Boolean.TRUE.toString()); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("timeBetweenEvictionRunsMillis").getValue()) - .isEqualTo("4000"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("validationQuery").getValue()).isEqualTo("SELECT 1"); - assertThat(dataSourceFactory.getPropertyValues() - .getPropertyValue("validatorClassName").getValue()) - .isEqualTo(SampleValidator.class.getName()); - } - - @Test - // As we provide default in the schema for better code completion we should check if - // they match to the underlying pool defaults - public void parseInternal_defaultPoolAttribute_matchesPoolConfiguration() - throws Exception { - // Arrange - PoolProperties poolProperties = new PoolProperties(); - - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-defaultPoolAttributes.xml", getClass())); - - // Act - BeanDefinition definition = beanFactory.getBeanDefinition("test"); - BeanDefinition dataSourceFactory = (BeanDefinition) definition.getPropertyValues() - .getPropertyValue("dataSourceFactory").getValue(); - - // Assert - BeanWrapper beanWrapper = PropertyAccessorFactory - .forBeanPropertyAccess(poolProperties); - - for (PropertyValue propertyValue : dataSourceFactory.getPropertyValues() - .getPropertyValueList()) { - assertThat(propertyValue.getValue()).isEqualTo( - beanWrapper.getPropertyValue(propertyValue.getName()).toString()); - } - } - - @Test - public void parseInternal_customRegionConfigured_amazonRdsClientWithCustomRegionConfigured() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-customRegion.xml", getClass())); - - // Act - AmazonRDS amazonRDS = beanFactory.getBean(AmazonRDS.class); - - // Assert - // have to use reflection utils - assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()) - .isEqualTo("https://rds.eu-west-1.amazonaws.com"); - } - - @Test - public void parseInternal_custRegionProviderConf_amazRdsClientWithCustomRegionConfThatIsReturnedFromRegionProvider() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-customRegionProvider.xml", getClass())); - - // Act - AmazonRDS amazonRDS = beanFactory.getBean(AmazonRDS.class); - - // Assert - // have to use reflection utils - assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()) - .isEqualTo("https://rds.eu-west-1.amazonaws.com"); - - } - - @Test - public void parseInternal_customRegionProviderAndRegionConfigured_reportsError() - throws Exception { - // Arrange - this.expectedException.expect(BeanDefinitionStoreException.class); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRegionProviderAndRegion.xml", - getClass()); - - // Assert - } - - @Test - public void parseInternal_userTagsDefined_createsUserTagBeanDefinition() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - beanDefinitionBuilder.setFactoryMethod("mock"); - beanDefinitionBuilder.addConstructorArgValue(AmazonRDS.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), - beanDefinitionBuilder.getBeanDefinition()); - - BeanDefinitionBuilder identityBuilder = BeanDefinitionBuilder - .rootBeanDefinition(Mockito.class); - identityBuilder.setFactoryMethod("mock"); - identityBuilder.addConstructorArgValue(AmazonIdentityManagement.class); - beanFactory.registerBeanDefinition( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonIdentityManagement.class.getName()), - identityBuilder.getBeanDefinition()); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-userTags.xml", getClass())); - - AmazonRDS client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()), AmazonRDS.class); - AmazonIdentityManagement amazonIdentityManagement = beanFactory.getBean( - AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonIdentityManagement.class.getName()), - AmazonIdentityManagement.class); - - when(amazonIdentityManagement.getUser()).thenReturn( - new GetUserResult().withUser(new User("/", "aemruli", "123456789012", - "arn:aws:iam::1234567890:user/aemruli", new Date()))); - when(client.listTagsForResource(new ListTagsForResourceRequest() - .withResourceName("arn:aws:rds:us-west-2:1234567890:db:test"))) - .thenReturn(new ListTagsForResourceResult().withTagList( - new Tag().withKey("key1").withValue("value2"))); - - // Act - Map dsTags = beanFactory.getBean("dsTags", Map.class); - - // Assert - assertThat(dsTags.get("key1")).isEqualTo("value2"); - } - - @Test - public void parseInternal_customRdsInstance_createsRdsBeanAndUserTagsWithCustomRdsInstance() - throws Exception { - - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - - XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader( - beanFactory); - xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-customRdsInstance.xml", getClass())); - - AmazonRDS clientMock = beanFactory.getBean("amazonRds", AmazonRDS.class); - - when(clientMock.describeDBInstances( - new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) - .thenReturn(new DescribeDBInstancesResult().withDBInstances( - new DBInstance().withDBInstanceStatus("available") - .withDBName("test") - .withDBInstanceIdentifier("test") - .withEngine("mysql").withMasterUsername("admin") - .withEndpoint(new Endpoint() - .withAddress("localhost").withPort(3306)) - .withReadReplicaDBInstanceIdentifiers("read1"))); - - AmazonIdentityManagement amazonIdentityManagement = beanFactory - .getBean("myIdentityService", AmazonIdentityManagement.class); - - when(amazonIdentityManagement.getUser()).thenReturn( - new GetUserResult().withUser(new User("/", "aemruli", "123456789012", - "arn:aws:iam::1234567890:user/aemruli", new Date()))); - when(clientMock.listTagsForResource(new ListTagsForResourceRequest() - .withResourceName("arn:aws:rds:us-west-2:1234567890:db:test"))) - .thenReturn(new ListTagsForResourceResult().withTagList( - new Tag().withKey("key1").withValue("value2"))); - - // Act - Map dsTags = beanFactory.getBean("dsTags", Map.class); - DataSource dataSource = beanFactory.getBean(DataSource.class); - - // Assert - assertThat(dsTags.get("key1")).isEqualTo("value2"); - assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue(); - } - -} diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest.java deleted file mode 100644 index 4437d2cbd..000000000 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import java.util.List; - -import com.amazonaws.services.rds.AmazonRDS; -import com.amazonaws.services.rds.AmazonRDSClient; -import org.aopalliance.intercept.MethodInterceptor; -import org.junit.Test; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Agim Emruli - */ -public class AmazonRdsRetryInterceptorBeanDefinitionParserTest { - - @Test - public void parseInternal_minimalConfiguration_createsRetryInterceptor() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-minimal.xml", getClass()); - - // Act - MethodInterceptor interceptor = classPathXmlApplicationContext - .getBean(MethodInterceptor.class); - - // Assert - assertThat(interceptor).isNotNull(); - } - - @Test - public void parseInternal_customRegionConfigured_createsAmazonRdsClientWithCustomRegionConfigured() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRegion.xml", getClass()); - - // Act - AmazonRDS amazonRDS = classPathXmlApplicationContext.getBean(AmazonRDS.class); - - // Assert - assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()) - .isEqualTo("https://rds.eu-west-1.amazonaws.com"); - } - - @Test - public void parseInternal_customRegionProviderConfigured_createAmazonRdsClientWithCustomRegionConfigured() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRegionProvider.xml", getClass()); - - // Act - AmazonRDS amazonRDS = classPathXmlApplicationContext.getBean(AmazonRDS.class); - - // Assert - assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()) - .isEqualTo("https://rds.eu-west-1.amazonaws.com"); - } - - @Test - public void parseInternal_customRDsClientConfigured_createInterceptorWithCustomRdsClient() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRdsClient.xml", getClass()); - - // Act - classPathXmlApplicationContext.getBean(MethodInterceptor.class); - - // Assert - assertThat(classPathXmlApplicationContext - .containsBean(AmazonWebserviceClientConfigurationUtils - .getBeanName(AmazonRDSClient.class.getName()))).isFalse(); - } - - @Test - public void parseInternal_customBackOffPolicy_createInterceptorWithCustomBackOffPolicy() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customBackOffPolicy.xml", getClass()); - BeanDefinition beanDefinition = classPathXmlApplicationContext.getBeanFactory() - .getBeanDefinition("interceptor"); - - // Act - BeanDefinition retryOperations = (BeanDefinition) beanDefinition - .getPropertyValues().getPropertyValue("retryOperations").getValue(); - - // Assert - assertThat(((RuntimeBeanReference) retryOperations.getPropertyValues() - .getPropertyValue("backOffPolicy").getValue()).getBeanName()) - .isEqualTo("policy"); - } - - @Test - public void parseInternal_customNumberOfRetiresConfigured_createRetryPolicyWithCustomNumberOfRetriesConfigured() - throws Exception { - // Arrange - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-maxNumberOfRetries.xml", getClass()); - - // Act - BeanDefinition beanDefinition = classPathXmlApplicationContext.getBeanFactory() - .getBeanDefinition("interceptor"); - - // Assert - BeanDefinition retryOperations = (BeanDefinition) beanDefinition - .getPropertyValues().getPropertyValue("retryOperations").getValue(); - BeanDefinition compositeRetryPolicy = (BeanDefinition) retryOperations - .getPropertyValues().getPropertyValue("retryPolicy").getValue(); - @SuppressWarnings("unchecked") - List policies = (List) compositeRetryPolicy - .getPropertyValues().getPropertyValue("policies").getValue(); - BeanDefinition sqlPolicy = policies.get(1); - assertThat(sqlPolicy.getPropertyValues().getPropertyValue("maxNumberOfRetries") - .getValue().toString()).isEqualTo("4"); - } - -} diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.java deleted file mode 100644 index 8c7c76fb2..000000000 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; - -/** - * @author Alain Sahli - */ -public class JdbcSchemaWithoutVersionTest { - - @Test - public void jdbcXsd_withoutVersion_shouldNotThrowAnException() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act & Assert - reader.loadBeanDefinitions( - new ClassPathResource(getClass().getSimpleName() + ".xml", getClass())); - } - -} diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/SampleValidator.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/SampleValidator.java deleted file mode 100644 index c6e67a2fc..000000000 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/xml/SampleValidator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.jdbc.config.xml; - -import java.sql.Connection; - -import org.apache.tomcat.jdbc.pool.Validator; - -/** - * @author Agim Emruli - */ -public class SampleValidator implements Validator { - - @Override - public boolean validate(Connection connection, int i) { - return true; - } - -} diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRdsInstance.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRdsInstance.xml deleted file mode 100644 index 9cab26062..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRdsInstance.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegion.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegion.xml deleted file mode 100644 index 5c988088a..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegion.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProvider.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProvider.xml deleted file mode 100644 index 9fa196d72..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProvider.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProviderAndRegion.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProviderAndRegion.xml deleted file mode 100644 index 856b3fb3b..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-customRegionProviderAndRegion.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-defaultPoolAttributes.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-defaultPoolAttributes.xml deleted file mode 100644 index e10bb27a0..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-defaultPoolAttributes.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-fullConfiguration.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-fullConfiguration.xml deleted file mode 100644 index d73f87395..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-fullConfiguration.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 661c3d7d4..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-noCredentials.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-noCredentials.xml deleted file mode 100644 index 0e77f44de..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-noCredentials.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-poolAttributes.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-poolAttributes.xml deleted file mode 100644 index a2155c0a3..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-poolAttributes.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-readReplicaEnabled.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-readReplicaEnabled.xml deleted file mode 100644 index 96e06fb22..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-readReplicaEnabled.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-userTags.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-userTags.xml deleted file mode 100644 index d4333c06f..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsDataSourceBeanDefinitionParserTest-userTags.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customBackOffPolicy.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customBackOffPolicy.xml deleted file mode 100644 index 2abad0216..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customBackOffPolicy.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRdsClient.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRdsClient.xml deleted file mode 100644 index dda7f9d52..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRdsClient.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegion.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegion.xml deleted file mode 100644 index 3a7223378..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegion.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegionProvider.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegionProvider.xml deleted file mode 100644 index a32d1b91c..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-customRegionProvider.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-maxNumberOfRetries.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-maxNumberOfRetries.xml deleted file mode 100644 index 99dc8234f..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-maxNumberOfRetries.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 2e423540f..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/AmazonRdsRetryInterceptorBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.xml b/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.xml deleted file mode 100644 index 745666e8b..000000000 --- a/spring-cloud-aws-jdbc/src/test/resources/org/springframework/cloud/aws/jdbc/config/xml/JdbcSchemaWithoutVersionTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParser.java deleted file mode 100644 index 61d099ed3..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParser.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; -import org.springframework.cloud.aws.messaging.listener.QueueMessageHandler; -import org.springframework.cloud.aws.messaging.listener.SendToHandlerMethodReturnValueHandler; -import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; -import org.springframework.core.Conventions; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; - -import static org.springframework.cloud.aws.messaging.config.xml.BufferedSqsClientBeanDefinitionUtils.getCustomAmazonSqsClientOrDecoratedDefaultSqsClientBeanName; - -/** - * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} for the - * <annotation-driven-queue-listener/> element. - * - * @author Agim Emruli - * @author Alain Sahli - * @since 1.0 - */ -public class AnnotationDrivenQueueListenerBeanDefinitionParser - extends AbstractBeanDefinitionParser { - - private static final String TASK_EXECUTOR_ATTRIBUTE = "task-executor"; - - private static final String MAX_NUMBER_OF_MESSAGES_ATTRIBUTE = "max-number-of-messages"; - - private static final String VISIBILITY_TIMEOUT_ATTRIBUTE = "visibility-timeout"; - - private static final String WAIT_TIME_OUT_ATTRIBUTE = "wait-time-out"; - - private static final String AUTO_STARTUP_ATTRIBUTE = "auto-startup"; - - private static final String DESTINATION_RESOLVER_ATTRIBUTE = "destination-resolver"; - - private static final String BACK_OFF_TIME = "back-off-time"; - - private static String getMessageHandlerBeanName(Element element, - ParserContext parserContext, String sqsClientBeanName) { - BeanDefinitionBuilder queueMessageHandlerDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(QueueMessageHandler.class); - - if (parserContext.getRegistry().containsBeanDefinition("jacksonObjectMapper")) { - queueMessageHandlerDefinitionBuilder - .addConstructorArgReference("jacksonObjectMapper"); - } - else { - BeanDefinitionBuilder mapper = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.messaging.converter.MappingJackson2MessageConverter"); - mapper.addPropertyValue("serializedPayloadClass", "java.lang.String"); - mapper.addPropertyValue("strictContentTypeMatch", true); - queueMessageHandlerDefinitionBuilder - .addConstructorArgValue(mapper.getBeanDefinition()); - } - - ManagedList argumentResolvers = getArgumentResolvers(element, parserContext); - if (!argumentResolvers.isEmpty()) { - queueMessageHandlerDefinitionBuilder - .addPropertyValue("customArgumentResolvers", argumentResolvers); - } - - ManagedList returnValueHandlers = getReturnValueHandlers(element, - parserContext); - returnValueHandlers.add(createSendToHandlerMethodReturnValueHandlerBeanDefinition( - element, parserContext, sqsClientBeanName)); - queueMessageHandlerDefinitionBuilder.addPropertyValue("customReturnValueHandlers", - returnValueHandlers); - - String messageHandlerBeanName = parserContext.getReaderContext().generateBeanName( - queueMessageHandlerDefinitionBuilder.getBeanDefinition()); - parserContext.getRegistry().registerBeanDefinition(messageHandlerBeanName, - queueMessageHandlerDefinitionBuilder.getBeanDefinition()); - - return messageHandlerBeanName; - } - - private static AbstractBeanDefinition createSendToHandlerMethodReturnValueHandlerBeanDefinition( - Element element, ParserContext parserContext, String sqsClientBeanName) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(SendToHandlerMethodReturnValueHandler.class); - if (StringUtils.hasText(element.getAttribute("send-to-message-template"))) { - beanDefinitionBuilder.addConstructorArgReference( - element.getAttribute("send-to-message-template")); - } - else { - // TODO consider creating a utils for setting up the queue messaging template - // as it also created in QueueMessagingTemplateBeanDefinitionParser - BeanDefinitionBuilder templateBuilder = BeanDefinitionBuilder - .rootBeanDefinition(QueueMessagingTemplate.class); - templateBuilder.addConstructorArgReference(sqsClientBeanName); - templateBuilder.addConstructorArgReference(GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry())); - - beanDefinitionBuilder - .addConstructorArgValue(templateBuilder.getBeanDefinition()); - } - - return beanDefinitionBuilder.getBeanDefinition(); - } - - private static ManagedList getArgumentResolvers(Element element, - ParserContext parserContext) { - Element resolversElement = DomUtils.getChildElementByTagName(element, - "argument-resolvers"); - if (resolversElement != null) { - return extractBeanSubElements(resolversElement, parserContext); - } - else { - return new ManagedList<>(0); - } - } - - private static ManagedList getReturnValueHandlers(Element element, - ParserContext parserContext) { - Element handlersElement = DomUtils.getChildElementByTagName(element, - "return-value-handlers"); - if (handlersElement != null) { - return extractBeanSubElements(handlersElement, parserContext); - } - else { - return new ManagedList<>(0); - } - } - - private static ManagedList extractBeanSubElements( - Element parentElement, ParserContext parserContext) { - ManagedList list = new ManagedList<>(); - list.setSource(parserContext.extractSource(parentElement)); - for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, - "bean")) { - BeanDefinitionHolder beanDef = parserContext.getDelegate() - .parseBeanDefinitionElement(beanElement); - beanDef = parserContext.getDelegate() - .decorateBeanDefinitionIfRequired(beanElement, beanDef); - list.add(beanDef.getBeanDefinition()); - } - return list; - } - - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext parserContext) { - BeanDefinitionBuilder containerBuilder = BeanDefinitionBuilder - .genericBeanDefinition(SimpleMessageListenerContainer.class); - - if (StringUtils.hasText(element.getAttribute(TASK_EXECUTOR_ATTRIBUTE))) { - containerBuilder.addPropertyReference( - Conventions.attributeNameToPropertyName(TASK_EXECUTOR_ATTRIBUTE), - element.getAttribute(TASK_EXECUTOR_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(MAX_NUMBER_OF_MESSAGES_ATTRIBUTE))) { - containerBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName( - MAX_NUMBER_OF_MESSAGES_ATTRIBUTE), - element.getAttribute(MAX_NUMBER_OF_MESSAGES_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(VISIBILITY_TIMEOUT_ATTRIBUTE))) { - containerBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(VISIBILITY_TIMEOUT_ATTRIBUTE), - element.getAttribute(VISIBILITY_TIMEOUT_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(WAIT_TIME_OUT_ATTRIBUTE))) { - containerBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(WAIT_TIME_OUT_ATTRIBUTE), - element.getAttribute(WAIT_TIME_OUT_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(AUTO_STARTUP_ATTRIBUTE))) { - containerBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(AUTO_STARTUP_ATTRIBUTE), - element.getAttribute(AUTO_STARTUP_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE))) { - containerBuilder.addPropertyReference( - Conventions - .attributeNameToPropertyName(DESTINATION_RESOLVER_ATTRIBUTE), - element.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE)); - } - - if (StringUtils.hasText(element.getAttribute(BACK_OFF_TIME))) { - containerBuilder.addPropertyValue( - Conventions.attributeNameToPropertyName(BACK_OFF_TIME), - element.getAttribute(BACK_OFF_TIME)); - } - - String amazonSqsClientBeanName = getCustomAmazonSqsClientOrDecoratedDefaultSqsClientBeanName( - element, parserContext); - - containerBuilder.addPropertyReference( - Conventions.attributeNameToPropertyName("amazon-sqs"), - amazonSqsClientBeanName); - - containerBuilder.addPropertyReference("resourceIdResolver", - GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry())); - containerBuilder.addPropertyReference("messageHandler", getMessageHandlerBeanName( - element, parserContext, amazonSqsClientBeanName)); - - return containerBuilder.getBeanDefinition(); - } - - @Override - protected boolean shouldGenerateId() { - return true; - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/BufferedSqsClientBeanDefinitionUtils.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/BufferedSqsClientBeanDefinitionUtils.java deleted file mode 100644 index 23eaed00b..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/BufferedSqsClientBeanDefinitionUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils; -import org.springframework.util.StringUtils; - -/** - * @author Alain Sahli - * @author Agim Emruli - */ -public final class BufferedSqsClientBeanDefinitionUtils { - - /** - * SQS client class name. - */ - // @checkstyle:off - public static final String SQS_CLIENT_CLASS_NAME = "com.amazonaws.services.sqs.AmazonSQSAsyncClient"; - - // @checkstyle:on - - // @checkstyle:off - static final String BUFFERED_SQS_CLIENT_CLASS_NAME = "com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient"; - - // @checkstyle:on - - private BufferedSqsClientBeanDefinitionUtils() { - // Avoid instantiation - } - - static String getCustomAmazonSqsClientOrDecoratedDefaultSqsClientBeanName( - Element element, ParserContext parserContext) { - String amazonSqsClientBeanName = XmlWebserviceConfigurationUtils - .getCustomClientOrDefaultClientBeanName(element, parserContext, - "amazon-sqs", SQS_CLIENT_CLASS_NAME); - if (!StringUtils.hasText(element.getAttribute("amazon-sqs"))) { - BeanDefinition clientBeanDefinition = parserContext.getRegistry() - .getBeanDefinition(amazonSqsClientBeanName); - if (!clientBeanDefinition.getBeanClassName() - .equals(BUFFERED_SQS_CLIENT_CLASS_NAME)) { - BeanDefinitionBuilder bufferedClientBeanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(BUFFERED_SQS_CLIENT_CLASS_NAME); - bufferedClientBeanDefinitionBuilder - .addConstructorArgValue(clientBeanDefinition); - parserContext.getRegistry().removeBeanDefinition(amazonSqsClientBeanName); - parserContext.getRegistry().registerBeanDefinition( - amazonSqsClientBeanName, - bufferedClientBeanDefinitionBuilder.getBeanDefinition()); - } - } - return amazonSqsClientBeanName; - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/MessagingNamespaceHandler.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/MessagingNamespaceHandler.java deleted file mode 100644 index 2c60178ed..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/MessagingNamespaceHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; - -/** - * {@link org.springframework.beans.factory.xml.NamespaceHandler} for the Spring Cloud AWS - * messaging namespace. - * - * @author Agim Emruli - * @author Alain Sahli - * @since 1.0 - */ -@SuppressWarnings("UnusedDeclaration") -public class MessagingNamespaceHandler extends NamespaceHandlerSupport { - - @Override - public void init() { - registerBeanDefinitionParser("annotation-driven-queue-listener", - new AnnotationDrivenQueueListenerBeanDefinitionParser()); - registerBeanDefinitionParser("queue-messaging-template", - new QueueMessagingTemplateBeanDefinitionParser()); - registerBeanDefinitionParser("notification-messaging-template", - new NotificationMessagingTemplateBeanDefinitionParser()); - registerBeanDefinitionParser("notification-argument-resolver", - new NotificationArgumentResolverBeanDefinitionParser()); - registerBeanDefinitionParser("sqs-async-client", - new SqsAsyncClientBeanDefinitionParser()); - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java deleted file mode 100644 index dc372d2c3..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * @author Agim Emruli - */ -class NotificationArgumentResolverBeanDefinitionParser - extends AbstractSingleBeanDefinitionParser { - - @Override - protected String getBeanClassName(Element element) { - return "org.springframework.cloud.aws.messaging.endpoint.config.NotificationHandlerMethodArgumentResolverFactoryBean"; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - builder.addConstructorArgReference( - getCustomClientOrDefaultClientBeanName(element, parserContext, - "amazon-sns", "com.amazonaws.services.sns.AmazonSNSClient")); - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java deleted file mode 100644 index 7bd1a71d0..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.getCustomClientOrDefaultClientBeanName; - -/** - * @author Alain Sahli - */ -public class NotificationMessagingTemplateBeanDefinitionParser - extends AbstractSingleBeanDefinitionParser { - - private static final String DEFAULT_DESTINATION_ATTRIBUTE = "default-destination"; - - private static final String SNS_CLIENT_CLASS_NAME = "com.amazonaws.services.sns.AmazonSNSClient"; - - @Override - protected Class getBeanClass(Element element) { - return NotificationMessagingTemplate.class; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - if (StringUtils.hasText(element.getAttribute(DEFAULT_DESTINATION_ATTRIBUTE))) { - builder.addPropertyValue("defaultDestinationName", - element.getAttribute(DEFAULT_DESTINATION_ATTRIBUTE)); - } - - builder.addConstructorArgReference(getCustomClientOrDefaultClientBeanName(element, - parserContext, "amazon-sns", SNS_CLIENT_CLASS_NAME)); - builder.addConstructorArgReference(GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry())); - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParser.java deleted file mode 100644 index c171a522e..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParser.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.messaging.config.xml.BufferedSqsClientBeanDefinitionUtils.getCustomAmazonSqsClientOrDecoratedDefaultSqsClientBeanName; - -/** - * @author Alain Sahli - */ -public class QueueMessagingTemplateBeanDefinitionParser - extends AbstractSingleBeanDefinitionParser { - - private static final String DEFAULT_DESTINATION_ATTRIBUTE = "default-destination"; - - private static final String MESSAGE_CONVERTER_ATTRIBUTE = "message-converter"; - - @Override - protected Class getBeanClass(Element element) { - return QueueMessagingTemplate.class; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, - BeanDefinitionBuilder builder) { - String amazonSqsClientBeanName = getCustomAmazonSqsClientOrDecoratedDefaultSqsClientBeanName( - element, parserContext); - - if (StringUtils.hasText(element.getAttribute(DEFAULT_DESTINATION_ATTRIBUTE))) { - builder.addPropertyValue("defaultDestinationName", - element.getAttribute(DEFAULT_DESTINATION_ATTRIBUTE)); - } - - builder.addConstructorArgReference(amazonSqsClientBeanName); - builder.addConstructorArgReference(GlobalBeanDefinitionUtils - .retrieveResourceIdResolverBeanName(parserContext.getRegistry())); - - if (StringUtils.hasText(element.getAttribute(MESSAGE_CONVERTER_ATTRIBUTE))) { - builder.addConstructorArgReference( - element.getAttribute(MESSAGE_CONVERTER_ATTRIBUTE)); - } - } - -} diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParser.java deleted file mode 100644 index 93df46ac2..000000000 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParser.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.cloud.aws.core.task.ShutdownSuppressingExecutorServiceAdapter; -import org.springframework.util.StringUtils; - -import static org.springframework.cloud.aws.core.config.xml.XmlWebserviceConfigurationUtils.parseCustomClientElement; - -/** - * @author Alain Sahli - * @author Agim Emruli - */ -public class SqsAsyncClientBeanDefinitionParser extends AbstractBeanDefinitionParser { - - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext parserContext) { - AbstractBeanDefinition sqsAsyncClientDefinition = parseCustomClientElement( - element, parserContext, - BufferedSqsClientBeanDefinitionUtils.SQS_CLIENT_CLASS_NAME); - if (StringUtils.hasText(element.getAttribute("task-executor"))) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - ShutdownSuppressingExecutorServiceAdapter.class); - builder.addConstructorArgReference(element.getAttribute("task-executor")); - sqsAsyncClientDefinition.getPropertyValues().addPropertyValue("executor", - builder.getBeanDefinition()); - } - if (Boolean.parseBoolean(element.getAttribute("buffered"))) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - BufferedSqsClientBeanDefinitionUtils.BUFFERED_SQS_CLIENT_CLASS_NAME); - builder.addConstructorArgValue(sqsAsyncClientDefinition); - return builder.getBeanDefinition(); - } - else { - return sqsAsyncClientDefinition; - } - } - -} diff --git a/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.handlers b/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.handlers deleted file mode 100644 index 4067ddd83..000000000 --- a/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.handlers +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/messaging=org.springframework.cloud.aws.messaging.config.xml.MessagingNamespaceHandler diff --git a/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.schemas b/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.schemas deleted file mode 100644 index cccdfed57..000000000 --- a/spring-cloud-aws-messaging/src/main/resources/META-INF/spring.schemas +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2013-2019 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -http\://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging-1.0.xsd=org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.0.xsd -http\://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging-1.2.xsd=org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd -http\://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging.xsd=org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd diff --git a/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.0.xsd b/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.0.xsd deleted file mode 100644 index 76ff7199e..000000000 --- a/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.0.xsd +++ /dev/null @@ -1,346 +0,0 @@ - - - - - - - - - - - - - Scans the classes annotated with - org.springframework.cloud.aws.messaging.config.annotation.QueueListener - and - registers them as endpoints for receiving messages from SQS. - - - - - - - - Configures HandlerMethodArgumentResolver types to support - custom queue messaging method argument types. - Using this option does not override the built-in support for - resolving handler method arguments. - - - - - - - - The HandlerMethodArgumentResolver bean definition. - - - - - - - - - - - Configures HandlerMethodReturnValueHandler types to support - custom queue messaging method return value handling. - Using this option does not override the built-in support for - handling return values. - - - - - - - - The HandlerMethodReturnValueHandler bean - definition. - - - - - - - - - - - - - - - - - - Configures the TaskExecutor which is used to poll messages and - execute them - by calling the handler methods. If no TaskExecutor is set, a - default one is created. - - - - - - - - - - - - Sets the AmazonSQSAsync that is going to be used by the container - to interact with the messaging - (SQS) API. - - - - - - - Configure the maximum number of messages that should be retrieved - during one poll to the Amazon SQS system. This - number must be a positive, non-zero number that has a maximum - number of 10. Values higher then 10 are currently - not supported by the queueing system. - - - - - - - Configures the duration (in seconds) that the received messages - are hidden from - subsequent poll requests after being retrieved from the system. - - - - - - documentation. - ]]> - - - - - - Configures if this container should be automatically started. The - default value is true. - - - - - - - A reference to a bean that implements the - org.springframework.messaging.core.MessageSendingOperations - interface. - This message template will be used to send return values of - methods annotated with @SendTo. - - - - - - - - - - - - A reference to a bean that implements the - org.springframework.messaging.core.DestinationResolver interface. - - - - - - - - - - - - Defines if a message must be deleted or not if the handler method - throws an exception and the exception handler - method is called. By default this value is set to true which means - that the message is deleted to avoid - poison messages. If this value is set to false it is the - responsibility of the exception handler method to delete - the message. The exception handler method can inject the message - headers with - org.springframework.messaging.handler.annotation.Headers - in order to get the receipt handle. - - - - - - - The number of milliseconds the polling thread must wait before - trying to recover when an error occurs - (e.g. connection timeout). Default value is 10000 milliseconds. - - - - - - - - - - Configures a - org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Configures a - org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate - - - - - - - - - - - - - - - - - - - - - - - - - Configures a HandlerMethodArgumentResolver to be used in Spring MVC to - support Notification endpoints in - Spring MVC. The configured bean must be registered as an custom argument - resolver in Spring MVC - - - - - - - - - - - - - - - - - - - - - - - - - - - - Configures an SQS client instance, with the configuration - parameter specified. - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd b/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd deleted file mode 100644 index 921c99c4d..000000000 --- a/spring-cloud-aws-messaging/src/main/resources/org/springframework/cloud/aws/messaging/config/xml/spring-cloud-aws-messaging-1.2.xsd +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - - - - - - - Scans the classes annotated with - org.springframework.cloud.aws.messaging.config.annotation.QueueListener - and - registers them as endpoints for receiving messages from SQS. - - - - - - - - Configures HandlerMethodArgumentResolver types to support - custom queue messaging method argument types. - Using this option does not override the built-in support for - resolving handler method arguments. - - - - - - - - The HandlerMethodArgumentResolver bean definition. - - - - - - - - - - - Configures HandlerMethodReturnValueHandler types to support - custom queue messaging method return value handling. - Using this option does not override the built-in support for - handling return values. - - - - - - - - The HandlerMethodReturnValueHandler bean - definition. - - - - - - - - - - - - - - - - - - Configures the TaskExecutor which is used to poll messages and - execute them - by calling the handler methods. If no TaskExecutor is set, a - default one is created. - - - - - - - - - - - - Sets the AmazonSQSAsync that is going to be used by the container - to interact with the messaging - (SQS) API. - - - - - - - Configure the maximum number of messages that should be retrieved - during one poll to the Amazon SQS system. This - number must be a positive, non-zero number that has a maximum - number of 10. Values higher then 10 are currently - not supported by the queueing system. - - - - - - - Configures the duration (in seconds) that the received messages - are hidden from - subsequent poll requests after being retrieved from the system. - - - - - - documentation. - ]]> - - - - - - Configures if this container should be automatically started. The - default value is true. - - - - - - - A reference to a bean that implements the - org.springframework.messaging.core.MessageSendingOperations - interface. - This message template will be used to send return values of - methods annotated with @SendTo. - - - - - - - - - - - - A reference to a bean that implements the - org.springframework.messaging.core.DestinationResolver interface. - - - - - - - - - - - - The number of milliseconds the polling thread must wait before - trying to recover when an error occurs - (e.g. connection timeout). Default value is 10000 milliseconds. - - - - - - - The number of milliseconds to wait before interupting the polling - thread when a queue is stopped. - Default value is 10000 milliseconds. - - - - - - - - - - Configures a - org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Configures a - org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate - - - - - - - - - - - - - - - - - - - - - - - - - Configures a HandlerMethodArgumentResolver to be used in Spring MVC to - support Notification endpoints in - Spring MVC. The configured bean must be registered as an custom argument - resolver in Spring MVC - - - - - - - - - - - - - - - - - - - - - - - - - - - - Configures an SQS client instance, with the configuration - parameter specified. - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest.java deleted file mode 100644 index 8ec2a35a8..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest.java +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import java.util.List; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.sqs.AmazonSQSAsync; -import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.core.env.StackResourceRegistryDetectingResourceIdResolver; -import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; -import org.springframework.cloud.aws.messaging.listener.QueueMessageHandler; -import org.springframework.cloud.aws.messaging.listener.SendToHandlerMethodReturnValueHandler; -import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.context.support.GenericXmlApplicationContext; -import org.springframework.core.MethodParameter; -import org.springframework.core.io.ClassPathResource; -import org.springframework.messaging.Message; -import org.springframework.messaging.converter.CompositeMessageConverter; -import org.springframework.messaging.converter.MappingJackson2MessageConverter; -import org.springframework.messaging.converter.MessageConverter; -import org.springframework.messaging.converter.StringMessageConverter; -import org.springframework.messaging.core.DestinationResolver; -import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; -import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Agim Emruli - * @author Alain Sahli - * @since 1.0 - */ -public class AnnotationDrivenQueueListenerBeanDefinitionParserTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - - @Test - public void parseInternal_minimalConfiguration_shouldProduceContainerWithDefaultAmazonSqsBean() - throws Exception { - // Act - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-minimal.xml", getClass()); - - // Assert - AmazonSQSAsync amazonSqsClient = applicationContext.getBean(AmazonSQSAsync.class); - assertThat(amazonSqsClient).isNotNull(); - - SimpleMessageListenerContainer container = applicationContext - .getBean(SimpleMessageListenerContainer.class); - assertThat(container).isNotNull(); - - assertThat(ReflectionTestUtils.getField(container, "amazonSqs")) - .isSameAs(amazonSqsClient); - assertThat(ReflectionTestUtils.getField(container, "resourceIdResolver")) - .isSameAs(applicationContext - .getBean(StackResourceRegistryDetectingResourceIdResolver.class)); - - QueueMessageHandler queueMessageHandler = (QueueMessageHandler) ReflectionTestUtils - .getField(container, "messageHandler"); - HandlerMethodReturnValueHandler sendToReturnValueHandler = queueMessageHandler - .getReturnValueHandlers().get(0); - assertThat(SendToHandlerMethodReturnValueHandler.class - .isInstance(sendToReturnValueHandler)).isTrue(); - QueueMessagingTemplate queueMessagingTemplate = (QueueMessagingTemplate) ReflectionTestUtils - .getField(sendToReturnValueHandler, "messageTemplate"); - - assertThat(CompositeMessageConverter.class - .isInstance(queueMessagingTemplate.getMessageConverter())).isTrue(); - - @SuppressWarnings("unchecked") - List messageConverters = (List) ReflectionTestUtils - .getField(queueMessagingTemplate.getMessageConverter(), "converters"); - assertThat(messageConverters.size()).isEqualTo(2); - assertThat(StringMessageConverter.class.isInstance(messageConverters.get(0))) - .isTrue(); - assertThat(MappingJackson2MessageConverter.class - .isInstance(messageConverters.get(1))).isTrue(); - - StringMessageConverter stringMessageConverter = (StringMessageConverter) messageConverters - .get(0); - assertThat(stringMessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(stringMessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - - MappingJackson2MessageConverter jackson2MessageConverter = (MappingJackson2MessageConverter) messageConverters - .get(1); - assertThat(jackson2MessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(jackson2MessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - } - - @Test - public void parseInternal_customSqsClient_shouldProduceContainerWithCustomSqsClientUsed() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-amazon-sqs.xml", getClass())); - - // Assert - BeanDefinition sqsAsync = registry.getBeanDefinition("myClient"); - assertThat(sqsAsync).isNotNull(); - - BeanDefinition abstractContainerDefinition = registry - .getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0"); - assertThat(abstractContainerDefinition).isNotNull(); - - assertThat(abstractContainerDefinition.getPropertyValues().size()).isEqualTo(3); - assertThat(((RuntimeBeanReference) abstractContainerDefinition.getPropertyValues() - .getPropertyValue("amazonSqs").getValue()).getBeanName()) - .isEqualTo("myClient"); - } - - @Test - public void parseInternal_customTaskExecutor_shouldCreateContainerAndClientWithCustomTaskExecutor() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-task-executor.xml", getClass())); - - // Assert - BeanDefinition executor = beanFactory.getBeanDefinition("executor"); - assertThat(executor).isNotNull(); - - BeanDefinition abstractContainerDefinition = beanFactory - .getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0"); - assertThat(abstractContainerDefinition).isNotNull(); - - assertThat(abstractContainerDefinition.getPropertyValues().size()).isEqualTo(4); - assertThat(((RuntimeBeanReference) abstractContainerDefinition.getPropertyValues() - .getPropertyValue("taskExecutor").getValue()).getBeanName()) - .isEqualTo("executor"); - - AmazonSQSBufferedAsyncClient bufferedAsyncClient = beanFactory - .getBean(AmazonSQSBufferedAsyncClient.class); - assertThat(bufferedAsyncClient).isNotNull(); - } - - @Test - public void parseInternal_withSendToMessageTemplateAttribute_mustBeSetOnTheBeanDefinition() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-with-send-to-message-template.xml", - getClass())); - - // Assert - BeanDefinition queueMessageHandler = registry - .getBeanDefinition(QueueMessageHandler.class.getName() + "#0"); - assertThat(queueMessageHandler).isNotNull(); - - assertThat(queueMessageHandler.getPropertyValues().size()).isEqualTo(1); - ManagedList returnValueHandlers = (ManagedList) queueMessageHandler - .getPropertyValues().getPropertyValue("customReturnValueHandlers") - .getValue(); - assertThat(returnValueHandlers.size()).isEqualTo(1); - RootBeanDefinition sendToReturnValueHandler = (RootBeanDefinition) returnValueHandlers - .get(0); - - assertThat(((RuntimeBeanReference) sendToReturnValueHandler - .getConstructorArgumentValues() - .getArgumentValue(0, RuntimeBeanReference.class).getValue()) - .getBeanName()).isEqualTo("messageTemplate"); - } - - @Test - public void parseInternal_withCustomProperties_customPropertiesConfiguredOnContainer() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-properties.xml", getClass())); - - // Assert - BeanDefinition abstractContainerDefinition = registry - .getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0"); - assertThat(abstractContainerDefinition).isNotNull(); - - assertThat(abstractContainerDefinition.getPropertyValues() - .getPropertyValue("autoStartup").getValue()).isEqualTo("false"); - assertThat(abstractContainerDefinition.getPropertyValues() - .getPropertyValue("maxNumberOfMessages").getValue()).isEqualTo("9"); - assertThat(abstractContainerDefinition.getPropertyValues() - .getPropertyValue("visibilityTimeout").getValue()).isEqualTo("6"); - assertThat(abstractContainerDefinition.getPropertyValues() - .getPropertyValue("waitTimeOut").getValue()).isEqualTo("3"); - } - - @Test - public void parseInternal_customArgumentResolvers_parsedAndConfiguredInQueueMessageHandler() - throws Exception { - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-argument-resolvers.xml", - getClass())); - - // Act - applicationContext.refresh(); - - // Assert - assertThat(applicationContext.getBean(QueueMessageHandler.class)).isNotNull(); - assertThat(applicationContext.getBean(QueueMessageHandler.class) - .getCustomArgumentResolvers().size()).isEqualTo(1); - assertThat(TestHandlerMethodArgumentResolver.class.isInstance(applicationContext - .getBean(QueueMessageHandler.class).getCustomArgumentResolvers().get(0))) - .isTrue(); - } - - @Test - public void parseInternal_customReturnValueHandlers_parsedAndConfiguredInQueueMessageHandler() - throws Exception { - // Arrange - GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-return-value-handlers.xml", - getClass())); - - // Act - applicationContext.refresh(); - - // Assert - assertThat(applicationContext.getBean(QueueMessageHandler.class)).isNotNull(); - assertThat(applicationContext.getBean(QueueMessageHandler.class) - .getCustomReturnValueHandlers().size()).isEqualTo(2); - assertThat(TestHandlerMethodReturnValueHandler.class - .isInstance(applicationContext.getBean(QueueMessageHandler.class) - .getCustomReturnValueHandlers().get(0))).isTrue(); - } - - @Test - public void parseInternal_customerRegionConfigured_regionConfiguredAndParsedForInternalCreatedSqsClient() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSQSBufferedAsyncClient = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils - .getField(amazonSQSBufferedAsyncClient, "realSQS"); - - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.EU_WEST_1) - .getServiceEndpoint("sqs")); - } - - // @checkstyle:off - @Test - public void parseInternal_customerRegionProviderConfigured_regionProviderConfiguredAndParsedForInternalCreatedSqsClient() - throws Exception { - // @checkstyle:on - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region-provider.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSQSBufferedAsyncClient = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils - .getField(amazonSQSBufferedAsyncClient, "realSQS"); - - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.AP_SOUTHEAST_2) - .getServiceEndpoint("sqs")); - } - - @Test - public void contextRegion_clientWithoutRegion_shouldHaveTheRegionGloballyDefined() - throws Exception { - // Arrange & Act - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-context-region.xml", getClass()); - - // Assert - AmazonSQSBufferedAsyncClient amazonSQSBufferedAsyncClient = applicationContext - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils - .getField(amazonSQSBufferedAsyncClient, "realSQS"); - - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.AP_SOUTHEAST_1) - .getServiceEndpoint("sqs")); - } - - @Test - public void parseInternal_customDestinationResolver_isUsedOnTheContainer() - throws Exception { - // Arrange & Act - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-custom-destination-resolver.xml", - getClass()); - - // Assert - SimpleMessageListenerContainer container = applicationContext - .getBean(SimpleMessageListenerContainer.class); - DestinationResolver customDestinationResolver = applicationContext - .getBean(DestinationResolver.class); - assertThat(customDestinationResolver == ReflectionTestUtils.getField(container, - "destinationResolver")).isTrue(); - } - - @Test - public void parseInternal_definedBackOffTime_shouldBeSetOnContainer() - throws Exception { - // Arrange & Act - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-back-off-time.xml", getClass()); - - // Assert - SimpleMessageListenerContainer container = applicationContext - .getBean(SimpleMessageListenerContainer.class); - assertThat(container.getBackOffTime()).isEqualTo(5000L); - } - - private static class TestHandlerMethodArgumentResolver - implements HandlerMethodArgumentResolver { - - @Override - public boolean supportsParameter(MethodParameter parameter) { - return false; - } - - @Override - public Object resolveArgument(MethodParameter parameter, Message message) - throws Exception { - return null; - } - - } - - private static class TestHandlerMethodReturnValueHandler - implements HandlerMethodReturnValueHandler { - - @Override - public boolean supportsReturnType(MethodParameter returnType) { - return false; - } - - @Override - public void handleReturnValue(Object returnValue, MethodParameter returnType, - Message message) throws Exception { - - } - - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.java deleted file mode 100644 index 2ed2e826f..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; - -/** - * @author Alain Sahli - */ -public class MessagingSchemaWithoutSchemaTest { - - @Test - public void messagingXsd_withoutVersion_shouldNotThrowAnException() throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act & Assert - reader.loadBeanDefinitions( - new ClassPathResource(getClass().getSimpleName() + ".xml", getClass())); - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java deleted file mode 100644 index a76fcd2a9..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import java.net.URI; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.sns.AmazonSNSClient; -import org.junit.Test; - -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.getBeanName; - -public class NotificationArgumentResolverBeanDefinitionParserTest { - - // @checkstyle:off - @Test - public void parseInternal_minimalConfiguration_configuresHandlerMethodArgumentResolverWithAmazonSnsImplicitlyConfigured() - throws Exception { - // @checkstyle:on - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-minimal.xml", getClass()); - - // Act - HandlerMethodArgumentResolver argumentResolver = context - .getBean(HandlerMethodArgumentResolver.class); - - // Assert - assertThat(argumentResolver).isNotNull(); - assertThat(context.containsBean(getBeanName(AmazonSNSClient.class.getName()))) - .isTrue(); - } - - // @checkstyle:off - @Test - public void parseInternal_customRegion_configuresHandlerMethodArgumentResolverWithAmazonSnsImplicitlyConfiguredAndCustomRegionSet() - throws Exception { - // @checkstyle:on - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRegion.xml", getClass()); - - // Act - AmazonSNSClient snsClient = context.getBean(AmazonSNSClient.class); - - // Assert - assertThat(ReflectionTestUtils.getField(snsClient, "endpoint")).isEqualTo(new URI( - "https", Region.getRegion(Regions.EU_WEST_1).getServiceEndpoint("sns"), - null, null)); - } - - // @checkstyle:off - @Test - public void parseInternal_customRegionProvider_configuresHandlerMethodArgumentResolverWithAmazonSnsImplicitlyConfiguredAndCustomRegionSet() - throws Exception { - // @checkstyle:on - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customRegionProvider.xml", getClass()); - - // Act - AmazonSNSClient snsClient = context.getBean(AmazonSNSClient.class); - - // Assert - assertThat(ReflectionTestUtils.getField(snsClient, "endpoint")).isEqualTo(new URI( - "https", Region.getRegion(Regions.US_WEST_2).getServiceEndpoint("sns"), - null, null)); - } - - @Test - public void parseInternal_customSnsClient_configuresHandlerMethodArgumentResolverWithCustomSnsClient() - throws Exception { - // Arrange - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - getClass().getSimpleName() + "-customSnsClient.xml", getClass()); - - // Act - AmazonSNSClient snsClient = context.getBean("customSnsClient", - AmazonSNSClient.class); - - // Assert - assertThat(snsClient).isNotNull(); - assertThat(context.containsBean(getBeanName(AmazonSNSClient.class.getName()))) - .isFalse(); - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java deleted file mode 100644 index 2568aa8a7..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import java.util.List; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.sns.AmazonSNSClient; -import org.junit.Test; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate; -import org.springframework.core.io.ClassPathResource; -import org.springframework.messaging.converter.CompositeMessageConverter; -import org.springframework.messaging.converter.MappingJackson2MessageConverter; -import org.springframework.messaging.converter.MessageConverter; -import org.springframework.messaging.converter.StringMessageConverter; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Alain Sahli - */ -public class NotificationMessagingTemplateBeanDefinitionParserTest { - - @Test - public void parseInternal_withMinimalConfig_shouldCreateDefaultTemplate() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-minimal.xml", getClass())); - - // Assert - NotificationMessagingTemplate notificationMessagingTemplate = registry - .getBean(NotificationMessagingTemplate.class); - assertThat( - ReflectionTestUtils.getField(notificationMessagingTemplate, "amazonSns")) - .isSameAs(registry.getBean(AmazonSNSClient.class)); - - Object cachingDestinationResolverProxy = ReflectionTestUtils - .getField(notificationMessagingTemplate, "destinationResolver"); - Object targetDestinationResolver = ReflectionTestUtils - .getField(cachingDestinationResolverProxy, "targetDestinationResolver"); - assertThat(ReflectionTestUtils.getField(targetDestinationResolver, - "resourceIdResolver")).isEqualTo(registry.getBean( - GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME)); - - assertThat(CompositeMessageConverter.class - .isInstance(notificationMessagingTemplate.getMessageConverter())) - .isTrue(); - @SuppressWarnings("unchecked") - List messageConverters = (List) ReflectionTestUtils - .getField(notificationMessagingTemplate.getMessageConverter(), - "converters"); - assertThat(messageConverters.size()).isEqualTo(2); - assertThat(StringMessageConverter.class.isInstance(messageConverters.get(0))) - .isTrue(); - assertThat(MappingJackson2MessageConverter.class - .isInstance(messageConverters.get(1))).isTrue(); - - StringMessageConverter stringMessageConverter = (StringMessageConverter) messageConverters - .get(0); - assertThat(stringMessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(stringMessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - - MappingJackson2MessageConverter jackson2MessageConverter = (MappingJackson2MessageConverter) messageConverters - .get(1); - assertThat(jackson2MessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(jackson2MessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - } - - @Test - public void parseInternal_withCustomAmazonSnsClient_shouldPassItAsConstructorArg() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-amazon-sns.xml", getClass())); - - // Assert - BeanDefinition notificationMessagingTemplateBeanDefinition = registry - .getBeanDefinition("notificationMessagingTemplate"); - assertThat(((RuntimeBeanReference) notificationMessagingTemplateBeanDefinition - .getConstructorArgumentValues() - .getArgumentValue(0, RuntimeBeanReference.class).getValue()) - .getBeanName()).isEqualTo("mySnsClient"); - } - - @Test - public void parseInternal_withDefaultDestination_mustBeSetOnTemplate() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-with-default-destination.xml", - getClass())); - - // Assert - BeanDefinition notificationMessagingTemplateBeanDefinition = registry - .getBeanDefinition("notificationMessagingTemplate"); - assertThat(notificationMessagingTemplateBeanDefinition.getPropertyValues() - .getPropertyValue("defaultDestinationName").getValue()) - .isEqualTo("myDefaultDestination"); - } - - @Test - public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCustomRegion() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region.xml", getClass())); - - // Assert - AmazonSNSClient amazonSns = registry.getBean(AmazonSNSClient.class); - assertThat(ReflectionTestUtils.getField(amazonSns, "endpoint").toString()) - .isEqualTo("https://" - + Region.getRegion(Regions.EU_WEST_1).getServiceEndpoint("sns")); - } - - @Test - public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientWithCustomRegionReturnedByProvider() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region-provider.xml", getClass())); - - // Assert - AmazonSNSClient amazonSns = registry.getBean(AmazonSNSClient.class); - assertThat(ReflectionTestUtils.getField(amazonSns, "endpoint").toString()) - .isEqualTo("https://" - + Region.getRegion(Regions.CN_NORTH_1).getServiceEndpoint("sns")); - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java deleted file mode 100644 index 719cfb41b..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import java.util.List; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.sqs.AmazonSQSAsync; -import com.amazonaws.services.sqs.AmazonSQSAsyncClient; -import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; -import org.junit.Test; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.context.config.xml.GlobalBeanDefinitionUtils; -import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; -import org.springframework.cloud.aws.messaging.support.converter.ObjectMessageConverter; -import org.springframework.core.io.ClassPathResource; -import org.springframework.messaging.converter.CompositeMessageConverter; -import org.springframework.messaging.converter.MappingJackson2MessageConverter; -import org.springframework.messaging.converter.MessageConverter; -import org.springframework.messaging.converter.StringMessageConverter; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Alain Sahli - */ -public class QueueMessagingTemplateBeanDefinitionParserTest { - - @Test - public void parseInternal_withMinimalConfig_shouldProduceAQueueMessagingTemplateWithDefaults() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-minimal.xml", getClass())); - - // Assert - QueueMessagingTemplate queueMessagingTemplate = registry - .getBean(QueueMessagingTemplate.class); - assertThat(ReflectionTestUtils.getField(queueMessagingTemplate, "amazonSqs")) - .isSameAs(registry.getBean(AmazonSQSAsync.class)); - Object cachingDestinationResolverProxy = ReflectionTestUtils - .getField(queueMessagingTemplate, "destinationResolver"); - Object targetDestinationResolver = ReflectionTestUtils - .getField(cachingDestinationResolverProxy, "targetDestinationResolver"); - assertThat(ReflectionTestUtils.getField(targetDestinationResolver, - "resourceIdResolver")).isEqualTo(registry.getBean( - GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME)); - assertThat(CompositeMessageConverter.class - .isInstance(queueMessagingTemplate.getMessageConverter())).isTrue(); - - assertThat(CompositeMessageConverter.class - .isInstance(queueMessagingTemplate.getMessageConverter())).isTrue(); - @SuppressWarnings("unchecked") - List messageConverters = (List) ReflectionTestUtils - .getField(queueMessagingTemplate.getMessageConverter(), "converters"); - assertThat(messageConverters.size()).isEqualTo(2); - assertThat(StringMessageConverter.class.isInstance(messageConverters.get(0))) - .isTrue(); - assertThat(MappingJackson2MessageConverter.class - .isInstance(messageConverters.get(1))).isTrue(); - - StringMessageConverter stringMessageConverter = (StringMessageConverter) messageConverters - .get(0); - assertThat(stringMessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(stringMessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - - MappingJackson2MessageConverter jackson2MessageConverter = (MappingJackson2MessageConverter) messageConverters - .get(1); - assertThat(jackson2MessageConverter.getSerializedPayloadClass()) - .isSameAs(String.class); - assertThat(ReflectionTestUtils.getField(jackson2MessageConverter, - "strictContentTypeMatch")).isEqualTo(false); - } - - @Test - public void parseInternal_withCustomAmazonSqsClient_shouldPassItAsConstructorArg() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-amazon-sqs.xml", getClass())); - - // Assert - BeanDefinition queueMessagingTemplateBeanDefinition = registry - .getBeanDefinition("queueMessagingTemplate"); - assertThat(((RuntimeBeanReference) queueMessagingTemplateBeanDefinition - .getConstructorArgumentValues() - .getArgumentValue(0, RuntimeBeanReference.class).getValue()) - .getBeanName()).isEqualTo("myClient"); - } - - @Test - public void parseInternal_withCustomConverter_mustBeSetOnTemplate() throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-converter.xml", getClass())); - - // Assert - QueueMessagingTemplate queueMessagingTemplateBeanDefinition = registry - .getBean(QueueMessagingTemplate.class); - MessageConverter messageConverter = queueMessagingTemplateBeanDefinition - .getMessageConverter(); - assertThat(CompositeMessageConverter.class.isInstance(messageConverter)).isTrue(); - CompositeMessageConverter compositeMessageConverter = (CompositeMessageConverter) messageConverter; - assertThat(compositeMessageConverter.getConverters().size()).isEqualTo(2); - assertThat(ObjectMessageConverter.class - .isInstance(compositeMessageConverter.getConverters().get(1))).isTrue(); - } - - @Test - public void parseInternal_withDefaultDestination_mustBeSetOnTemplate() - throws Exception { - // Arrange - SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-with-default-destination.xml", - getClass())); - - // Assert - BeanDefinition queueMessagingTemplateBeanDefinition = registry - .getBeanDefinition("queueMessagingTemplate"); - assertThat(queueMessagingTemplateBeanDefinition.getPropertyValues() - .getPropertyValue("defaultDestinationName").getValue()) - .isEqualTo("myDefaultDestination"); - } - - @Test - public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCustomRegion() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSqs = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils.getField(amazonSqs, "realSQS"); - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.SA_EAST_1) - .getServiceEndpoint("sqs")); - } - - @Test - public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientWithCustomRegionReturnedByProvider() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region-provider.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSqs = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils.getField(amazonSqs, "realSQS"); - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.AP_SOUTHEAST_2) - .getServiceEndpoint("sqs")); - } - - @Test - public void parseInternal_withMultipleMessagingTemplatesDefined_shouldConfigureOnlyOneSqsClientAndDecorateOnlyOnce() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-multiple-templates.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSqs = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - assertThat(ReflectionTestUtils.getField(amazonSqs, - "realSQS") instanceof AmazonSQSAsyncClient).isTrue(); - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java deleted file mode 100644 index 68d650020..000000000 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.aws.messaging.config.xml; - -import java.util.concurrent.ThreadPoolExecutor; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.sqs.AmazonSQSAsyncClient; -import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; -import org.junit.Test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.cloud.aws.core.task.ShutdownSuppressingExecutorServiceAdapter; -import org.springframework.core.io.ClassPathResource; -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SqsAsyncClientBeanDefinitionParserTest { - - @Test - public void parseInternal_minimalConfiguration_createsBufferedClientWithoutExplicitTaskExecutor() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-minimal.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient sqsBufferedAsyncClient = beanFactory - .getBean("customClient", AmazonSQSBufferedAsyncClient.class); - AmazonSQSAsyncClient asyncClient = (AmazonSQSAsyncClient) ReflectionTestUtils - .getField(sqsBufferedAsyncClient, "realSQS"); - assertThat(asyncClient).isNotNull(); - ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) ReflectionTestUtils - .getField(asyncClient, "executorService"); - assertThat(threadPoolExecutor.getCorePoolSize()).isEqualTo(50); - } - - @Test - public void parseInternal_notBuffered_createsAsyncClientWithoutBufferedDecorator() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-not-buffered.xml", getClass())); - - // Assert - AmazonSQSAsyncClient asyncClient = beanFactory.getBean("customClient", - AmazonSQSAsyncClient.class); - assertThat(asyncClient).isNotNull(); - assertThat(AmazonSQSAsyncClient.class.isInstance(asyncClient)).isTrue(); - } - - @Test - public void parseInternal_withCustomTasExecutor_createsBufferedClientWithCustomTaskExecutor() - throws Exception { - // Arrange - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-task-executor.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient sqsBufferedAsyncClient = beanFactory - .getBean("customClient", AmazonSQSBufferedAsyncClient.class); - AmazonSQSAsyncClient asyncClient = (AmazonSQSAsyncClient) ReflectionTestUtils - .getField(sqsBufferedAsyncClient, "realSQS"); - assertThat(asyncClient).isNotNull(); - ShutdownSuppressingExecutorServiceAdapter executor = (ShutdownSuppressingExecutorServiceAdapter) ReflectionTestUtils - .getField(asyncClient, "executorService"); - assertThat(ReflectionTestUtils.getField(executor, "taskExecutor")) - .isSameAs(beanFactory.getBean("myThreadPoolTaskExecutor")); - } - - @Test - public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCustomRegion() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSqs = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils.getField(amazonSqs, "realSQS"); - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.EU_WEST_1) - .getServiceEndpoint("sqs")); - } - - @Test - public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientWithCustomRegionReturnedByProvider() - throws Exception { - // Arrange - DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); - - // Act - reader.loadBeanDefinitions(new ClassPathResource( - getClass().getSimpleName() + "-custom-region-provider.xml", getClass())); - - // Assert - AmazonSQSBufferedAsyncClient amazonSqs = registry - .getBean(AmazonSQSBufferedAsyncClient.class); - Object amazonSqsAsyncClient = ReflectionTestUtils.getField(amazonSqs, "realSQS"); - assertThat( - ReflectionTestUtils.getField(amazonSqsAsyncClient, "endpoint").toString()) - .isEqualTo("https://" + Region.getRegion(Regions.AP_SOUTHEAST_2) - .getServiceEndpoint("sqs")); - } - -} diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java index b4b6403da..c4b523819 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java @@ -20,8 +20,13 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.aws.messaging.config.annotation.EnableSns; +import org.springframework.cloud.aws.messaging.endpoint.ComplexNotificationEndpointControllerTest.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -30,6 +35,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.util.FileCopyUtils; import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; @@ -42,7 +48,7 @@ */ @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration +@ContextConfiguration(classes = Config.class) public class ComplexNotificationEndpointControllerTest { @Autowired @@ -136,4 +142,16 @@ public void notification_unsubscribeConfirmationReceivedAsMessage_reSubscription + "0bddfb45"); } + @EnableWebMvc + @EnableSns + @Import(ComplexNotificationTestController.class) + static class Config { + + @Bean + AmazonSNS amazonSNS() { + return Mockito.mock(AmazonSNS.class); + } + + } + } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java index 111f0f9c4..71cf1919d 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java @@ -20,8 +20,13 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.aws.messaging.config.annotation.EnableSns; +import org.springframework.cloud.aws.messaging.endpoint.NotificationEndpointControllerTest.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -30,6 +35,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.util.FileCopyUtils; import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; @@ -42,7 +48,7 @@ */ @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration +@ContextConfiguration(classes = Config.class) public class NotificationEndpointControllerTest { @Autowired @@ -129,4 +135,16 @@ public void notification_unsubscribeConfirmationReceivedAsMessage_reSubscription + "54605e020f04ad3d47796045c9f24d902e72e811a1ad59852cad453f40bddfb45"); } + @EnableWebMvc + @EnableSns + @Import(NotificationTestController.class) + static class Config { + + @Bean + AmazonSNS amazonSNS() { + return Mockito.mock(AmazonSNS.class); + } + + } + } diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-back-off-time.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-back-off-time.xml deleted file mode 100644 index 896c2a792..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-back-off-time.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-context-region.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-context-region.xml deleted file mode 100644 index 1678036ea..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-context-region.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml deleted file mode 100644 index 75781d2d4..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-argument-resolvers.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-argument-resolvers.xml deleted file mode 100644 index b52e32030..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-argument-resolvers.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-destination-resolver.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-destination-resolver.xml deleted file mode 100644 index 10f7f4531..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-destination-resolver.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-properties.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-properties.xml deleted file mode 100644 index 347707e36..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-properties.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region-provider.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region-provider.xml deleted file mode 100644 index 29b5ebec1..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region-provider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region.xml deleted file mode 100644 index 3cfc8078d..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-region.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-return-value-handlers.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-return-value-handlers.xml deleted file mode 100644 index 9d30f6101..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-return-value-handlers.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-task-executor.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-task-executor.xml deleted file mode 100644 index 429dc1fdb..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-task-executor.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 400b17abe..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-with-send-to-message-template.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-with-send-to-message-template.xml deleted file mode 100644 index 78bbf4371..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-with-send-to-message-template.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.xml deleted file mode 100644 index df35fa43c..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/MessagingSchemaWithoutSchemaTest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegion.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegion.xml deleted file mode 100644 index e769fafe5..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegion.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegionProvider.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegionProvider.xml deleted file mode 100644 index f07eac683..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customRegionProvider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml deleted file mode 100644 index fec426a05..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 83796863d..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-amazon-sns.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-amazon-sns.xml deleted file mode 100644 index dd40dd6b9..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-amazon-sns.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml deleted file mode 100644 index 318eebeed..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region.xml deleted file mode 100644 index 8c7cfa7de..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-custom-region.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 15f62832c..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml deleted file mode 100644 index 185a9fd62..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-amazon-sqs.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-amazon-sqs.xml deleted file mode 100644 index 1644a49f1..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-amazon-sqs.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-converter.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-converter.xml deleted file mode 100644 index 32d2bcb8d..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-converter.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml deleted file mode 100644 index 7d4024a89..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region-provider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region.xml deleted file mode 100644 index bd0594f81..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-custom-region.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index ffb4de102..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-multiple-templates.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-multiple-templates.xml deleted file mode 100644 index f23a11d20..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-multiple-templates.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml deleted file mode 100644 index ed7f92d9e..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest-with-default-destination.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region-provider.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region-provider.xml deleted file mode 100644 index 1d35f7da4..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region-provider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region.xml deleted file mode 100644 index 3292cc645..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-region.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-task-executor.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-task-executor.xml deleted file mode 100644 index 6c3862b9d..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-custom-task-executor.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-minimal.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-minimal.xml deleted file mode 100644 index 07e12fa61..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-minimal.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-not-buffered.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-not-buffered.xml deleted file mode 100644 index 9a7f41e5b..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest-not-buffered.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml deleted file mode 100644 index 24c32e153..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest-context.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest-context.xml deleted file mode 100644 index 4c5baaefb..000000000 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest-context.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - From 8af3acadb461970b93e16f5f784b02522bf877bf Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 8 Jun 2020 17:10:36 +0200 Subject: [PATCH 29/47] Changed packaging to jar --- docs/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pom.xml b/docs/pom.xml index 4b3a18d6d..9116c22a9 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -25,7 +25,7 @@ 3.0.0-SNAPSHOT spring-cloud-aws-docs - pom + jar Spring Cloud AWS Docs Spring Cloud AWS Docs From 6a7580b72ce025f04755de64bf408fa6ab97caee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Sun, 7 Jun 2020 16:41:17 -0500 Subject: [PATCH 30/47] Remove Autowired annotations --- .../ContextStackAutoConfiguration.java | 31 +++++++------ .../mail/MailSenderAutoConfiguration.java | 12 ++++-- .../CloudWatchExportAutoConfiguration.java | 13 +++--- .../ElastiCacheCachingConfiguration.java | 22 ++++++---- .../annotation/ContextStackConfiguration.java | 22 ++++++---- .../config/annotation/SnsConfiguration.java | 17 +++++--- .../annotation/SqsClientConfiguration.java | 18 +++++--- .../config/annotation/SqsConfiguration.java | 43 +++++++++++-------- 8 files changed, 106 insertions(+), 72 deletions(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java index 4fcdc80c6..e56541a21 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; import com.amazonaws.services.ec2.AmazonEC2; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -44,6 +44,7 @@ /** * @author Agim Emruli * @author Maciej Walkowiak + * @author Eddú Meléndez */ @Configuration(proxyBeanMethods = false) @Import({ ContextCredentialsAutoConfiguration.class, @@ -52,17 +53,11 @@ @EnableConfigurationProperties(AwsStackProperties.class) public class ContextStackAutoConfiguration { - @Autowired - private AwsStackProperties properties; + private final AwsStackProperties properties; - @Autowired(required = false) - private AmazonEC2 amazonEC2; - - @Autowired(required = false) - private RegionProvider regionProvider; - - @Autowired(required = false) - private AWSCredentialsProvider credentialsProvider; + public ContextStackAutoConfiguration(AwsStackProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean @@ -76,8 +71,10 @@ public StackNameProvider staticStackNameProvider() { @ConditionalOnProperty(name = "cloud.aws.stack.auto", havingValue = "true", matchIfMissing = true) public StackNameProvider autoDetectingStackNameProvider( - AmazonCloudFormation amazonCloudFormation) { - return new AutoDetectingStackNameProvider(amazonCloudFormation, this.amazonEC2); + AmazonCloudFormation amazonCloudFormation, + ObjectProvider amazonEC2) { + return new AutoDetectingStackNameProvider(amazonCloudFormation, + amazonEC2.getIfAvailable()); } @Bean @@ -92,9 +89,11 @@ public StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean( @Bean @ConditionalOnMissingAmazonClient(AmazonCloudFormation.class) - public AmazonWebserviceClientFactoryBean amazonCloudFormation() { + public AmazonWebserviceClientFactoryBean amazonCloudFormation( + ObjectProvider regionProvider, + ObjectProvider credentialsProvider) { return new AmazonWebserviceClientFactoryBean<>(AmazonCloudFormationClient.class, - this.credentialsProvider, this.regionProvider); + credentialsProvider.getIfAvailable(), regionProvider.getIfAvailable()); } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfiguration.java index 395fe4a0c..74e9c26b3 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -39,6 +39,7 @@ /** * @author Agim Emruli + * @author Eddú Meléndez */ @Configuration(proxyBeanMethods = false) @AutoConfigureAfter(org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration.class) @@ -48,8 +49,11 @@ @Import(ContextCredentialsAutoConfiguration.class) public class MailSenderAutoConfiguration { - @Autowired(required = false) - private RegionProvider regionProvider; + private final RegionProvider regionProvider; + + public MailSenderAutoConfiguration(ObjectProvider regionProvider) { + this.regionProvider = regionProvider.getIfAvailable(); + } @Bean @ConditionalOnMissingAmazonClient(AmazonSimpleEmailService.class) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfiguration.java index 26710b51f..1d52f400d 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import io.micrometer.cloudwatch.CloudWatchMeterRegistry; import io.micrometer.core.instrument.Clock; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; @@ -47,6 +47,7 @@ * @author Jon Schneider * @author Dawid Kublik * @author Jan Sauer + * @author Eddú Meléndez * @since 2.0.0 */ @Configuration(proxyBeanMethods = false) @@ -60,9 +61,6 @@ @ConditionalOnClass({ CloudWatchMeterRegistry.class, RegionProvider.class }) public class CloudWatchExportAutoConfiguration { - @Autowired(required = false) - private RegionProvider regionProvider; - @Bean @ConditionalOnProperty(value = "management.metrics.export.cloudwatch.enabled", matchIfMissing = true) @@ -74,9 +72,10 @@ public CloudWatchMeterRegistry cloudWatchMeterRegistry(CloudWatchConfig config, @Bean @ConditionalOnMissingAmazonClient(AmazonCloudWatchAsync.class) public AmazonWebserviceClientFactoryBean amazonCloudWatchAsync( - AWSCredentialsProvider credentialsProvider) { + AWSCredentialsProvider credentialsProvider, + ObjectProvider regionProvider) { return new AmazonWebserviceClientFactoryBean<>(AmazonCloudWatchAsyncClient.class, - credentialsProvider, this.regionProvider); + credentialsProvider, regionProvider.getIfAvailable()); } @Bean diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfiguration.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfiguration.java index 15f6dcac5..f99eb5f97 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfiguration.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import com.amazonaws.services.elasticache.AmazonElastiCache; import com.amazonaws.services.elasticache.AmazonElastiCacheClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cloud.aws.cache.CacheFactory; import org.springframework.cloud.aws.cache.memcached.MemcachedCacheFactory; @@ -49,6 +49,7 @@ /** * @author Agim Emruli + * @author Eddú Meléndez */ @Configuration(proxyBeanMethods = false) @Import(ContextDefaultConfigurationRegistrar.class) @@ -60,14 +61,19 @@ public class ElastiCacheCachingConfiguration implements ImportAware { private AnnotationAttributes annotationAttributes; - @Autowired(required = false) - private RegionProvider regionProvider; + private final RegionProvider regionProvider; - @Autowired(required = false) - private AWSCredentialsProvider credentialsProvider; + private final AWSCredentialsProvider credentialsProvider; - @Autowired(required = false) - private ListableStackResourceFactory stackResourceFactory; + private final ListableStackResourceFactory stackResourceFactory; + + public ElastiCacheCachingConfiguration(ObjectProvider regionProvider, + ObjectProvider credentialsProvider, + ObjectProvider stackResourceFactory) { + this.regionProvider = regionProvider.getIfAvailable(); + this.credentialsProvider = credentialsProvider.getIfAvailable(); + this.stackResourceFactory = stackResourceFactory.getIfAvailable(); + } @Override public void setImportMetadata(AnnotationMetadata importMetadata) { diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfiguration.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfiguration.java index c41107350..f3470ffb4 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfiguration.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; import com.amazonaws.services.ec2.AmazonEC2; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient; import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean; import org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider; @@ -39,6 +39,7 @@ /** * @author Agim Emruli + * @author Eddú Meléndez */ @Configuration(proxyBeanMethods = false) @Import(ContextDefaultConfigurationRegistrar.class) @@ -46,14 +47,19 @@ public class ContextStackConfiguration implements ImportAware { private AnnotationAttributes annotationAttributes; - @Autowired(required = false) - private RegionProvider regionProvider; + private final RegionProvider regionProvider; - @Autowired(required = false) - private AWSCredentialsProvider credentialsProvider; + private final AWSCredentialsProvider credentialsProvider; - @Autowired(required = false) - private AmazonEC2 amazonEc2; + private final AmazonEC2 amazonEc2; + + public ContextStackConfiguration(ObjectProvider regionProvider, + ObjectProvider credentialsProvider, + ObjectProvider amazonEc2) { + this.regionProvider = regionProvider.getIfAvailable(); + this.credentialsProvider = credentialsProvider.getIfAvailable(); + this.amazonEc2 = amazonEc2.getIfAvailable(); + } @Override public void setImportMetadata(AnnotationMetadata importMetadata) { diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfiguration.java index ccac4272a..e89c94bcd 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import com.amazonaws.services.sns.AmazonSNS; import com.amazonaws.services.sns.AmazonSNSClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient; import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean; import org.springframework.cloud.aws.core.region.RegionProvider; @@ -30,16 +30,21 @@ /** * @author Alain Sahli * @author Agim Emruli + * @author Eddú Meléndez * @since 1.0 */ @Configuration(proxyBeanMethods = false) public class SnsConfiguration { - @Autowired(required = false) - private AWSCredentialsProvider awsCredentialsProvider; + private final AWSCredentialsProvider awsCredentialsProvider; - @Autowired(required = false) - private RegionProvider regionProvider; + private final RegionProvider regionProvider; + + public SnsConfiguration(ObjectProvider awsCredentialsProvider, + ObjectProvider regionProvider) { + this.awsCredentialsProvider = awsCredentialsProvider.getIfAvailable(); + this.regionProvider = regionProvider.getIfAvailable(); + } @ConditionalOnMissingAmazonClient(AmazonSNS.class) @Bean diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsClientConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsClientConfiguration.java index 9c110071f..7119c0a93 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsClientConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsyncClient; import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient; import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean; import org.springframework.cloud.aws.core.region.RegionProvider; @@ -31,17 +31,23 @@ /** * @author Alain Sahli + * @author Eddú Meléndez * @since 1.0 */ @Configuration(proxyBeanMethods = false) @ConditionalOnMissingAmazonClient(AmazonSQS.class) public class SqsClientConfiguration { - @Autowired(required = false) - private AWSCredentialsProvider awsCredentialsProvider; + private final AWSCredentialsProvider awsCredentialsProvider; - @Autowired(required = false) - private RegionProvider regionProvider; + private final RegionProvider regionProvider; + + public SqsClientConfiguration( + ObjectProvider awsCredentialsProvider, + ObjectProvider regionProvider) { + this.awsCredentialsProvider = awsCredentialsProvider.getIfAvailable(); + this.regionProvider = regionProvider.getIfAvailable(); + } @Lazy @Bean(destroyMethod = "shutdown") diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java index 2e26b63d4..8f48072eb 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsync; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.aws.context.config.annotation.ContextDefaultConfigurationRegistrar; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.cloud.aws.messaging.config.QueueMessageHandlerFactory; @@ -37,30 +37,38 @@ /** * @author Alain Sahli * @author Maciej Walkowiak + * @author Eddú Meléndez * @since 1.0 */ @Configuration @Import(ContextDefaultConfigurationRegistrar.class) public class SqsConfiguration { - @Autowired(required = false) - // @checkstyle:off - private final SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory = new SimpleMessageListenerContainerFactory(); + private final SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory; - // @checkstyle:on - @Autowired(required = false) - private final QueueMessageHandlerFactory queueMessageHandlerFactory = new QueueMessageHandlerFactory(); + private final QueueMessageHandlerFactory queueMessageHandlerFactory; - // @checkstyle:off - @Autowired - public BeanFactory beanFactory; + private final BeanFactory beanFactory; - // @checkstyle:on - @Autowired(required = false) - private ResourceIdResolver resourceIdResolver; + private final ResourceIdResolver resourceIdResolver; - @Autowired(required = false) - private MappingJackson2MessageConverter mappingJackson2MessageConverter; + private final MappingJackson2MessageConverter mappingJackson2MessageConverter; + + public SqsConfiguration( + ObjectProvider simpleMessageListenerContainerFactory, + ObjectProvider queueMessageHandlerFactory, + BeanFactory beanFactory, + ObjectProvider resourceIdResolver, + ObjectProvider mappingJackson2MessageConverter) { + this.simpleMessageListenerContainerFactory = simpleMessageListenerContainerFactory + .getIfAvailable(SimpleMessageListenerContainerFactory::new); + this.queueMessageHandlerFactory = queueMessageHandlerFactory + .getIfAvailable(QueueMessageHandlerFactory::new); + this.beanFactory = beanFactory; + this.resourceIdResolver = resourceIdResolver.getIfAvailable(); + this.mappingJackson2MessageConverter = mappingJackson2MessageConverter + .getIfAvailable(); + } @Bean public SimpleMessageListenerContainer simpleMessageListenerContainer( @@ -68,7 +76,8 @@ public SimpleMessageListenerContainer simpleMessageListenerContainer( if (this.simpleMessageListenerContainerFactory.getAmazonSqs() == null) { this.simpleMessageListenerContainerFactory.setAmazonSqs(amazonSqs); } - if (this.simpleMessageListenerContainerFactory.getResourceIdResolver() == null) { + if (this.simpleMessageListenerContainerFactory.getResourceIdResolver() == null + && this.resourceIdResolver != null) { this.simpleMessageListenerContainerFactory .setResourceIdResolver(this.resourceIdResolver); } From 80391e9df4d9e1710884915d91e9e3db2e6d6ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Mon, 8 Jun 2020 22:42:50 -0500 Subject: [PATCH 31/47] Enforce spring-javaformat plugin --- .github/CONTRIBUTING.md | 8 +++----- pom.xml | 9 +++++++++ .../AwsSecretsManagerPropertySourceLocator.java | 9 ++++++--- .../AwsSecretsManagerPropertySourceLocatorTest.java | 12 ++++++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index eb9a16ae6..58e1628b2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -24,11 +24,9 @@ unacceptable behavior to spring-code-of-conduct@pivotal.io. None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge. -* Use the Spring Framework code format conventions. If you use Eclipse - you can import formatter settings using the - `eclipse-code-formatter.xml` file from the - [Spring Cloud Build](https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml) project. If using IntelliJ, you can use the - [Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546) to import the same file. +* We use the [Spring JavaFormat](https://github.com/spring-io/spring-javaformat/) project + to apply code formatting conventions. Format de code running + `./mvnw io.spring.javaformat:spring-javaformat-maven-plugin:apply` * Make sure all new `.java` files to have a simple Javadoc class comment with at least an `@author` tag identifying you, and preferably at least a paragraph on what the class is for. diff --git a/pom.xml b/pom.xml index 94f767b64..c27159ee5 100644 --- a/pom.xml +++ b/pom.xml @@ -155,6 +155,15 @@ io.spring.javaformat spring-javaformat-maven-plugin + + + validate + true + + validate + + + diff --git a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java index aea23d3c2..8524dbfcd 100644 --- a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java +++ b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocator.java @@ -53,13 +53,15 @@ public class AwsSecretsManagerPropertySourceLocator implements PropertySourceLoc private Log logger = LogFactory.getLog(getClass()); - public AwsSecretsManagerPropertySourceLocator(String propertySourceName, AWSSecretsManager smClient, AwsSecretsManagerProperties properties) { + public AwsSecretsManagerPropertySourceLocator(String propertySourceName, + AWSSecretsManager smClient, AwsSecretsManagerProperties properties) { this.propertySourceName = propertySourceName; this.smClient = smClient; this.properties = properties; } - public AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient, AwsSecretsManagerProperties properties) { + public AwsSecretsManagerPropertySourceLocator(AWSSecretsManager smClient, + AwsSecretsManagerProperties properties) { this("aws-secrets-manager", smClient, properties); } @@ -95,7 +97,8 @@ public PropertySource locate(Environment environment) { Collections.reverse(this.contexts); - CompositePropertySource composite = new CompositePropertySource(this.propertySourceName); + CompositePropertySource composite = new CompositePropertySource( + this.propertySourceName); for (String propertySourceContext : this.contexts) { try { diff --git a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java index d487fb32a..77da6b75e 100644 --- a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java +++ b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java @@ -44,10 +44,12 @@ public class AwsSecretsManagerPropertySourceLocatorTest { public void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecifiedName() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); - when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult); + when(smClient.getSecretValue(any(GetSecretValueRequest.class))) + .thenReturn(secretValueResult); AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); - AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator("my-name", smClient, properties); + AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator( + "my-name", smClient, properties); PropertySource propertySource = locator.locate(env); @@ -58,10 +60,12 @@ public void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecified public void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); - when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult); + when(smClient.getSecretValue(any(GetSecretValueRequest.class))) + .thenReturn(secretValueResult); AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); - AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(smClient, properties); + AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator( + smClient, properties); PropertySource propertySource = locator.locate(env); From 650cc6900437f07a78d73cf58408b2e38c27e2ef Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Tue, 9 Jun 2020 00:48:29 +0200 Subject: [PATCH 32/47] Use DefaultAWSCredentialsProvider and DefaultAWSRegionProviderChain by default. Fixes gh-583 Closes gh-568 --- docs/src/main/asciidoc/_configprops.adoc | 5 +- docs/src/main/asciidoc/spring-cloud-aws.adoc | 26 +- .../ContextCredentialsAutoConfiguration.java | 120 ++--- ...ontextRegionProviderAutoConfiguration.java | 68 +-- .../properties/AwsCredentialsProperties.java | 21 +- .../properties/AwsRegionProperties.java | 30 +- ...ntextCredentialsAutoConfigurationTest.java | 423 +++++------------- ...xtRegionProviderAutoConfigurationTest.java | 101 ++--- .../AwsCredentialsPropertiesTest.java | 22 +- .../properties/AwsRegionPropertiesTest.java | 10 - .../support/ContextConfigurationUtils.java | 12 - 11 files changed, 211 insertions(+), 627 deletions(-) diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 5825aa564..e6338ea1e 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -14,17 +14,14 @@ |aws.secretsmanager.prefix | /secret | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config". |aws.secretsmanager.profile-separator | _ | |cloud.aws.credentials.access-key | | The access key to be used with a static provider. -|cloud.aws.credentials.instance-profile | true | Configures an instance profile credentials provider with no further configuration. +|cloud.aws.credentials.instance-profile | false | Configures an instance profile credentials provider with no further configuration. |cloud.aws.credentials.profile-name | | The AWS profile name. |cloud.aws.credentials.profile-path | | The AWS profile path. |cloud.aws.credentials.secret-key | | The secret key to be used with a static provider. -|cloud.aws.credentials.use-default-aws-credentials-chain | false | Use the DefaultAWSCredentials Chain instead of configuring a custom credentials chain. |cloud.aws.loader.core-pool-size | 1 | The core pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setCorePoolSize(int) |cloud.aws.loader.max-pool-size | | The maximum pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize(int) |cloud.aws.loader.queue-capacity | | The maximum queue capacity for backed up S3 requests. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity(int) -|cloud.aws.region.auto | true | Enables automatic region detection based on the EC2 meta data service. |cloud.aws.region.static | | -|cloud.aws.region.use-default-aws-region-chain | false | Whether default AWS SDK region provider chain should be used when auto is set to true. |cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application. |cloud.aws.stack.name | | The name of the manually configured stack name that will be used to retrieve the resources. diff --git a/docs/src/main/asciidoc/spring-cloud-aws.adoc b/docs/src/main/asciidoc/spring-cloud-aws.adoc index b2deccfe9..ac4b6ad41 100644 --- a/docs/src/main/asciidoc/spring-cloud-aws.adoc +++ b/docs/src/main/asciidoc/spring-cloud-aws.adoc @@ -305,14 +305,16 @@ only configure classes that are available in the Spring Boot application's class ===== Configuring credentials Spring Boot provides a standard way to define properties with property file or YAML configuration files. Spring Cloud AWS provides support to configure the credential information with the Spring Boot application configuration files. -Spring Cloud AWS provides the following properties to configure the credentials setup for the whole application. -Unless `cloud.aws.credentials.use-default-aws-credentials-chain` is set to `true`, Spring Cloud AWS configures following -credentials chain: +By default Spring Cloud AWS configures https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html[DefaultAWSCredentialsProviderChain] to resolve AWS credentials. + +If other credentials providers are configured, https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html[DefaultAWSCredentialsProviderChain] is not used and Spring Cloud AWS configures following credentials chain: 1. `AWSStaticCredentialsProvider` if `cloud.aws.credentials.access-key` is provided -2. `EC2ContainerCredentialsProviderWrapper` unless `cloud.aws.credentials.instance-profile` is set to `false` -3. `ProfileCredentialsProvider` +2. `EC2ContainerCredentialsProviderWrapper` if `cloud.aws.credentials.instance-profile` is set to `true` +3. `ProfileCredentialsProvider` if `cloud.aws.credentials.profile-name` is provided + +Spring Cloud AWS provides the following properties to configure the credentials setup for the whole application. [cols="3*", options="header"] |=== @@ -339,15 +341,11 @@ credentials chain: |cloud.aws.credentials.profile-path |`~/.aws/credentials` |The file path where the profile configuration file is located. Defaults to `~/.aws/credentials` if value is not provided - -|cloud.aws.credentials.use-default-aws-credentials-chain -|true -|Use the DefaultAWSCredentials Chain instead of configuring a custom credentials chain |=== ===== Configuring region Like for the credentials, the Spring Cloud AWS module also supports the configuration of the region inside the Spring -Boot configuration files. The region can be automatically detected or explicitly configured (e.g. in case of local tests +Boot configuration files. The region can be automatically detected using https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/DefaultAwsRegionProviderChain.html[DefaultAwsRegionProviderChain] or explicitly configured (e.g. in case of local tests against the AWS cloud). The properties to configure the region are shown below @@ -358,14 +356,6 @@ The properties to configure the region are shown below |example |description -|cloud.aws.region.auto -|true -|Enables automatic region detection based on the EC2 meta data service - -|cloud.aws.region.use-default-aws-region-chain -|true -|Use the DefaultAWSRegion Chain instead of configuring a custom region chain - |cloud.aws.region.static |eu-west-1 |Configures a static region for the application. Possible regions are (currently) us-east-1, us-west-1, us-west-2, diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java index 56fd92d6a..788432c19 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfiguration.java @@ -16,100 +16,76 @@ package org.springframework.cloud.aws.autoconfigure.context; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import java.util.ArrayList; +import java.util.List; + +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSCredentialsProviderChain; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; +import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper; +import com.amazonaws.auth.profile.ProfileCredentialsProvider; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.aws.autoconfigure.context.properties.AwsCredentialsProperties; -import org.springframework.cloud.aws.context.config.annotation.ContextDefaultConfigurationRegistrar; -import org.springframework.cloud.aws.core.credentials.CredentialsProviderFactoryBean; -import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.core.env.Environment; -import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.StringUtils; -import static com.amazonaws.auth.profile.internal.AwsProfileNameLoader.DEFAULT_PROFILE_NAME; -import static org.springframework.cloud.aws.context.config.support.ContextConfigurationUtils.registerCredentialsProvider; -import static org.springframework.cloud.aws.context.config.support.ContextConfigurationUtils.registerDefaultAWSCredentialsProvider; +import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME; /** + * {@link EnableAutoConfiguration} for {@link AWSCredentialsProvider}. + * * @author Agim Emruli + * @author Maciej Walkowiak */ @Configuration(proxyBeanMethods = false) -@Import({ ContextDefaultConfigurationRegistrar.class, - ContextCredentialsAutoConfiguration.Registrar.class }) -@ConditionalOnClass(name = "com.amazonaws.auth.AWSCredentialsProvider") +@EnableConfigurationProperties(AwsCredentialsProperties.class) +@ConditionalOnClass(com.amazonaws.auth.AWSCredentialsProvider.class) public class ContextCredentialsAutoConfiguration { - /** - * The prefix used for AWS credentials related properties. - */ - public static final String AWS_CREDENTIALS_PROPERTY_PREFIX = "cloud.aws.credentials"; + @Bean(name = CREDENTIALS_PROVIDER_BEAN_NAME) + @ConditionalOnMissingBean(name = CREDENTIALS_PROVIDER_BEAN_NAME) + public AWSCredentialsProvider awsCredentialsProvider( + AwsCredentialsProperties properties) { - /** - * Bind AWS credentials related properties to a property instance. - * @return An {@link AwsCredentialsProperties} instance - */ - @Bean - @ConfigurationProperties(prefix = AWS_CREDENTIALS_PROPERTY_PREFIX) - public AwsCredentialsProperties awsCredentialsProperties() { - return new AwsCredentialsProperties(); - } + List providers = resolveCredentialsProviders(properties); - /** - * Registrar for the credentials provider. - */ - public static class Registrar - implements ImportBeanDefinitionRegistrar, EnvironmentAware { + if (providers.isEmpty()) { + return new DefaultAWSCredentialsProviderChain(); + } + else { + return new AWSCredentialsProviderChain(providers); + } + } - private Environment environment; + private List resolveCredentialsProviders( + AwsCredentialsProperties properties) { + List providers = new ArrayList<>(); - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; + if (StringUtils.hasText(properties.getAccessKey()) + && StringUtils.hasText(properties.getSecretKey())) { + providers.add(new AWSStaticCredentialsProvider(new BasicAWSCredentials( + properties.getAccessKey(), properties.getSecretKey()))); } - @Override - public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, - BeanDefinitionRegistry registry) { - // Do not register a credentials provider if a bean with the same name is - // already registered. - if (registry.containsBeanDefinition( - CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME)) { - return; - } + if (properties.isInstanceProfile()) { + providers.add(new EC2ContainerCredentialsProviderWrapper()); + } - Boolean useDefaultCredentialsChain = this.environment - .getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX - + ".use-default-aws-credentials-chain", - Boolean.class, false); - String accessKey = this.environment - .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"); - String secretKey = this.environment - .getProperty(AWS_CREDENTIALS_PROPERTY_PREFIX + ".secret-key"); - if (useDefaultCredentialsChain && (StringUtils.isEmpty(accessKey) - || StringUtils.isEmpty(secretKey))) { - registerDefaultAWSCredentialsProvider(registry); - } - else { - registerCredentialsProvider(registry, accessKey, secretKey, - this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".instance-profile", - Boolean.class, true) - && !this.environment.containsProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".access-key"), - this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-name", - DEFAULT_PROFILE_NAME), - this.environment.getProperty( - AWS_CREDENTIALS_PROPERTY_PREFIX + ".profile-path")); - } + if (properties.getProfileName() != null) { + providers.add(properties.getProfilePath() != null + ? new ProfileCredentialsProvider(properties.getProfilePath(), + properties.getProfileName()) + : new ProfileCredentialsProvider(properties.getProfileName())); } + return providers; } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java index ac2e8b686..9f58cc076 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfiguration.java @@ -16,20 +16,17 @@ package org.springframework.cloud.aws.autoconfigure.context; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.aws.autoconfigure.context.properties.AwsRegionProperties; -import org.springframework.context.EnvironmentAware; +import org.springframework.cloud.aws.core.region.DefaultAwsRegionProviderChainDelegate; +import org.springframework.cloud.aws.core.region.RegionProvider; +import org.springframework.cloud.aws.core.region.StaticRegionProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.core.env.Environment; -import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.StringUtils; import static org.springframework.cloud.aws.context.config.support.ContextConfigurationUtils.REGION_PROVIDER_BEAN_NAME; -import static org.springframework.cloud.aws.context.config.support.ContextConfigurationUtils.registerRegionProvider; /** * Region auto configuration, based on credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - } - - // @checkstyle:off - @Test - public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider_existAccessKeyAndSecretKey() { - // @checkstyle:on - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues - .of("cloud.aws.credentials.accessKey:testAccessKey", - "cloud.aws.credentials.secretKey:testSecretKey", - "cloud.aws.credentials.useDefaultAwsCredentialsChain:true") - .applyTo(this.context); - this.context.refresh(); - - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("testAccessKey"); - assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) - .isEqualTo("testSecretKey"); - } - - @Test - public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider_existAccessKeyAndSecretKey() { + public void credentialsProvider_noExplicitCredentialsProviderConfigured_configuresDefaultAwsCredentialsProviderChain() { // @checkstyle:on - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues - .of("cloud.aws.credentials.access-key:testAccessKey", - "cloud.aws.credentials.secret-key:testSecretKey", - "cloud.aws.credentials.use-default-aws-credentials-chain:true") - .applyTo(this.context); - this.context.refresh(); - - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); + this.contextRunner.run((context) -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull() + .isInstanceOf(DefaultAWSCredentialsProviderChain.class); + }); - assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("testAccessKey"); - assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) - .isEqualTo("testSecretKey"); } @Test public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.useDefaultAwsCredentialsChain:true") - .applyTo(this.context); - this.context.refresh(); - - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - assertThat(awsCredentialsProvider.getClass() - .isAssignableFrom(DefaultAWSCredentialsProviderChain.class)).isTrue(); - } - - @Test - public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues - .of("cloud.aws.credentials.use-default-aws-credentials-chain:true") - .applyTo(this.context); - this.context.refresh(); - - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - assertThat(awsCredentialsProvider.getClass() - .isAssignableFrom(DefaultAWSCredentialsProviderChain.class)).isTrue(); + this.contextRunner + .withPropertyValues( + "cloud.aws.credentials.use-default-aws-credentials-chain:true") + .run((context -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + assertThat(awsCredentialsProvider) + .isInstanceOf(DefaultAWSCredentialsProviderChain.class); + })); } // @checkstyle:off @Test public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { // @checkstyle:on - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.accessKey:foo", - "cloud.aws.credentials.secretKey:bar").applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProviderChain.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(AWSStaticCredentialsProvider.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("foo"); - assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) - .isEqualTo("bar"); - - } - - // @checkstyle:off - @Test - public void credentialsProvider_dashSeparatedAccessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { - // @checkstyle:on - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.access-key:foo", - "cloud.aws.credentials.secret-key:bar").applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProviderChain.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(AWSStaticCredentialsProvider.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("foo"); - assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) - .isEqualTo("bar"); - + this.contextRunner.withPropertyValues( + "cloud.aws.credentials.use-default-aws-credentials-chain:false", + "cloud.aws.credentials.accessKey:foo", + "cloud.aws.credentials.secretKey:bar").run((context) -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProviderChain.class); + assertThat(awsCredentialsProvider).isNotNull(); + assertThat( + awsCredentialsProvider.getCredentials().getAWSAccessKeyId()) + .isEqualTo("foo"); + assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey()) + .isEqualTo("bar"); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders).hasSize(1) + .hasOnlyElementsOfType(AWSStaticCredentialsProvider.class); + }); } @Test public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.instanceProfile") - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - } - - @Test - public void credentialsProvider_dashSeparatedInstanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.instance-profile") - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); + this.contextRunner.withPropertyValues( + "cloud.aws.credentials.use-default-aws-credentials-chain:false", + "cloud.aws.credentials.instance-profile:true").run((context) -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders).hasSize(1).hasOnlyElementsOfType( + EC2ContainerCredentialsProviderWrapper.class); + }); } @Test public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.profileName:test") - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - assertThat( - ReflectionTestUtils.getField(credentialsProviders.get(1), "profileName")) - .isEqualTo("test"); - } - - @Test - public void credentialsProvider_dashSeparatedProfileNameConfigured_configuresProfileCredentialsProvider() { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.credentials.profile-name:test") - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - assertThat( - ReflectionTestUtils.getField(credentialsProviders.get(1), "profileName")) - .isEqualTo("test"); + this.contextRunner.withPropertyValues( + "cloud.aws.credentials.use-default-aws-credentials-chain:false", + "cloud.aws.credentials.profile-name:test").run((context) -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders).hasSize(1) + .hasOnlyElementsOfType(ProfileCredentialsProvider.class); + assertThat(ReflectionTestUtils.getField(credentialsProviders.get(0), + "profileName")).isEqualTo("test"); + }); } @Test public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() throws IOException { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues - .of("cloud.aws.credentials.profileName:customProfile", + this.contextRunner + .withPropertyValues( + "cloud.aws.credentials.use-default-aws-credentials-chain:false", + "cloud.aws.credentials.profileName:customProfile", "cloud.aws.credentials.profilePath:" + new ClassPathResource( getClass().getSimpleName() + "-profile", getClass()) .getFile().getAbsolutePath()) - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders - .get(1); - assertThat(provider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("testAccessKey"); - assertThat(provider.getCredentials().getAWSSecretKey()) - .isEqualTo("testSecretKey"); - } - - @Test - public void credentialsProvider_dashSeparatedProfileNameAndPathConfigured_configuresProfileCredentialsProvider() - throws IOException { - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextCredentialsAutoConfiguration.class); - TestPropertyValues - .of("cloud.aws.credentials.profile-name:customProfile", - "cloud.aws.credentials.profile-path:" + new ClassPathResource( - getClass().getSimpleName() + "-profile", getClass()) - .getFile().getAbsolutePath()) - .applyTo(this.context); - this.context.refresh(); - AWSCredentialsProvider awsCredentialsProvider = this.context.getBean( - AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, - AWSCredentialsProvider.class); - assertThat(awsCredentialsProvider).isNotNull(); - - @SuppressWarnings("unchecked") - List credentialsProviders = (List) ReflectionTestUtils - .getField(awsCredentialsProvider, "credentialsProviders"); - assertThat(credentialsProviders.size()).isEqualTo(2); - assertThat(EC2ContainerCredentialsProviderWrapper.class - .isInstance(credentialsProviders.get(0))).isTrue(); - assertThat( - ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1))) - .isTrue(); - - ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders - .get(1); - assertThat(provider.getCredentials().getAWSAccessKeyId()) - .isEqualTo("testAccessKey"); - assertThat(provider.getCredentials().getAWSSecretKey()) - .isEqualTo("testSecretKey"); + .run((context) -> { + AWSCredentialsProvider awsCredentialsProvider = context.getBean( + AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, + AWSCredentialsProvider.class); + assertThat(awsCredentialsProvider).isNotNull(); + + @SuppressWarnings("unchecked") + List credentialsProviders = (List) ReflectionTestUtils + .getField(awsCredentialsProvider, "credentialsProviders"); + assertThat(credentialsProviders).hasSize(1) + .hasOnlyElementsOfType(ProfileCredentialsProvider.class); + + ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders + .get(0); + assertThat(provider.getCredentials().getAWSAccessKeyId()) + .isEqualTo("testAccessKey"); + assertThat(provider.getCredentials().getAWSSecretKey()) + .isEqualTo("testSecretKey"); + }); } } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java index 745116481..55c36c2e3 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java @@ -18,102 +18,55 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.After; import org.junit.Test; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.aws.core.region.DefaultAwsRegionProviderChainDelegate; -import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider; import org.springframework.cloud.aws.core.region.StaticRegionProvider; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; /** + * Tests for {@link ContextRegionProviderAutoConfiguration}. + * * @author Agim Emruli * @author Petromir Dzhunev * @author Maciej Walkowiak */ public class ContextRegionProviderAutoConfigurationTest { - private AnnotationConfigApplicationContext context; - - @After - public void tearDown() throws Exception { - if (this.context != null) { - this.context.close(); - } - - } + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(ContextRegionProviderAutoConfiguration.class)); @Test - public void regionProvider_autoDetectionConfigured_Ec2metaDataRegionProviderConfigured() - throws Exception { - // Arrange - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextRegionProviderAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.region.auto").applyTo(this.context); - - // Act - this.context.refresh(); - - // Assert - assertThat(this.context.getBean(Ec2MetadataRegionProvider.class)).isNotNull(); + public void autoDetectionConfigured_noConfigurationProvided_DefaultAwsRegionProviderChainDelegateConfigured() { + this.contextRunner.run((context) -> { + assertThat(context.getBean(DefaultAwsRegionProviderChainDelegate.class)) + .isNotNull(); + }); } @Test - public void regionProvider_autoDetectionConfigured_emptyStaticRegionConfigured_Ec2metaDataRegionProviderConfigured() - throws Exception { - // Arrange - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextRegionProviderAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.region.auto").applyTo(this.context); - TestPropertyValues.of("cloud.aws.region.static:").applyTo(this.context); - - // Act - this.context.refresh(); - - // Assert - assertThat(this.context.getBean(Ec2MetadataRegionProvider.class)).isNotNull(); + public void autoDetectionConfigured_emptyStaticRegionConfigured_DefaultAwsRegionProviderChainDelegateConfigured() { + this.contextRunner.withPropertyValues("cloud.aws.region.static:") + .run((context) -> { + assertThat( + context.getBean(DefaultAwsRegionProviderChainDelegate.class)) + .isNotNull(); + }); } @Test - public void regionProvider_staticRegionConfigured_staticRegionProviderWithConfiguredRegionConfigured() - throws Exception { - // Arrange - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextRegionProviderAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.region.static:eu-west-1").applyTo(this.context); - - // Act - this.context.refresh(); - StaticRegionProvider regionProvider = this.context - .getBean(StaticRegionProvider.class); - - // Assert - assertThat(regionProvider.getRegion()) - .isEqualTo(Region.getRegion(Regions.EU_WEST_1)); - } - - @Test - public void regionProvider_autoDetectionAndDefaultChainConfigured_DefaultAwsRegionProviderChainDelegateConfigured() { - // Arrange - this.context = new AnnotationConfigApplicationContext(); - this.context.register(ContextRegionProviderAutoConfiguration.class); - TestPropertyValues.of("cloud.aws.region.auto:true").applyTo(this.context); - TestPropertyValues.of("cloud.aws.region.useDefaultAwsRegionChain:true") - .applyTo(this.context); - - // Act - this.context.refresh(); - - // Assert - assertThat(this.context.getBean(DefaultAwsRegionProviderChainDelegate.class)) - .isNotNull(); - assertThatThrownBy(() -> this.context.getBean(Ec2MetadataRegionProvider.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); + public void staticRegionConfigured_staticRegionProviderWithConfiguredRegionConfigured() { + this.contextRunner.withPropertyValues("cloud.aws.region.static:eu-west-1") + .run((context) -> { + StaticRegionProvider regionProvider = context + .getBean(StaticRegionProvider.class); + assertThat(regionProvider.getRegion()) + .isEqualTo(Region.getRegion(Regions.EU_WEST_1)); + }); } } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java index ccefe18b9..628524720 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java @@ -18,7 +18,6 @@ import java.util.UUID; -import com.amazonaws.auth.profile.internal.AwsProfileNameLoader; import org.junit.Before; import org.junit.Test; @@ -28,6 +27,7 @@ * Tests for {@link AwsCredentialsProperties}. * * @author Tom Gianos + * @author Maciej Walkowiak * @since 2.0.2 */ public class AwsCredentialsPropertiesTest { @@ -64,29 +64,17 @@ public void secretKeyCanBeSet() { @Test public void instanceProfileCanBeSet() { assertThat(this.properties.isInstanceProfile()) - .as("Instance profile default expected to be true").isTrue(); + .as("Instance profile default expected to be false").isFalse(); - this.properties.setInstanceProfile(false); + this.properties.setInstanceProfile(true); assertThat(this.properties.isInstanceProfile()) - .as("Instance profile should have been assigned").isFalse(); - } - - @Test - public void useDefaultAwsCredentialsChainCanBeSet() { - assertThat(this.properties.isUseDefaultAwsCredentialsChain()) - .as("useDefaultAwsCredentialsChain default expected to be false") - .isFalse(); - - this.properties.setUseDefaultAwsCredentialsChain(true); - assertThat(this.properties.isUseDefaultAwsCredentialsChain()) - .as("useDefaultAwsCredentialsChain should have been assigned").isTrue(); + .as("Instance profile should have been assigned").isTrue(); } @Test public void profileNameCanBeSet() { assertThat(this.properties.getProfileName()) - .as("Default profile name expected to be set") - .isEqualTo(AwsProfileNameLoader.DEFAULT_PROFILE_NAME); + .as("Default profile name is not expected to be set").isEqualTo(null); String newProfileName = UUID.randomUUID().toString(); this.properties.setProfileName(newProfileName); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java index e892f6850..75b2a858b 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java @@ -37,16 +37,6 @@ public void setup() { this.properties = new AwsRegionProperties(); } - @Test - public void autoCanBeSet() { - assertThat(this.properties.isAuto()).as("Default value of auto should be true") - .isTrue(); - - this.properties.setAuto(false); - assertThat(this.properties.isAuto()) - .as("Auto should have been reassigned as false").isFalse(); - } - @Test public void staticRegionCanBeSet() { assertThat(this.properties.getStatic()) diff --git a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java index 461dd9e4e..345031b9c 100644 --- a/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java +++ b/spring-cloud-aws-context/src/main/java/org/springframework/cloud/aws/context/config/support/ContextConfigurationUtils.java @@ -18,7 +18,6 @@ import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper; import com.amazonaws.auth.profile.ProfileCredentialsProvider; @@ -88,17 +87,6 @@ else if (StringUtils.hasText(configuredRegion)) { REGION_PROVIDER_BEAN_NAME); } - public static void registerDefaultAWSCredentialsProvider( - BeanDefinitionRegistry registry) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .rootBeanDefinition(DefaultAWSCredentialsProviderChain.class); - registry.registerBeanDefinition( - CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME, - builder.getBeanDefinition()); - AmazonWebserviceClientConfigurationUtils.replaceDefaultCredentialsProvider( - registry, CredentialsProviderFactoryBean.CREDENTIALS_PROVIDER_BEAN_NAME); - } - public static void registerCredentialsProvider(BeanDefinitionRegistry registry, String accessKey, String secretKey, boolean instanceProfile, String profileName, String profilePath) { From 68799fb5f256e4afbd7c9b762aea567d2d236360 Mon Sep 17 00:00:00 2001 From: Darren Forsythe Date: Mon, 8 Jun 2020 22:18:42 +0100 Subject: [PATCH 33/47] Migrate to JUnit 5. Fixes gh-566 Closes gh-587 --- pom.xml | 6 + .../ElastiCacheAutoConfigurationTest.java | 36 ++-- .../cache/TestMemcacheServer.java | 6 +- ...ntextCredentialsAutoConfigurationTest.java | 16 +- ...textInstanceDataAutoConfigurationTest.java | 26 +-- ...xtRegionProviderAutoConfigurationTest.java | 10 +- ...xtResourceLoaderAutoConfigurationTest.java | 14 +- .../ContextStackAutoConfigurationTest.java | 30 +-- .../AwsCredentialsPropertiesTest.java | 20 +- .../properties/AwsRegionPropertiesTest.java | 12 +- .../AwsS3ResourceLoaderPropertiesTest.java | 16 +- ...mazonRdsDatabaseAutoConfigurationTest.java | 30 +-- .../mail/MailSenderAutoConfigurationTest.java | 7 +- ...CloudWatchExportAutoConfigurationTest.java | 14 +- .../metrics/CloudWatchPropertiesTest.java | 8 +- .../aws/cache/ElastiCacheFactoryBeanTest.java | 27 +-- .../ElastiCacheCachingConfigurationTest.java | 44 ++--- .../memcached/MemcachedCacheFactoryTest.java | 8 +- .../memcached/SimpleSpringMemcachedTest.java | 177 +++++++----------- .../cache/redis/RedisCacheFactoryTest.java | 6 +- .../OnAwsCloudEnvironmentConditionTest.java | 20 +- .../OnMissingAmazonClientConditionTest.java | 12 +- ...ceDataPropertySourcePostProcessorTest.java | 8 +- ...CredentialsConfigurationRegistrarTest.java | 46 ++--- .../ContextInstanceDataConfigurationTest.java | 31 ++- ...ntextRegionConfigurationRegistrarTest.java | 70 +++---- ...ontextResourceLoaderConfigurationTest.java | 14 +- .../ContextStackConfigurationTest.java | 18 +- .../xml/GlobalBeanDefinitionUtilsTest.java | 14 +- ...StorageProtocolResolverConfigurerTest.java | 22 +-- .../SimpleEmailServiceJavaMailSenderTest.java | 30 +-- .../SimpleEmailServiceMailSenderTest.java | 14 +- .../config/AmazonTestWebserviceClient.java | 6 +- ...ebserviceClientConfigurationUtilsTest.java | 37 ++-- ...AmazonWebserviceClientFactoryBeanTest.java | 9 +- .../CredentialsProviderFactoryBeanTest.java | 23 +-- ...gistryDetectingResourceIdResolverTest.java | 26 +-- ...azonEc2InstanceDataPropertySourceTest.java | 33 ++-- ...zonEc2InstanceUserTagsFactoryBeanTest.java | 6 +- .../StackResourceRegistryFactoryBeanTest.java | 19 +- .../StackResourceUserTagsFactoryBeanTest.java | 6 +- .../core/io/s3/AmazonS3ClientFactoryTest.java | 46 ++--- .../core/io/s3/AmazonS3ProxyFactoryTest.java | 12 +- ...pleStorageResourcePatternResolverTest.java | 12 +- .../io/s3/SimpleStorageNameUtilsTest.java | 96 +++++----- .../s3/SimpleStorageProtocolResolverTest.java | 16 +- .../core/io/s3/SimpleStorageResourceTest.java | 70 +++---- .../core/naming/AmazonResourceNameTest.java | 59 +++--- .../region/Ec2MetadataRegionProviderTest.java | 27 +-- .../core/region/StaticRegionProviderTest.java | 6 +- .../aws/cache/BootElastiCacheAwsTest.java | 2 +- .../cloud/aws/cache/ElastiCacheAwsTest.java | 14 +- .../aws/cache/JavaElastiCacheAwsTest.java | 2 +- ...BootPathMatchingResourceLoaderAwsTest.java | 2 +- .../support/io/BootResourceLoaderAwsTest.java | 2 +- ...JavaPathMatchingResourceLoaderAwsTest.java | 2 +- .../io/PathMatchingResourceLoaderAwsTest.java | 45 ++--- .../support/io/ResourceLoaderAwsTest.java | 36 ++-- ...nEc2InstanceDataPropertySourceAwsTest.java | 34 ++-- .../AmazonEc2InstanceIdProviderAwsTest.java | 16 +- ...Ec2InstanceUserTagsFactoryBeanAwsTest.java | 32 ++-- ...nEc2InstanceDataPropertySourceAwsTest.java | 2 +- .../stack/BootStackConfigurationAwsTest.java | 2 +- .../stack/JavaStackConfigurationAwsTest.java | 2 +- .../env/stack/StackConfigurationAwsTest.java | 30 +-- .../stack/StackResourceUserTagsAwsTest.java | 16 +- .../BootDataSourceFactoryBeanAwsTest.java | 2 +- .../jdbc/DataSourceFactoryBeanAwsTest.java | 14 +- .../JavaDataSourceFactoryBeanAwsTest.java | 2 +- .../cloud/aws/mail/BootMailSenderAwsTest.java | 2 +- .../cloud/aws/mail/MailSenderAwsTest.java | 14 +- .../aws/messaging/AbstractContainerTest.java | 12 +- .../BootMessageListenerContainerAwsTest.java | 2 +- ...ationMessagingTemplateIntegrationTest.java | 2 +- .../aws/messaging/BootQueueListenerTest.java | 2 +- ...QueueMessagingTemplateIntegrationTest.java | 2 +- .../JavaMessageListenerContainerAwsTest.java | 2 +- ...ationMessagingTemplateIntegrationTest.java | 2 +- .../aws/messaging/JavaQueueListenerTest.java | 2 +- ...QueueMessagingTemplateIntegrationTest.java | 2 +- .../MessageListenerContainerAwsTest.java | 20 +- ...ationMessagingTemplateIntegrationTest.java | 22 +-- .../aws/messaging/QueueListenerTest.java | 28 +-- ...QueueMessagingTemplateIntegrationTest.java | 20 +- .../AmazonRdsInstanceConfigurationTest.java | 48 ++--- .../ReadOnlyRoutingDataSourceTest.java | 12 +- .../TomcatJdbcDataSourceFactoryTest.java | 16 +- .../MapBasedDatabasePlatformSupportTest.java | 46 +++-- .../AmazonRdsDataSourceFactoryBeanTest.java | 30 ++- ...nRdsDataSourceUserTagsFactoryBeanTest.java | 10 +- ...ReplicaAwareDataSourceFactoryBeanTest.java | 8 +- ...DatabaseInstanceStatusRetryPolicyTest.java | 30 ++- .../RdbmsRetryOperationsInterceptorTest.java | 24 +-- .../aws/jdbc/retry/SqlRetryPolicyTest.java | 12 +- .../annotation/SnsConfigurationTest.java | 28 ++- .../annotation/SqsConfigurationTest.java | 86 ++++----- .../NotificationMessagingTemplateTest.java | 12 +- .../core/QueueMessageChannelTest.java | 101 +++++----- .../core/QueueMessagingTemplateTest.java | 46 ++--- .../core/TopicMessageChannelTest.java | 20 +- ...geChannelMessagingSendingTemplateTest.java | 32 ++-- ...sageHandlerMethodArgumentResolverTest.java | 8 +- ...lexNotificationEndpointControllerTest.java | 22 +-- .../ComplexNotificationTestController.java | 18 +- .../NotificationEndpointControllerTest.java | 22 +-- ...sageHandlerMethodArgumentResolverTest.java | 30 ++- ...atusHandlerMethodArgumentResolverTest.java | 26 +-- ...jectHandlerMethodArgumentResolverTest.java | 30 ++- .../endpoint/NotificationTestController.java | 8 +- ...MethodArgumentResolverFactoryBeanTest.java | 29 ++- .../MessageListenerContainerTest.java | 68 +++---- .../listener/QueueMessageHandlerTest.java | 71 ++++--- ...ToHandlerMethodReturnValueHandlerTest.java | 49 +++-- .../SimpleMessageListenerContainerTest.java | 114 ++++++----- ...mentHandlerMethodArgumentResolverTest.java | 23 +-- ...lityHandlerMethodArgumentResolverTest.java | 23 +-- ...tificationMessageArgumentResolverTest.java | 13 +- ...tificationSubjectArgumentResolverTest.java | 14 +- .../NotificationRequestConverterTest.java | 89 +++++---- .../converter/ObjectMessageConverterTest.java | 44 ++--- ...ynamicQueueUrlDestinationResolverTest.java | 26 +-- .../DynamicTopicDestinationResolverTest.java | 43 ++--- .../AwsParamStorePropertySourceTest.java | 6 +- ...cretsManagerPropertySourceLocatorTest.java | 8 +- .../AwsSecretsManagerPropertySourceTest.java | 6 +- 125 files changed, 1417 insertions(+), 1646 deletions(-) diff --git a/pom.xml b/pom.xml index c27159ee5..3098273c5 100644 --- a/pom.xml +++ b/pom.xml @@ -113,6 +113,12 @@ org.springframework.boot spring-boot-starter-test test + + + junit + junit + + junit diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/ElastiCacheAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/ElastiCacheAutoConfigurationTest.java index 0ca52d251..1370f59ab 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/ElastiCacheAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/ElastiCacheAutoConfigurationTest.java @@ -26,10 +26,10 @@ import com.amazonaws.services.elasticache.model.Endpoint; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cache.CacheManager; @@ -45,22 +45,22 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ElastiCacheAutoConfigurationTest { +class ElastiCacheAutoConfigurationTest { private AnnotationConfigApplicationContext context; - @AfterClass - public static void shutDownHttpServer() { + @AfterAll + static void shutDownHttpServer() { MetaDataServer.shutdownHttpServer(); } - @AfterClass - public static void shutdownCacheServer() throws Exception { + @AfterAll + static void shutdownCacheServer() throws Exception { TestMemcacheServer.stopServer(); } - @Before - public void restContextInstanceDataCondition() throws IllegalAccessException { + @BeforeEach + void restContextInstanceDataCondition() throws IllegalAccessException { Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.class, "isCloudEnvironment"); assertThat(field).isNotNull(); @@ -68,13 +68,13 @@ public void restContextInstanceDataCondition() throws IllegalAccessException { field.set(null, null); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { this.context.close(); } @Test - public void cacheManager_configuredMultipleCachesWithStack_configuresCacheManager() + void cacheManager_configuredMultipleCachesWithStack_configuresCacheManager() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -102,7 +102,7 @@ public void cacheManager_configuredMultipleCachesWithStack_configuresCacheManage } @Test - public void cacheManager_configuredNoCachesWithNoStack_configuresNoCacheManager() + void cacheManager_configuredNoCachesWithNoStack_configuresNoCacheManager() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -125,10 +125,10 @@ public void cacheManager_configuredNoCachesWithNoStack_configuresNoCacheManager( } @Configuration(proxyBeanMethods = false) - public static class MockCacheConfigurationWithStackCaches { + static class MockCacheConfigurationWithStackCaches { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest sampleCacheOneLogical = new DescribeCacheClustersRequest() @@ -166,7 +166,7 @@ public AmazonElastiCache amazonElastiCache() { } @Bean - public ListableStackResourceFactory stackResourceFactory() { + ListableStackResourceFactory stackResourceFactory() { ListableStackResourceFactory resourceFactory = Mockito .mock(ListableStackResourceFactory.class); Mockito.when( diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/TestMemcacheServer.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/TestMemcacheServer.java index d34df135e..1dce2bcd8 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/TestMemcacheServer.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/cache/TestMemcacheServer.java @@ -34,7 +34,7 @@ // Suppression as this is not a util class // @checkstyle:off @SuppressWarnings({ "UtilityClassWithoutPrivateConstructor", "NonFinalUtilityClass" }) -public class TestMemcacheServer { +class TestMemcacheServer { // @checkstyle:on @@ -44,7 +44,7 @@ public class TestMemcacheServer { @SuppressWarnings("StaticNonFinalField") private static int portForInstance; - public static int startServer() { + static int startServer() { if (daemon == null) { System.setProperty("net.spy.log.LoggerImpl", SLF4JLogger.class.getName()); @@ -64,7 +64,7 @@ public static int startServer() { return portForInstance; } - public static void stopServer() { + static void stopServer() { try { daemon.stop(); daemon = null; diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java index 1add3cbab..b1d1ed1d2 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextCredentialsAutoConfigurationTest.java @@ -26,7 +26,7 @@ import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import org.apache.http.client.CredentialsProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -42,7 +42,7 @@ * @author Agim Emruli * @author Maciej Walkowiak */ -public class ContextCredentialsAutoConfigurationTest { +class ContextCredentialsAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( @@ -50,7 +50,7 @@ public class ContextCredentialsAutoConfigurationTest { // @checkstyle:off @Test - public void credentialsProvider_noExplicitCredentialsProviderConfigured_configuresDefaultAwsCredentialsProviderChain() { + void credentialsProvider_noExplicitCredentialsProviderConfigured_configuresDefaultAwsCredentialsProviderChain() { // @checkstyle:on this.contextRunner.run((context) -> { AWSCredentialsProvider awsCredentialsProvider = context.getBean( @@ -63,7 +63,7 @@ public void credentialsProvider_noExplicitCredentialsProviderConfigured_configur } @Test - public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { + void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider() { this.contextRunner .withPropertyValues( "cloud.aws.credentials.use-default-aws-credentials-chain:true") @@ -80,7 +80,7 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr // @checkstyle:off @Test - public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { + void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() { // @checkstyle:on this.contextRunner.withPropertyValues( "cloud.aws.credentials.use-default-aws-credentials-chain:false", @@ -105,7 +105,7 @@ public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStatic } @Test - public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { + void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() { this.contextRunner.withPropertyValues( "cloud.aws.credentials.use-default-aws-credentials-chain:false", "cloud.aws.credentials.instance-profile:true").run((context) -> { @@ -123,7 +123,7 @@ public void credentialsProvider_instanceProfileConfigured_configuresInstanceProf } @Test - public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() { + void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() { this.contextRunner.withPropertyValues( "cloud.aws.credentials.use-default-aws-credentials-chain:false", "cloud.aws.credentials.profile-name:test").run((context) -> { @@ -143,7 +143,7 @@ public void credentialsProvider_profileNameConfigured_configuresProfileCredentia } @Test - public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() + void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() throws IOException { this.contextRunner .withPropertyValues( diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextInstanceDataAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextInstanceDataAutoConfigurationTest.java index c79ea5f8d..1c10537f7 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextInstanceDataAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextInstanceDataAutoConfigurationTest.java @@ -20,9 +20,9 @@ import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils; @@ -34,12 +34,12 @@ /** * @author Agim Emruli */ -public class ContextInstanceDataAutoConfigurationTest { +class ContextInstanceDataAutoConfigurationTest { private AnnotationConfigApplicationContext context; - @Before - public void restContextInstanceDataCondition() throws IllegalAccessException { + @BeforeEach + void restContextInstanceDataCondition() throws IllegalAccessException { Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.class, "isCloudEnvironment"); assertThat(field).isNotNull(); @@ -47,15 +47,15 @@ public void restContextInstanceDataCondition() throws IllegalAccessException { field.set(null, null); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void placeHolder_noExplicitConfiguration_createInstanceDataResolverForAwsEnvironment() + void placeHolder_noExplicitConfiguration_createInstanceDataResolverForAwsEnvironment() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -78,7 +78,7 @@ public void placeHolder_noExplicitConfiguration_createInstanceDataResolverForAws } @Test - public void placeHolder_noExplicitConfiguration_missingInstanceDataResolverForNotAwsEnvironment() + void placeHolder_noExplicitConfiguration_missingInstanceDataResolverForNotAwsEnvironment() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -101,7 +101,7 @@ public void placeHolder_noExplicitConfiguration_missingInstanceDataResolverForNo } @Test - public void placeHolder_noExplicitConfiguration_createInstanceDataResolverThatResolvesWithDefaultAttributes() + void placeHolder_noExplicitConfiguration_createInstanceDataResolverThatResolvesWithDefaultAttributes() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -126,7 +126,7 @@ public void placeHolder_noExplicitConfiguration_createInstanceDataResolverThatRe } @Test - public void placeHolder_customValueSeparator_createInstanceDataResolverThatResolvesWithCustomValueSeparator() + void placeHolder_customValueSeparator_createInstanceDataResolverThatResolvesWithCustomValueSeparator() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); @@ -155,7 +155,7 @@ public void placeHolder_customValueSeparator_createInstanceDataResolverThatResol } @Test - public void placeHolder_customAttributeSeparator_createInstanceDataResolverThatResolvesWithCustomAttribute() + void placeHolder_customAttributeSeparator_createInstanceDataResolverThatResolvesWithCustomAttribute() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java index 55c36c2e3..68d2dbcce 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextRegionProviderAutoConfigurationTest.java @@ -18,7 +18,7 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -34,14 +34,14 @@ * @author Petromir Dzhunev * @author Maciej Walkowiak */ -public class ContextRegionProviderAutoConfigurationTest { +class ContextRegionProviderAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of(ContextRegionProviderAutoConfiguration.class)); @Test - public void autoDetectionConfigured_noConfigurationProvided_DefaultAwsRegionProviderChainDelegateConfigured() { + void autoDetectionConfigured_noConfigurationProvided_DefaultAwsRegionProviderChainDelegateConfigured() { this.contextRunner.run((context) -> { assertThat(context.getBean(DefaultAwsRegionProviderChainDelegate.class)) .isNotNull(); @@ -49,7 +49,7 @@ public void autoDetectionConfigured_noConfigurationProvided_DefaultAwsRegionProv } @Test - public void autoDetectionConfigured_emptyStaticRegionConfigured_DefaultAwsRegionProviderChainDelegateConfigured() { + void autoDetectionConfigured_emptyStaticRegionConfigured_DefaultAwsRegionProviderChainDelegateConfigured() { this.contextRunner.withPropertyValues("cloud.aws.region.static:") .run((context) -> { assertThat( @@ -59,7 +59,7 @@ public void autoDetectionConfigured_emptyStaticRegionConfigured_DefaultAwsRegion } @Test - public void staticRegionConfigured_staticRegionProviderWithConfiguredRegionConfigured() { + void staticRegionConfigured_staticRegionProviderWithConfiguredRegionConfigured() { this.contextRunner.withPropertyValues("cloud.aws.region.static:eu-west-1") .run((context) -> { StaticRegionProvider regionProvider = context diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextResourceLoaderAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextResourceLoaderAutoConfigurationTest.java index 1a7b48afc..7b6c5cbcf 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextResourceLoaderAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextResourceLoaderAutoConfigurationTest.java @@ -16,8 +16,8 @@ package org.springframework.cloud.aws.autoconfigure.context; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver; @@ -28,19 +28,19 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ContextResourceLoaderAutoConfigurationTest { +class ContextResourceLoaderAutoConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() { + @AfterEach + void tearDown() { if (this.context != null) { this.context.close(); } } @Test - public void createResourceLoader_withCustomTaskExecutorSettings_executorConfigured() { + void createResourceLoader_withCustomTaskExecutorSettings_executorConfigured() { // Arrange this.context = new AnnotationConfigApplicationContext(); this.context.register(ContextResourceLoaderAutoConfiguration.class); @@ -66,7 +66,7 @@ public void createResourceLoader_withCustomTaskExecutorSettings_executorConfigur } @Test - public void createResourceLoader_withoutExecutorSettings_executorConfigured() { + void createResourceLoader_withoutExecutorSettings_executorConfigured() { // Arrange this.context = new AnnotationConfigApplicationContext(); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java index f326f0ae2..cae0aeb6f 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfigurationTest.java @@ -27,9 +27,9 @@ import com.amazonaws.services.cloudformation.model.StackResource; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -47,12 +47,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class ContextStackAutoConfigurationTest { +class ContextStackAutoConfigurationTest { private AnnotationConfigApplicationContext context; - @Before - public void restContextInstanceDataCondition() throws IllegalAccessException { + @BeforeEach + void restContextInstanceDataCondition() throws IllegalAccessException { Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.class, "isCloudEnvironment"); assertThat(field).isNotNull(); @@ -60,15 +60,15 @@ public void restContextInstanceDataCondition() throws IllegalAccessException { field.set(null, null); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void stackRegistry_autoConfigurationEnabled_returnsAutoConfiguredStackRegistry() + void stackRegistry_autoConfigurationEnabled_returnsAutoConfiguredStackRegistry() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -90,7 +90,7 @@ public void stackRegistry_autoConfigurationEnabled_returnsAutoConfiguredStackReg } @Test - public void stackRegistry_manualConfigurationEnabled_returnsAutoConfiguredStackRegistry() + void stackRegistry_manualConfigurationEnabled_returnsAutoConfiguredStackRegistry() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -108,7 +108,7 @@ public void stackRegistry_manualConfigurationEnabled_returnsAutoConfiguredStackR } @Test - public void stackRegistry_manualConfigurationEnabledAndStackNameProvided_returnsStaticStackNameProvider() + void stackRegistry_manualConfigurationEnabledAndStackNameProvided_returnsStaticStackNameProvider() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -129,7 +129,7 @@ public void stackRegistry_manualConfigurationEnabledAndStackNameProvided_returns } @Test - public void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfiguredBean() + void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfiguredBean() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -145,7 +145,7 @@ public void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfigure } @Test - public void stackResourceRegistryFactoryBean_isNotCreatedWhenStackNameAbsentAndStackAutoFalse() { + void stackResourceRegistryFactoryBean_isNotCreatedWhenStackNameAbsentAndStackAutoFalse() { // Arrange this.context = new AnnotationConfigApplicationContext(); this.context.register(ContextStackAutoConfiguration.class); @@ -162,7 +162,7 @@ public void stackResourceRegistryFactoryBean_isNotCreatedWhenStackNameAbsentAndS static class AutoConfigurationStackRegistryTestConfiguration { @Bean - public AmazonCloudFormation amazonCloudFormation() { + AmazonCloudFormation amazonCloudFormation() { AmazonCloudFormation amazonCloudFormation = Mockito .mock(AmazonCloudFormation.class); Mockito.when(amazonCloudFormation.describeStackResources( @@ -182,7 +182,7 @@ public AmazonCloudFormation amazonCloudFormation() { static class ManualConfigurationStackRegistryTestConfiguration { @Bean - public AmazonCloudFormation amazonCloudFormation() { + AmazonCloudFormation amazonCloudFormation() { AmazonCloudFormation amazonCloudFormation = Mockito .mock(AmazonCloudFormation.class); Mockito.when(amazonCloudFormation.listStackResources( diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java index 628524720..5777d9e2c 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsCredentialsPropertiesTest.java @@ -18,8 +18,8 @@ import java.util.UUID; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -30,17 +30,17 @@ * @author Maciej Walkowiak * @since 2.0.2 */ -public class AwsCredentialsPropertiesTest { +class AwsCredentialsPropertiesTest { private AwsCredentialsProperties properties; - @Before - public void setup() { + @BeforeEach + void setup() { this.properties = new AwsCredentialsProperties(); } @Test - public void accessKeyCanBeSet() { + void accessKeyCanBeSet() { assertThat(this.properties.getAccessKey()) .as("Access key default value expected to be null").isNull(); @@ -51,7 +51,7 @@ public void accessKeyCanBeSet() { } @Test - public void secretKeyCanBeSet() { + void secretKeyCanBeSet() { assertThat(this.properties.getSecretKey()) .as("Secret key default value expected to be null").isNull(); @@ -62,7 +62,7 @@ public void secretKeyCanBeSet() { } @Test - public void instanceProfileCanBeSet() { + void instanceProfileCanBeSet() { assertThat(this.properties.isInstanceProfile()) .as("Instance profile default expected to be false").isFalse(); @@ -72,7 +72,7 @@ public void instanceProfileCanBeSet() { } @Test - public void profileNameCanBeSet() { + void profileNameCanBeSet() { assertThat(this.properties.getProfileName()) .as("Default profile name is not expected to be set").isEqualTo(null); @@ -83,7 +83,7 @@ public void profileNameCanBeSet() { } @Test - public void profilePathCanBeSet() { + void profilePathCanBeSet() { assertThat(this.properties.getProfilePath()) .as("Profile path default value expected to be null").isNull(); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java index 75b2a858b..1e17f169b 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsRegionPropertiesTest.java @@ -17,8 +17,8 @@ package org.springframework.cloud.aws.autoconfigure.context.properties; import com.amazonaws.regions.Regions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -28,17 +28,17 @@ * @author Tom Gianos * @since 2.0.2 */ -public class AwsRegionPropertiesTest { +class AwsRegionPropertiesTest { private AwsRegionProperties properties; - @Before - public void setup() { + @BeforeEach + void setup() { this.properties = new AwsRegionProperties(); } @Test - public void staticRegionCanBeSet() { + void staticRegionCanBeSet() { assertThat(this.properties.getStatic()) .as("Static region value should have default of null").isNull(); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsS3ResourceLoaderPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsS3ResourceLoaderPropertiesTest.java index f6fd963f7..c98541be2 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsS3ResourceLoaderPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/context/properties/AwsS3ResourceLoaderPropertiesTest.java @@ -16,8 +16,8 @@ package org.springframework.cloud.aws.autoconfigure.context.properties; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -27,17 +27,17 @@ * @author Tom Gianos * @since 2.0.2 */ -public class AwsS3ResourceLoaderPropertiesTest { +class AwsS3ResourceLoaderPropertiesTest { private AwsS3ResourceLoaderProperties properties; - @Before - public void setup() { + @BeforeEach + void setup() { this.properties = new AwsS3ResourceLoaderProperties(); } @Test - public void corePoolSizeCanBeSet() { + void corePoolSizeCanBeSet() { assertThat(this.properties.getCorePoolSize()) .as("Default value of the core size should be one").isEqualTo(1); @@ -48,7 +48,7 @@ public void corePoolSizeCanBeSet() { } @Test - public void maxPoolSizeCanBeSet() { + void maxPoolSizeCanBeSet() { assertThat(this.properties.getMaxPoolSize()) .as("Default value of the max pool size should be integer max value") .isEqualTo(Integer.MAX_VALUE); @@ -60,7 +60,7 @@ public void maxPoolSizeCanBeSet() { } @Test - public void queueCapacityCanBeSet() { + void queueCapacityCanBeSet() { assertThat(this.properties.getQueueCapacity()).as( "Default value of the queue capacity size should be integer max value") .isEqualTo(Integer.MAX_VALUE); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/jdbc/AmazonRdsDatabaseAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/jdbc/AmazonRdsDatabaseAutoConfigurationTest.java index d05fe16b9..05aee9573 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/jdbc/AmazonRdsDatabaseAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/jdbc/AmazonRdsDatabaseAutoConfigurationTest.java @@ -24,8 +24,8 @@ import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; import com.amazonaws.services.rds.model.DescribeDBInstancesResult; import com.amazonaws.services.rds.model.Endpoint; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.boot.test.util.TestPropertyValues; @@ -37,19 +37,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -public class AmazonRdsDatabaseAutoConfigurationTest { +class AmazonRdsDatabaseAutoConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresFactoryBeanWithoutReadReplica() + void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresFactoryBeanWithoutReadReplica() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -67,7 +67,7 @@ public void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresF } @Test - public void configureBean_withCustomDataBaseName_configuresFactoryBeanWithCustomDatabaseName() + void configureBean_withCustomDataBaseName_configuresFactoryBeanWithCustomDatabaseName() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -91,7 +91,7 @@ public void configureBean_withCustomDataBaseName_configuresFactoryBeanWithCustom } @Test - public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaAndMultipleDatabases_configuresBothDatabases() + void configureBean_withDefaultClientSpecifiedAndNoReadReplicaAndMultipleDatabases_configuresBothDatabases() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -117,7 +117,7 @@ public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaAndMultipleD } @Test - public void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFactoryBeanWithReadReplicaEnabled() + void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFactoryBeanWithReadReplicaEnabled() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -138,10 +138,10 @@ public void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFac .isNotNull(); } - public static class ApplicationConfigurationWithoutReadReplica { + static class ApplicationConfigurationWithoutReadReplica { @Bean - public AmazonRDSClient amazonRDS() { + AmazonRDSClient amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -161,10 +161,10 @@ public AmazonRDSClient amazonRDS() { } - public static class ApplicationConfigurationWithMultipleDatabases { + static class ApplicationConfigurationWithMultipleDatabases { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -193,10 +193,10 @@ public AmazonRDS amazonRDS() { } - public static class ApplicationConfigurationWithReadReplica { + static class ApplicationConfigurationWithReadReplica { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfigurationTest.java index 0a4761e64..f05ff2fb7 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/mail/MailSenderAutoConfigurationTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.aws.autoconfigure.mail; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.mail.MailSender; @@ -24,11 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class MailSenderAutoConfigurationTest { +class MailSenderAutoConfigurationTest { @Test - public void mailSender_MailSenderWithJava_configuresJavaMailSender() - throws Exception { + void mailSender_MailSenderWithJava_configuresJavaMailSender() throws Exception { // Arrange AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(MailSenderAutoConfiguration.class); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfigurationTest.java index b60868102..33506fbae 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchExportAutoConfigurationTest.java @@ -19,8 +19,8 @@ import io.micrometer.cloudwatch.CloudWatchConfig; import io.micrometer.cloudwatch.CloudWatchMeterRegistry; import io.micrometer.core.instrument.Clock; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.mock.env.MockEnvironment; @@ -32,21 +32,21 @@ * * @author Dawid Kublik */ -public class CloudWatchExportAutoConfigurationTest { +class CloudWatchExportAutoConfigurationTest { private MockEnvironment env; private AnnotationConfigApplicationContext context; - @Before - public void before() { + @BeforeEach + void before() { this.env = new MockEnvironment(); this.context = new AnnotationConfigApplicationContext(); this.context.setEnvironment(this.env); } @Test - public void testWithoutSettingAnyConfigProperties() { + void testWithoutSettingAnyConfigProperties() { this.context.register(CloudWatchExportAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBeansOfType(CloudWatchMeterRegistry.class).isEmpty()) @@ -54,7 +54,7 @@ public void testWithoutSettingAnyConfigProperties() { } @Test - public void testConfiguration() throws Exception { + void testConfiguration() throws Exception { this.env.setProperty("management.metrics.export.cloudwatch.namespace", "test"); this.context.register(CloudWatchExportAutoConfiguration.class); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java index c8944214a..90a4d407c 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchPropertiesTest.java @@ -18,7 +18,7 @@ import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -30,10 +30,10 @@ /** * @author Bernardo Martins */ -public class CloudWatchPropertiesTest { +class CloudWatchPropertiesTest { @Test - public void properties_notSet_shouldHaveDefaultValues() { + void properties_notSet_shouldHaveDefaultValues() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( CloudWatchPropertiesConfiguration.class); @@ -44,7 +44,7 @@ public void properties_notSet_shouldHaveDefaultValues() { } @Test - public void properties_set_shouldOverrideValues() { + void properties_set_shouldOverrideValues() { Properties properties = new Properties(); properties.setProperty("management.metrics.export.cloudwatch.namespace", "test"); properties.setProperty("management.metrics.export.cloudwatch.batch-size", "5"); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheFactoryBeanTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheFactoryBeanTest.java index d9f91a3e7..bca5e9cc7 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheFactoryBeanTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheFactoryBeanTest.java @@ -25,25 +25,20 @@ import com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest; import com.amazonaws.services.elasticache.model.DescribeCacheClustersResult; import com.amazonaws.services.elasticache.model.Endpoint; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cache.Cache; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ElastiCacheFactoryBeanTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class ElastiCacheFactoryBeanTest { @Test - public void getObject_availableCluster_returnsConfiguredMemcachedClient() - throws Exception { + void getObject_availableCluster_returnsConfiguredMemcachedClient() throws Exception { // Arrange AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class); @@ -69,7 +64,7 @@ public void getObject_availableCluster_returnsConfiguredMemcachedClient() } @Test - public void getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName() + void getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName() throws Exception { // Arrange AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class); @@ -101,12 +96,8 @@ public void getObject_availableClusterWithLogicalName_returnsConfigurationMemcac } @Test - public void getObject_clusterWithRedisEngineConfigured_reportsError() - throws Exception { + void getObject_clusterWithRedisEngineConfigured_reportsError() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("engine"); - AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class); DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest() .withCacheClusterId("memcached"); @@ -122,10 +113,10 @@ public void getObject_clusterWithRedisEngineConfigured_reportsError() amazonElastiCache, "memcached", Collections.singletonList( new TestCacheFactory("testCache", "localhost", 45678))); - // Act - elastiCacheFactoryBean.afterPropertiesSet(); - // Assert + assertThatThrownBy(elastiCacheFactoryBean::afterPropertiesSet) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("engine"); } private static final class TestCacheFactory implements CacheFactory { diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfigurationTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfigurationTest.java index 06028b9e3..d6fd04135 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfigurationTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/config/annotation/ElastiCacheCachingConfigurationTest.java @@ -24,8 +24,8 @@ import com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest; import com.amazonaws.services.elasticache.model.DescribeCacheClustersResult; import com.amazonaws.services.elasticache.model.Endpoint; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cache.Cache; @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ElastiCacheCachingConfigurationTest { +class ElastiCacheCachingConfigurationTest { private AnnotationConfigApplicationContext context; @@ -54,15 +54,15 @@ private static int getExpirationFromCache(Cache cache) throws IllegalAccessExcep return expiration.getInt(cache); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void enableElasticache_configuredWithExplicitCluster_configuresExplicitlyConfiguredCaches() + void enableElasticache_configuredWithExplicitCluster_configuresExplicitlyConfiguredCaches() throws Exception { // Arrange @@ -85,7 +85,7 @@ public void enableElasticache_configuredWithExplicitCluster_configuresExplicitly // @checkstyle:off @Test - public void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithCustomExpirationTimes() + void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithCustomExpirationTimes() // @checkstyle:on throws Exception { // Arrange @@ -109,7 +109,7 @@ public void enableElasticache_configuredWithExplicitClusterAndExpiration_configu // @checkstyle:off @Test - public void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithMixedExpirationTimes() + void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithMixedExpirationTimes() throws Exception { // @checkstyle:on // Arrange @@ -132,7 +132,7 @@ public void enableElasticache_configuredWithExplicitClusterAndExpiration_configu } @Test - public void enableElasticache_configuredWithoutExplicitCluster_configuresImplicitlyConfiguredCaches() + void enableElasticache_configuredWithoutExplicitCluster_configuresImplicitlyConfiguredCaches() throws Exception { // Arrange @@ -155,7 +155,7 @@ public void enableElasticache_configuredWithoutExplicitCluster_configuresImplici // @checkstyle:off @Test - public void enableElasticache_configuredWithoutExplicitClusterButDefaultExpiryTime_configuresImplicitlyConfiguredCachesWithDefaultExpiryTimeOnAllCaches() + void enableElasticache_configuredWithoutExplicitClusterButDefaultExpiryTime_configuresImplicitlyConfiguredCachesWithDefaultExpiryTimeOnAllCaches() throws Exception { // @checkstyle:on // Arrange @@ -179,10 +179,10 @@ public void enableElasticache_configuredWithoutExplicitClusterButDefaultExpiryTi @EnableElastiCache({ @CacheClusterConfig(name = "firstCache"), @CacheClusterConfig(name = "secondCache") }) - public static class ApplicationConfigurationWithExplicitStackConfiguration { + static class ApplicationConfigurationWithExplicitStackConfiguration { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest describeCacheClustersRequest = new DescribeCacheClustersRequest() @@ -215,10 +215,10 @@ public AmazonElastiCache amazonElastiCache() { @EnableElastiCache({ @CacheClusterConfig(name = "firstCache", expiration = 23), @CacheClusterConfig(name = "secondCache", expiration = 42) }) - public static class ApplicationConfigurationWithExplicitStackConfigurationAndExpiryTime { + static class ApplicationConfigurationWithExplicitStackConfigurationAndExpiryTime { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest firstCache = new DescribeCacheClustersRequest() @@ -248,10 +248,10 @@ public AmazonElastiCache amazonElastiCache() { value = { @CacheClusterConfig(name = "firstCache"), @CacheClusterConfig(name = "secondCache", expiration = 42) }, defaultExpiration = 12) - public static class ApplicationConfigurationWithExplicitStackConfigurationAndMixedExpiryTime { + static class ApplicationConfigurationWithExplicitStackConfigurationAndMixedExpiryTime { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest firstCache = new DescribeCacheClustersRequest() @@ -278,10 +278,10 @@ public AmazonElastiCache amazonElastiCache() { } @EnableElastiCache - public static class ApplicationConfigurationWithNoExplicitStackConfiguration { + static class ApplicationConfigurationWithNoExplicitStackConfiguration { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest sampleCacheOneLogical = new DescribeCacheClustersRequest() @@ -319,7 +319,7 @@ public AmazonElastiCache amazonElastiCache() { } @Bean - public ListableStackResourceFactory stackResourceFactory() { + ListableStackResourceFactory stackResourceFactory() { ListableStackResourceFactory resourceFactory = Mockito .mock(ListableStackResourceFactory.class); Mockito.when( @@ -335,10 +335,10 @@ public ListableStackResourceFactory stackResourceFactory() { } @EnableElastiCache(defaultExpiration = 23) - public static class ApplicationConfigurationWithNoExplicitStackConfigurationAndDefaultExpiration { + static class ApplicationConfigurationWithNoExplicitStackConfigurationAndDefaultExpiration { @Bean - public AmazonElastiCache amazonElastiCache() { + AmazonElastiCache amazonElastiCache() { AmazonElastiCache amazonElastiCache = Mockito.mock(AmazonElastiCache.class); int port = TestMemcacheServer.startServer(); DescribeCacheClustersRequest sampleCacheOneLogical = new DescribeCacheClustersRequest() @@ -376,7 +376,7 @@ public AmazonElastiCache amazonElastiCache() { } @Bean - public ListableStackResourceFactory stackResourceFactory() { + ListableStackResourceFactory stackResourceFactory() { ListableStackResourceFactory resourceFactory = Mockito .mock(ListableStackResourceFactory.class); Mockito.when( diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/MemcachedCacheFactoryTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/MemcachedCacheFactoryTest.java index 0b0013711..3b401232c 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/MemcachedCacheFactoryTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/MemcachedCacheFactoryTest.java @@ -16,16 +16,16 @@ package org.springframework.cloud.aws.cache.memcached; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.cache.config.TestMemcacheServer; import static org.assertj.core.api.Assertions.assertThat; -public class MemcachedCacheFactoryTest { +class MemcachedCacheFactoryTest { @Test - public void createCache_withLocalMemCachedClient_createSimpleSpringMemcached() + void createCache_withLocalMemCachedClient_createSimpleSpringMemcached() throws Exception { // Arrange int memCachedPort = TestMemcacheServer.startServer(); @@ -47,7 +47,7 @@ public void createCache_withLocalMemCachedClient_createSimpleSpringMemcached() } @Test - public void createCache_WithExpiryTime_createSimpleSpringMemcachedWithExpiryTime() + void createCache_WithExpiryTime_createSimpleSpringMemcachedWithExpiryTime() throws Exception { // Arrange int memCachedPort = TestMemcacheServer.startServer(); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/SimpleSpringMemcachedTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/SimpleSpringMemcachedTest.java index f31658fc4..30f0041db 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/SimpleSpringMemcachedTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/memcached/SimpleSpringMemcachedTest.java @@ -17,14 +17,13 @@ package org.springframework.cloud.aws.cache.memcached; import net.spy.memcached.MemcachedClientIF; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cache.Cache; import org.springframework.scheduling.annotation.AsyncResult; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -33,13 +32,10 @@ /** * @author Agim Emruli */ -public class SimpleSpringMemcachedTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class SimpleSpringMemcachedTest { @Test - public void getName_configuredName_configuredNameReturned() throws Exception { + void getName_configuredName_configuredNameReturned() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); @@ -52,38 +48,27 @@ public void getName_configuredName_configuredNameReturned() throws Exception { } @Test - public void simpleSpringMemcached_withoutName_reportsError() throws Exception { + void simpleSpringMemcached_withoutName_reportsError() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("cacheName is mandatory"); - MemcachedClientIF client = mock(MemcachedClientIF.class); - // Act - // noinspection ResultOfObjectAllocationIgnored - new SimpleSpringMemcached(client, null); - // Assert + assertThatThrownBy(() -> new SimpleSpringMemcached(client, null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("cacheName is mandatory"); } @Test - public void simpleSpringMemcached_withoutMemcachedClient_reportsError() - throws Exception { - // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("memcachedClient is mandatory"); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new SimpleSpringMemcached(null, "test"); - + void simpleSpringMemcached_withoutMemcachedClient_reportsError() throws Exception { // Assert - + assertThatThrownBy(() -> new SimpleSpringMemcached(null, "test")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("memcachedClient is mandatory"); } @Test - public void getNativeCache_withConfiguredMemcachedClient_returnsConfiguredMemcachedClient() + void getNativeCache_withConfiguredMemcachedClient_returnsConfiguredMemcachedClient() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -97,7 +82,7 @@ public void getNativeCache_withConfiguredMemcachedClient_returnsConfiguredMemcac } @Test - public void get_withoutTypeParameterAndFoundInstance_returnsValueWrapperWithInstance() + void get_withoutTypeParameterAndFoundInstance_returnsValueWrapperWithInstance() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -113,8 +98,7 @@ public void get_withoutTypeParameterAndFoundInstance_returnsValueWrapperWithInst } @Test - public void get_withoutTypeParameterAndNonFoundInstance_returnsValue() - throws Exception { + void get_withoutTypeParameterAndNonFoundInstance_returnsValue() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); @@ -127,8 +111,7 @@ public void get_withoutTypeParameterAndNonFoundInstance_returnsValue() } @Test - public void get_withTypeParameterAndFoundInstance_returnsConvertedValue() - throws Exception { + void get_withTypeParameterAndFoundInstance_returnsConvertedValue() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); @@ -143,7 +126,7 @@ public void get_withTypeParameterAndFoundInstance_returnsConvertedValue() } @Test - public void get_withTypeParameterAndNonFoundInstance_returnsValue() throws Exception { + void get_withTypeParameterAndNonFoundInstance_returnsValue() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); @@ -156,97 +139,79 @@ public void get_withTypeParameterAndNonFoundInstance_returnsValue() throws Excep } @Test - public void get_withTypeParameterAndNonCompatibleInstance_reportsIllegalArgumentException() + void get_withTypeParameterAndNonCompatibleInstance_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "java.lang.Long is not assignable to class java.lang.String"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); when(client.get("test")).thenReturn(23L); - // Act - cache.get("test", String.class); - // Assert + assertThatThrownBy(() -> cache.get("test", String.class)) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "java.lang.Long is not assignable to class java.lang.String"); } @Test - public void get_withoutTypeParameterAndNonCompatibleCacheKey_reportsIllegalArgumentException() + void get_withoutTypeParameterAndNonCompatibleCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "java.lang.Long is not assignable to class java.lang.String"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.get(23L); - // Assert + assertThatThrownBy(() -> cache.get(23L)) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "java.lang.Long is not assignable to class java.lang.String"); } @Test - public void get_withTypeParameterAndNonCompatibleCacheKey_reportsIllegalArgumentException() + void get_withTypeParameterAndNonCompatibleCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "java.lang.Long is not assignable to class java.lang.String"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.get(23L, Object.class); - // Assert + assertThatThrownBy(() -> cache.get(23L, Object.class)) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "java.lang.Long is not assignable to class java.lang.String"); } @Test - public void get_withoutTypeParameterAndNullCacheKey_reportsIllegalArgumentException() + void get_withoutTypeParameterAndNullCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("key parameter is mandatory"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.get(null); - // Assert + assertThatThrownBy(() -> cache.get(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("key parameter is mandatory"); } @Test - public void get_withTypeParameterAndNullCacheKey_reportsIllegalArgumentException() + void get_withTypeParameterAndNullCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("key parameter is mandatory"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.get(null, Object.class); - // Assert + assertThatThrownBy(() -> cache.get(null, Object.class)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("key parameter is mandatory"); } @Test - public void get_witValueLoaderAndNonExistingValue_createsValueFromValueLoaderAndStoresItInCache() + void get_witValueLoaderAndNonExistingValue_createsValueFromValueLoaderAndStoresItInCache() throws Exception { // Arrange @@ -264,8 +229,7 @@ public void get_witValueLoaderAndNonExistingValue_createsValueFromValueLoaderAnd } @Test - public void get_witValueLoaderAndExistingValue_doesNotCallValueLoader() - throws Exception { + void get_witValueLoaderAndExistingValue_doesNotCallValueLoader() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -283,41 +247,33 @@ public void get_witValueLoaderAndExistingValue_doesNotCallValueLoader() } @Test - public void put_nullCacheKey_reportsIllegalArgumentException() throws Exception { + void put_nullCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("key parameter is mandatory"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.put(null, "test"); - // Assert + assertThatThrownBy(() -> cache.put(null, "test")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("key parameter is mandatory"); } @Test - public void put_longCacheKey_reportsIllegalArgumentException() throws Exception { + void put_longCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "java.lang.Long is not assignable to class java.lang.String"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.put(23L, "test"); - // Assert + assertThatThrownBy(() -> cache.put(23L, "test")) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "java.lang.Long is not assignable to class java.lang.String"); } @Test - public void put_nullCacheValueWithDefaultExpiration_keyStoredInCache() - throws Exception { + void put_nullCacheValueWithDefaultExpiration_keyStoredInCache() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -332,7 +288,7 @@ public void put_nullCacheValueWithDefaultExpiration_keyStoredInCache() } @Test - public void put_withDefaultExpiration_keyStoredInCache() throws Exception { + void put_withDefaultExpiration_keyStoredInCache() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -347,7 +303,7 @@ public void put_withDefaultExpiration_keyStoredInCache() throws Exception { } @Test - public void put_withCustomExpiration_keyStoredInCache() throws Exception { + void put_withCustomExpiration_keyStoredInCache() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -363,40 +319,34 @@ public void put_withCustomExpiration_keyStoredInCache() throws Exception { } @Test - public void evict_nullCacheKey_reportsIllegalArgumentException() throws Exception { + void evict_nullCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("key parameter is mandatory"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.evict(null); - // Assert + assertThatThrownBy(() -> cache.evict(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("key parameter is mandatory"); } @Test - public void evict_longCacheKey_reportsIllegalArgumentException() throws Exception { + void evict_longCacheKey_reportsIllegalArgumentException() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "java.lang.Long is not assignable to class java.lang.String"); - MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); - // Act - cache.evict(23L); - // Assert + assertThatThrownBy(() -> cache.evict(23L)) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "java.lang.Long is not assignable to class java.lang.String"); + } @Test - public void evict_withCacheKey_deletedObjectInCache() throws Exception { + void evict_withCacheKey_deletedObjectInCache() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -411,7 +361,7 @@ public void evict_withCacheKey_deletedObjectInCache() throws Exception { } @Test - public void clear_withDefaultSettings_flushesCache() throws Exception { + void clear_withDefaultSettings_flushesCache() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); @@ -425,8 +375,7 @@ public void clear_withDefaultSettings_flushesCache() throws Exception { } @Test - public void putIfAbsent_withNewValue_shouldPutTheNewValueAndReturnNull() - throws Exception { + void putIfAbsent_withNewValue_shouldPutTheNewValueAndReturnNull() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); @@ -440,7 +389,7 @@ public void putIfAbsent_withNewValue_shouldPutTheNewValueAndReturnNull() } @Test - public void putIfAbsent_withExistingValue_shouldNotPutTheValueAndReturnTheExistingOne() + void putIfAbsent_withExistingValue_shouldNotPutTheValueAndReturnTheExistingOne() throws Exception { // Arrange MemcachedClientIF client = mock(MemcachedClientIF.class); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/redis/RedisCacheFactoryTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/redis/RedisCacheFactoryTest.java index 9943f0fd1..462bbf54d 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/redis/RedisCacheFactoryTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/cache/redis/RedisCacheFactoryTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.aws.cache.redis; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.DisposableBean; @@ -25,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class RedisCacheFactoryTest { +class RedisCacheFactoryTest { @Test - public void createCache_withMockedRedisConnectionFactory_createsAndDestroysConnectionFactory() + void createCache_withMockedRedisConnectionFactory_createsAndDestroysConnectionFactory() throws Exception { // Arrange RedisConnectionFactory connectionFactory = Mockito.mock( diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java index 91e7c9812..38f4e1506 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnAwsCloudEnvironmentConditionTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.aws.context.annotation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -27,10 +27,10 @@ /** * @author Bernardo Martins */ -public class OnAwsCloudEnvironmentConditionTest { +class OnAwsCloudEnvironmentConditionTest { @Test - public void condition_methodAnnotation_shouldNotCreateBeanFoo() { + void condition_methodAnnotation_shouldNotCreateBeanFoo() { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithConditionalOnAwsCloudEnvironmentAnnotatedBean.class); @@ -40,7 +40,7 @@ public void condition_methodAnnotation_shouldNotCreateBeanFoo() { } @Test - public void condition_typeAnnotation_shouldNotCreateBeanFoo() { + void condition_typeAnnotation_shouldNotCreateBeanFoo() { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithConditionalOnAwsCloudEnvironmentAnnotation.class); @@ -50,7 +50,7 @@ public void condition_typeAnnotation_shouldNotCreateBeanFoo() { } @Test - public void condition_methodAnnotation_shouldCreateBeanFoo() { + void condition_methodAnnotation_shouldCreateBeanFoo() { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotatedBean.class); @@ -60,7 +60,7 @@ public void condition_methodAnnotation_shouldCreateBeanFoo() { } @Test - public void condition_typeAnnotation_shouldCreateBeanFoo() { + void condition_typeAnnotation_shouldCreateBeanFoo() { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotation.class); @@ -74,7 +74,7 @@ protected static class ConfigWithConditionalOnAwsCloudEnvironmentAnnotatedBean { @Bean @ConditionalOnAwsCloudEnvironment - public String foo() { + String foo() { return "foo"; } @@ -85,7 +85,7 @@ public String foo() { protected static class ConfigWithConditionalOnAwsCloudEnvironmentAnnotation { @Bean - public String foo() { + String foo() { return "foo"; } @@ -96,7 +96,7 @@ protected static class ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotate @Bean @ConditionalOnMissingAwsCloudEnvironment - public String foo() { + String foo() { return "foo"; } @@ -107,7 +107,7 @@ public String foo() { protected static class ConfigWithConditionalOnMissingAwsCloudEnvironmentAnnotation { @Bean - public String foo() { + String foo() { return "foo"; } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnMissingAmazonClientConditionTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnMissingAmazonClientConditionTest.java index 0c8d55fdb..c37452fcd 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnMissingAmazonClientConditionTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/annotation/OnMissingAmazonClientConditionTest.java @@ -17,7 +17,7 @@ package org.springframework.cloud.aws.context.annotation; import com.amazonaws.services.s3.AmazonS3; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -29,10 +29,10 @@ /** * @author Alain Sahli */ -public class OnMissingAmazonClientConditionTest { +class OnMissingAmazonClientConditionTest { @Test - public void condition_withMatchingCase_shouldCreateBeanFoo() throws Exception { + void condition_withMatchingCase_shouldCreateBeanFoo() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithMissingAmazonClientCondition.class); @@ -42,7 +42,7 @@ public void condition_withMatchingCase_shouldCreateBeanFoo() throws Exception { } @Test - public void condition_withNonMatchingCase_shouldNotCreateBeanFoo() throws Exception { + void condition_withNonMatchingCase_shouldNotCreateBeanFoo() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigWithDummyS3Client.class, @@ -56,7 +56,7 @@ public void condition_withNonMatchingCase_shouldNotCreateBeanFoo() throws Except protected static class ConfigWithDummyS3Client { @Bean - public AmazonS3 amazonS3() { + AmazonS3 amazonS3() { return mock(AmazonS3.class); } @@ -67,7 +67,7 @@ protected static class ConfigWithMissingAmazonClientCondition { @Bean @ConditionalOnMissingAmazonClient(AmazonS3.class) - public String foo() { + String foo() { return "foo"; } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/AmazonEc2InstanceDataPropertySourcePostProcessorTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/AmazonEc2InstanceDataPropertySourcePostProcessorTest.java index fbfd03dcd..174b7cf35 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/AmazonEc2InstanceDataPropertySourcePostProcessorTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/AmazonEc2InstanceDataPropertySourcePostProcessorTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.aws.context.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -29,10 +29,10 @@ /** * @author Agim Emruli */ -public class AmazonEc2InstanceDataPropertySourcePostProcessorTest { +class AmazonEc2InstanceDataPropertySourcePostProcessorTest { @Test - public void postProcessBeanFactory_withConfigurableEnvironment_registersPropertySource() + void postProcessBeanFactory_withConfigurableEnvironment_registersPropertySource() throws Exception { // Arrange StaticApplicationContext staticApplicationContext = new StaticApplicationContext(); @@ -49,7 +49,7 @@ public void postProcessBeanFactory_withConfigurableEnvironment_registersProperty } @Test - public void postProcessBeanFactory_withNonConfigurableEnvironment_skipsRegistration() + void postProcessBeanFactory_withNonConfigurableEnvironment_skipsRegistration() throws Exception { // Arrange ConfigurableListableBeanFactory staticApplicationContext = new DefaultListableBeanFactory(); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextCredentialsConfigurationRegistrarTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextCredentialsConfigurationRegistrarTest.java index a8d087eeb..707a4285d 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextCredentialsConfigurationRegistrarTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextCredentialsConfigurationRegistrarTest.java @@ -26,8 +26,8 @@ import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import org.apache.http.client.CredentialsProvider; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -37,19 +37,19 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ContextCredentialsConfigurationRegistrarTest { +class ContextCredentialsConfigurationRegistrarTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void credentialsProvider_defaultCredentialsProviderWithoutFurtherConfig_awsCredentialsProviderConfigured() + void credentialsProvider_defaultCredentialsProviderWithoutFurtherConfig_awsCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -66,7 +66,7 @@ public void credentialsProvider_defaultCredentialsProviderWithoutFurtherConfig_a } @Test - public void credentialsProvider_configWithAccessAndSecretKey_staticAwsCredentialsProviderConfigured() + void credentialsProvider_configWithAccessAndSecretKey_staticAwsCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -94,7 +94,7 @@ public void credentialsProvider_configWithAccessAndSecretKey_staticAwsCredential // @checkstyle:off @Test - public void credentialsProvider_configWithAccessAndSecretKeyAsExpressions_staticAwsCredentialsProviderConfiguredWithResolvedExpressions() + void credentialsProvider_configWithAccessAndSecretKeyAsExpressions_staticAwsCredentialsProviderConfiguredWithResolvedExpressions() throws Exception { // @checkstyle:on // Arrange @@ -132,7 +132,7 @@ public void credentialsProvider_configWithAccessAndSecretKeyAsExpressions_static // @checkstyle:off @Test - public void credentialsProvider_configWithAccessAndSecretKeyAsPlaceHolders_staticAwsCredentialsProviderConfiguredWithResolvedPlaceHolders() + void credentialsProvider_configWithAccessAndSecretKeyAsPlaceHolders_staticAwsCredentialsProviderConfiguredWithResolvedPlaceHolders() throws Exception { // @checkstyle:on // Arrange @@ -173,7 +173,7 @@ public void credentialsProvider_configWithAccessAndSecretKeyAsPlaceHolders_stati // @checkstyle:off @Test - public void credentialsProvider_configWithAccessAndSecretKeyAndInstanceProfile_staticAwsCredentialsProviderConfiguredWithInstanceProfile() + void credentialsProvider_configWithAccessAndSecretKeyAndInstanceProfile_staticAwsCredentialsProviderConfiguredWithInstanceProfile() throws Exception { // @checkstyle:on // Arrange @@ -198,7 +198,7 @@ public void credentialsProvider_configWithAccessAndSecretKeyAndInstanceProfile_s } @Test - public void credentialsProvider_configWithInstanceProfile_instanceProfileCredentialsProviderConfigured() + void credentialsProvider_configWithInstanceProfile_instanceProfileCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -220,7 +220,7 @@ public void credentialsProvider_configWithInstanceProfile_instanceProfileCredent } @Test - public void credentialsProvider_configWithProfileNameAndNoProfilePath_profileCredentialsProviderConfigured() + void credentialsProvider_configWithProfileNameAndNoProfilePath_profileCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -248,7 +248,7 @@ public void credentialsProvider_configWithProfileNameAndNoProfilePath_profileCre } @Test - public void credentialsProvider_configWithProfileNameAndCustomProfilePath_profileCredentialsProviderConfigured() + void credentialsProvider_configWithProfileNameAndCustomProfilePath_profileCredentialsProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -292,7 +292,7 @@ public void credentialsProvider_configWithProfileNameAndCustomProfilePath_profil } @Test - public void credentialsProvider_configWithAllProviders_allCredentialsProvidersConfigured() + void credentialsProvider_configWithAllProviders_allCredentialsProvidersConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -319,52 +319,52 @@ public void credentialsProvider_configWithAllProviders_allCredentialsProvidersCo } @EnableContextCredentials - public static class ApplicationConfigurationWithDefaultCredentialsProvider { + static class ApplicationConfigurationWithDefaultCredentialsProvider { } @EnableContextCredentials(accessKey = "accessTest", secretKey = "testSecret") - public static class ApplicationConfigurationWithAccessKeyAndSecretKey { + static class ApplicationConfigurationWithAccessKeyAndSecretKey { } @EnableContextCredentials(accessKey = "#{environment.accessKey}", secretKey = "#{environment.secretKey}") - public static class ApplicationConfigurationWithAccessKeyAndSecretKeyAsExpressions { + static class ApplicationConfigurationWithAccessKeyAndSecretKeyAsExpressions { } @EnableContextCredentials(accessKey = "${accessKey}", secretKey = "${secretKey}") - public static class ApplicationConfigurationWithAccessKeyAndSecretKeyAsPlaceHolder { + static class ApplicationConfigurationWithAccessKeyAndSecretKeyAsPlaceHolder { } @EnableContextCredentials(accessKey = "accessTest", secretKey = "testSecret", instanceProfile = true) - public static class ApplicationConfigurationWithAccessKeyAndSecretKeyAndInstanceProfile { + static class ApplicationConfigurationWithAccessKeyAndSecretKeyAndInstanceProfile { } @EnableContextCredentials(instanceProfile = true) - public static class ApplicationConfigurationWithInstanceProfileOnly { + static class ApplicationConfigurationWithInstanceProfileOnly { } @EnableContextCredentials(profileName = "test") - public static class ApplicationConfigurationWithProfileAndDefaultProfilePath { + static class ApplicationConfigurationWithProfileAndDefaultProfilePath { } @EnableContextCredentials(profileName = "customProfile", profilePath = "${profilePath}") - public static class ApplicationConfigurationWithProfileAndCustomProfilePath { + static class ApplicationConfigurationWithProfileAndCustomProfilePath { } // @checkstyle:off @EnableContextCredentials(accessKey = "accessTest", secretKey = "testSecret", instanceProfile = true, profileName = "customProfile") - public static class ApplicationConfigurationWithAllProviders { + static class ApplicationConfigurationWithAllProviders { } // @checkstyle:on diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextInstanceDataConfigurationTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextInstanceDataConfigurationTest.java index c75820de7..6018c9a42 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextInstanceDataConfigurationTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextInstanceDataConfigurationTest.java @@ -20,9 +20,9 @@ import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.context.MetaDataServer; import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils; @@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ContextInstanceDataConfigurationTest { +class ContextInstanceDataConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } @@ -45,7 +45,7 @@ public void tearDown() throws Exception { } @Test - public void propertySource_nonCloudEnvironment_noBeanConfigured() throws Exception { + void propertySource_nonCloudEnvironment_noBeanConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); this.context.register(ApplicationConfiguration.class); @@ -58,8 +58,7 @@ public void propertySource_nonCloudEnvironment_noBeanConfigured() throws Excepti } @Test - public void propertySource_enableInstanceData_propertySourceConfigured() - throws Exception { + void propertySource_enableInstanceData_propertySourceConfigured() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); HttpContext httpContext = httpServer.createContext( @@ -78,7 +77,7 @@ public void propertySource_enableInstanceData_propertySourceConfigured() // @checkstyle:off @Test - public void propertySource_enableInstanceDataWithCustomAttributeSeparator_propertySourceConfiguredAndUsesCustomAttributeSeparator() + void propertySource_enableInstanceDataWithCustomAttributeSeparator_propertySourceConfiguredAndUsesCustomAttributeSeparator() throws Exception { // @checkstyle:on // Arrange @@ -99,7 +98,7 @@ public void propertySource_enableInstanceDataWithCustomAttributeSeparator_proper // @checkstyle:off @Test - public void propertySource_enableInstanceDataWithCustomValueSeparator_propertySourceConfiguredAndUsesCustomValueSeparator() + void propertySource_enableInstanceDataWithCustomValueSeparator_propertySourceConfiguredAndUsesCustomValueSeparator() throws Exception { // @checkstyle:on // Arrange @@ -118,8 +117,8 @@ public void propertySource_enableInstanceDataWithCustomValueSeparator_propertySo httpServer.removeContext(httpContext); } - @Before - public void restContextInstanceDataCondition() throws IllegalAccessException { + @BeforeEach + void restContextInstanceDataCondition() throws IllegalAccessException { Field field = ReflectionUtils.findField(AwsCloudEnvironmentCheckUtils.class, "isCloudEnvironment"); assertThat(field).isNotNull(); @@ -129,19 +128,19 @@ public void restContextInstanceDataCondition() throws IllegalAccessException { @Configuration(proxyBeanMethods = false) @EnableContextInstanceData - public static class ApplicationConfiguration { + static class ApplicationConfiguration { } @Configuration(proxyBeanMethods = false) @EnableContextInstanceData(attributeSeparator = "/") - public static class ApplicationConfigurationWithCustomAttributeSeparator { + static class ApplicationConfigurationWithCustomAttributeSeparator { } @Configuration(proxyBeanMethods = false) @EnableContextInstanceData(valueSeparator = "=") - public static class ApplicationConfigurationWithCustomValueSeparator { + static class ApplicationConfigurationWithCustomValueSeparator { } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java index 51f8efbfa..c77d1aa26 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextRegionConfigurationRegistrarTest.java @@ -20,10 +20,8 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider; @@ -35,23 +33,21 @@ import org.springframework.core.env.MapPropertySource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class ContextRegionConfigurationRegistrarTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class ContextRegionConfigurationRegistrarTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() + void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -68,7 +64,7 @@ public void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() } @Test - public void regionProvider_withAutoDetectedRegion_dynamicRegionProviderConfigured() + void regionProvider_withAutoDetectedRegion_dynamicRegionProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -83,7 +79,7 @@ public void regionProvider_withAutoDetectedRegion_dynamicRegionProviderConfigure } @Test - public void regionProvider_withAutoDetectedRegionAndDefaultChain_defaulAwsChainRegionProviderConfigured() + void regionProvider_withAutoDetectedRegionAndDefaultChain_defaulAwsChainRegionProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext( @@ -98,7 +94,7 @@ public void regionProvider_withAutoDetectedRegionAndDefaultChain_defaulAwsChainR } @Test - public void regionProvider_withExpressionConfiguredRegion_staticRegionProviderConfigured() + void regionProvider_withExpressionConfiguredRegion_staticRegionProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -118,7 +114,7 @@ public void regionProvider_withExpressionConfiguredRegion_staticRegionProviderCo } @Test - public void regionProvider_withPlaceHolderConfiguredRegion_staticRegionProviderConfigured() + void regionProvider_withPlaceHolderConfiguredRegion_staticRegionProviderConfigured() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -138,53 +134,39 @@ public void regionProvider_withPlaceHolderConfiguredRegion_staticRegionProviderC } @Test - public void regionProvider_withNoRegionAndNoAutoDetection_reportsError() - throws Exception { - // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "Region must be manually configured or autoDetect enabled"); + void regionProvider_withNoRegionAndNoAutoDetection_reportsError() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(ApplicationConfigurationWithNoRegion.class); - // Act - this.context.refresh(); - // Assert + assertThatThrownBy(() -> this.context.refresh()) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "Region must be manually configured or autoDetect enabled"); + } @Test - public void regionProvider_withRegionAndAutoDetection_reportsError() - throws Exception { - // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "No region must be configured if autoDetect is defined as true"); + void regionProvider_withRegionAndAutoDetection_reportsError() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(ApplicationConfigurationWithAutoDetectionAndRegion.class); - // Act - this.context.refresh(); - // Assert + assertThatThrownBy(() -> this.context.refresh()) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "No region must be configured if autoDetect is defined as true"); } @Test - public void regionProvider_withConfiguredWrongRegion_reportsError() throws Exception { - // Arrange - this.expectedException.expect(BeanCreationException.class); - this.expectedException.expectMessage("not a valid region"); + void regionProvider_withConfiguredWrongRegion_reportsError() throws Exception { - this.context = new AnnotationConfigApplicationContext( - ApplicationConfigurationWithWrongRegion.class); - - // Act - - // Assert + assertThatThrownBy(() -> new AnnotationConfigApplicationContext( + ApplicationConfigurationWithWrongRegion.class)) + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("not a valid region"); } @Configuration(proxyBeanMethods = false) @@ -210,7 +192,7 @@ static class ApplicationConfigurationWithExpressionRegion { static class ApplicationConfigurationWithPlaceHolderRegion { @Bean - public static PropertySourcesPlaceholderConfigurer configurer() { + static PropertySourcesPlaceholderConfigurer configurer() { return new PropertySourcesPlaceholderConfigurer(); } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextResourceLoaderConfigurationTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextResourceLoaderConfigurationTest.java index a98cff4f1..6d6acae0e 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextResourceLoaderConfigurationTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextResourceLoaderConfigurationTest.java @@ -16,8 +16,8 @@ package org.springframework.cloud.aws.context.config.annotation; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver; @@ -28,19 +28,19 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ContextResourceLoaderConfigurationTest { +class ContextResourceLoaderConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() { + @AfterEach + void tearDown() { if (this.context != null) { this.context.close(); } } @Test - public void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() { + void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() { // Arrange this.context = new AnnotationConfigApplicationContext( ApplicationConfigurationWithResourceLoader.class); @@ -63,7 +63,7 @@ public void regionProvider_withConfiguredRegion_staticRegionProviderConfigured() static class ApplicationConfigurationWithResourceLoader { @Bean - public ApplicationBean appBean() { + ApplicationBean appBean() { return new ApplicationBean(); } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfigurationTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfigurationTest.java index 2a212c8c1..f26d5cd66 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfigurationTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/annotation/ContextStackConfigurationTest.java @@ -26,8 +26,8 @@ import com.amazonaws.services.cloudformation.model.StackResource; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.aws.context.MetaDataServer; @@ -38,12 +38,12 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ContextStackConfigurationTest { +class ContextStackConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } @@ -52,7 +52,7 @@ public void tearDown() throws Exception { } @Test - public void stackRegistry_noStackNameConfigured_returnsAutoConfiguredStackRegistry() + void stackRegistry_noStackNameConfigured_returnsAutoConfiguredStackRegistry() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -75,7 +75,7 @@ public void stackRegistry_noStackNameConfigured_returnsAutoConfiguredStackRegist } @Test - public void stackRegistry_stackNameConfigured_returnsConfiguredStackRegistryForName() + void stackRegistry_stackNameConfigured_returnsConfiguredStackRegistryForName() throws Exception { // Arrange this.context = new AnnotationConfigApplicationContext(); @@ -96,7 +96,7 @@ public void stackRegistry_stackNameConfigured_returnsConfiguredStackRegistryForN static class ApplicationConfigurationWithEmptyStackName { @Bean - public AmazonCloudFormation amazonCloudFormation() { + AmazonCloudFormation amazonCloudFormation() { AmazonCloudFormation amazonCloudFormation = Mockito .mock(AmazonCloudFormation.class); Mockito.when(amazonCloudFormation.describeStackResources( @@ -117,7 +117,7 @@ public AmazonCloudFormation amazonCloudFormation() { static class ManualConfigurationStackRegistryTestConfiguration { @Bean - public AmazonCloudFormation amazonCloudFormation() { + AmazonCloudFormation amazonCloudFormation() { AmazonCloudFormation amazonCloudFormation = Mockito .mock(AmazonCloudFormation.class); Mockito.when(amazonCloudFormation.listStackResources( diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/GlobalBeanDefinitionUtilsTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/GlobalBeanDefinitionUtilsTest.java index 2e137d646..a5d429def 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/GlobalBeanDefinitionUtilsTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/config/xml/GlobalBeanDefinitionUtilsTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.aws.context.config.xml; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -25,11 +25,11 @@ import static org.assertj.core.api.Assertions.assertThat; -public class GlobalBeanDefinitionUtilsTest { +class GlobalBeanDefinitionUtilsTest { // @checkstyle:off @Test - public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_resourceIdResolverBeanIsRegistered() { + void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_resourceIdResolverBeanIsRegistered() { // @checkstyle:on // Arrange DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); @@ -44,7 +44,7 @@ public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegis // @checkstyle:off @Test - public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_resourceIdResolverBeanIsRegisteredUnderInternalName() { + void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_resourceIdResolverBeanIsRegisteredUnderInternalName() { // @checkstyle:on // Arrange DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); @@ -58,7 +58,7 @@ public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegis } @Test - public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_returnsInternalBeanName() { + void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_returnsInternalBeanName() { // Arrange DefaultListableBeanFactory registry = new DefaultListableBeanFactory(); @@ -73,7 +73,7 @@ public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegis // @checkstyle:off @Test - public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegistered_resourceIdResolverBeanIsNotAgainRegistered() { + void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegistered_resourceIdResolverBeanIsNotAgainRegistered() { // @checkstyle:on // Arrange BeanDefinition resourceIdResolverBeanDefinition = new GenericBeanDefinition(); @@ -93,7 +93,7 @@ public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegi } @Test - public void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegistered_returnsInternalBeanName() { + void retrieveResourceIdResolverBeanName_resourceIdResolverBeanAlreadyRegistered_returnsInternalBeanName() { // Arrange BeanDefinition resourceIdResolverBeanDefinition = new GenericBeanDefinition(); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/support/io/SimpleStorageProtocolResolverConfigurerTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/support/io/SimpleStorageProtocolResolverConfigurerTest.java index 231217508..7deba76b1 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/support/io/SimpleStorageProtocolResolverConfigurerTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/context/support/io/SimpleStorageProtocolResolverConfigurerTest.java @@ -17,7 +17,7 @@ package org.springframework.cloud.aws.context.support.io; import com.amazonaws.services.s3.AmazonS3; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -36,7 +36,7 @@ /** * */ -public class SimpleStorageProtocolResolverConfigurerTest { +class SimpleStorageProtocolResolverConfigurerTest { private static void configureApplicationContext( StaticApplicationContext staticApplicationContext) { @@ -59,7 +59,7 @@ private static void configureApplicationContext( } @Test - public void postProcessBeans_beanWithFieldInjectedResourceLoader_receivesSimpleStorageResourceLoader() { + void postProcessBeans_beanWithFieldInjectedResourceLoader_receivesSimpleStorageResourceLoader() { // Arrange StaticApplicationContext staticApplicationContext = new StaticApplicationContext(); @@ -84,7 +84,7 @@ public void postProcessBeans_beanWithFieldInjectedResourceLoader_receivesSimpleS } @Test - public void postProcessBeans_beanWithMethodInjectedResourceLoader_receivesSimpleStorageResourceLoader() { + void postProcessBeans_beanWithMethodInjectedResourceLoader_receivesSimpleStorageResourceLoader() { // Arrange StaticApplicationContext staticApplicationContext = new StaticApplicationContext(); @@ -113,7 +113,7 @@ public void postProcessBeans_beanWithMethodInjectedResourceLoader_receivesSimple } @Test - public void postProcessBeans_beanWithConstructorInjectedResourceLoader_receivesSimpleStorageResourceLoader() { + void postProcessBeans_beanWithConstructorInjectedResourceLoader_receivesSimpleStorageResourceLoader() { // Arrange StaticApplicationContext staticApplicationContext = new StaticApplicationContext(); @@ -142,7 +142,7 @@ public void postProcessBeans_beanWithConstructorInjectedResourceLoader_receivesS } @Test - public void postProcessBeans_beanWithResourceLoaderAwareInterface_receivesSimpleStorageResourceLoader() { + void postProcessBeans_beanWithResourceLoaderAwareInterface_receivesSimpleStorageResourceLoader() { StaticApplicationContext staticApplicationContext = new StaticApplicationContext(); configureApplicationContext(staticApplicationContext); @@ -172,7 +172,7 @@ private static final class FieldInjectionTarget { @Autowired private ResourceLoader resourceLoader; - public ResourceLoader getResourceLoader() { + ResourceLoader getResourceLoader() { return this.resourceLoader; } @@ -182,12 +182,12 @@ private static final class MethodInjectionTarget { private ResourceLoader resourceLoader; - public ResourceLoader getResourceLoader() { + ResourceLoader getResourceLoader() { return this.resourceLoader; } @Autowired - public void setResourceLoader( + void setResourceLoader( @SuppressWarnings("SpringJavaAutowiringInspection") ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } @@ -204,7 +204,7 @@ private ConstructorInjectionTarget( this.resourceLoader = resourceLoader; } - public ResourceLoader getResourceLoader() { + ResourceLoader getResourceLoader() { return this.resourceLoader; } @@ -214,7 +214,7 @@ private static final class ResourceLoaderAwareBean implements ResourceLoaderAwar private ResourceLoader resourceLoader; - public ResourceLoader getResourceLoader() { + ResourceLoader getResourceLoader() { return this.resourceLoader; } diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceJavaMailSenderTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceJavaMailSenderTest.java index bdbeaae9a..530dd5b28 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceJavaMailSenderTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceJavaMailSenderTest.java @@ -33,7 +33,7 @@ import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.model.SendRawEmailRequest; import com.amazonaws.services.simpleemail.model.SendRawEmailResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; @@ -54,10 +54,10 @@ /** * Tests for class SimpleEmailServiceJavaMailSender. */ -public class SimpleEmailServiceJavaMailSenderTest { +class SimpleEmailServiceJavaMailSenderTest { @Test - public void createMimeMessage_withDefaultPropertiesAndNoEncodingAndFileTypeMap_returnsSessionWithEmptyProperties() { + void createMimeMessage_withDefaultPropertiesAndNoEncodingAndFileTypeMap_returnsSessionWithEmptyProperties() { // Arrange JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(null); @@ -70,7 +70,7 @@ public void createMimeMessage_withDefaultPropertiesAndNoEncodingAndFileTypeMap_r } @Test - public void createMimeMessage_withCustomProperties_sessionMaintainsCustomProperties() { + void createMimeMessage_withCustomProperties_sessionMaintainsCustomProperties() { // Arrange Properties mailProperties = new Properties(); mailProperties.setProperty("mail.from", "agim.emruli@maildomain.com"); @@ -89,7 +89,7 @@ public void createMimeMessage_withCustomProperties_sessionMaintainsCustomPropert } @Test - public void createMimeMessage_withCustomSession_sessionUsedInMailIsCustomSession() { + void createMimeMessage_withCustomSession_sessionUsedInMailIsCustomSession() { // Arrange Session customSession = Session.getInstance(new Properties()); @@ -105,7 +105,7 @@ public void createMimeMessage_withCustomSession_sessionUsedInMailIsCustomSession } @Test - public void createMimeMessage_withCustomEncoding_encodingIsDetectedInMimeMessageHelper() { + void createMimeMessage_withCustomEncoding_encodingIsDetectedInMimeMessageHelper() { // Arrange SimpleEmailServiceJavaMailSender mailSender = new SimpleEmailServiceJavaMailSender( null); @@ -120,7 +120,7 @@ public void createMimeMessage_withCustomEncoding_encodingIsDetectedInMimeMessage } @Test - public void createMimeMessage_withCustomFileTypeMap_fileTypeMapIsAvailableInMailSender() { + void createMimeMessage_withCustomFileTypeMap_fileTypeMapIsAvailableInMailSender() { // Arrange SimpleEmailServiceJavaMailSender mailSender = new SimpleEmailServiceJavaMailSender( null); @@ -135,7 +135,7 @@ public void createMimeMessage_withCustomFileTypeMap_fileTypeMapIsAvailableInMail } @Test - public void testCreateMimeMessageFromPreDefinedMessage() throws Exception { + void testCreateMimeMessageFromPreDefinedMessage() throws Exception { JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(null); MimeMessage original = createMimeMessage(); @@ -150,7 +150,7 @@ public void testCreateMimeMessageFromPreDefinedMessage() throws Exception { } @Test - public void testSendMimeMessage() throws MessagingException { + void testSendMimeMessage() throws MessagingException { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); @@ -164,7 +164,7 @@ public void testSendMimeMessage() throws MessagingException { } @Test - public void testSendMultipleMimeMessages() throws Exception { + void testSendMultipleMimeMessages() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); @@ -177,7 +177,7 @@ public void testSendMultipleMimeMessages() throws Exception { } @Test - public void testSendMailWithMimeMessagePreparator() throws Exception { + void testSendMailWithMimeMessagePreparator() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); @@ -206,7 +206,7 @@ public void testSendMailWithMimeMessagePreparator() throws Exception { } @Test - public void testSendMailWithMultipleMimeMessagePreparators() throws Exception { + void testSendMailWithMultipleMimeMessagePreparators() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); @@ -246,7 +246,7 @@ public void testSendMailWithMultipleMimeMessagePreparators() throws Exception { } @Test - public void testCreateMimeMessageWithExceptionInInputStream() throws Exception { + void testCreateMimeMessageWithExceptionInInputStream() throws Exception { InputStream inputStream = mock(InputStream.class); AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); @@ -270,7 +270,7 @@ public void testCreateMimeMessageWithExceptionInInputStream() throws Exception { } @Test - public void testSendMultipleMailsWithException() throws Exception { + void testSendMultipleMailsWithException() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); @@ -292,7 +292,7 @@ public void testSendMultipleMailsWithException() throws Exception { } @Test - public void testSendMailsWithExceptionWhilePreparing() { + void testSendMailsWithExceptionWhilePreparing() { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); diff --git a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceMailSenderTest.java b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceMailSenderTest.java index 5322f56a6..1bcdd48f4 100644 --- a/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceMailSenderTest.java +++ b/spring-cloud-aws-context/src/test/java/org/springframework/cloud/aws/mail/simplemail/SimpleEmailServiceMailSenderTest.java @@ -20,7 +20,7 @@ import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.model.SendEmailRequest; import com.amazonaws.services.simpleemail.model.SendEmailResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; @@ -37,10 +37,10 @@ /** * Tests for class SimpleEmailServiceMailSender. */ -public class SimpleEmailServiceMailSenderTest { +class SimpleEmailServiceMailSenderTest { @Test - public void testSendSimpleMailWithMinimalProperties() throws Exception { + void testSendSimpleMailWithMinimalProperties() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender( emailService); @@ -69,7 +69,7 @@ public void testSendSimpleMailWithMinimalProperties() throws Exception { } @Test - public void testSendSimpleMailWithCCandBCC() throws Exception { + void testSendSimpleMailWithCCandBCC() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender( emailService); @@ -100,7 +100,7 @@ public void testSendSimpleMailWithCCandBCC() throws Exception { } @Test - public void testSendMultipleMails() throws Exception { + void testSendMultipleMails() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender( emailService); @@ -116,7 +116,7 @@ public void testSendMultipleMails() throws Exception { } @Test - public void testSendMultipleMailsWithExceptionWhileSending() throws Exception { + void testSendMultipleMailsWithExceptionWhileSending() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender( emailService); @@ -143,7 +143,7 @@ public void testSendMultipleMailsWithExceptionWhileSending() throws Exception { } @Test - public void testShutDownOfResources() throws Exception { + void testShutDownOfResources() throws Exception { AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); SimpleEmailServiceMailSender mailSender = new SimpleEmailServiceMailSender( emailService); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonTestWebserviceClient.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonTestWebserviceClient.java index 6c58b0c31..5bbb00f25 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonTestWebserviceClient.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonTestWebserviceClient.java @@ -27,16 +27,16 @@ * @author Agim Emruli Test stub used by * {@link AmazonWebserviceClientConfigurationUtilsTest} */ -public class AmazonTestWebserviceClient extends AmazonWebServiceClient { +class AmazonTestWebserviceClient extends AmazonWebServiceClient { private Region region; - public AmazonTestWebserviceClient(AWSCredentialsProvider awsCredentialsProvider) { + AmazonTestWebserviceClient(AWSCredentialsProvider awsCredentialsProvider) { super(new ClientConfiguration()); notNull(awsCredentialsProvider, "Credentialsprovider must not be null"); } - public Region getRegion() { + Region getRegion() { return this.region; } diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientConfigurationUtilsTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientConfigurationUtilsTest.java index 59657397b..701a6ef30 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientConfigurationUtilsTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientConfigurationUtilsTest.java @@ -21,9 +21,7 @@ import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -31,17 +29,15 @@ import org.springframework.cloud.aws.core.region.StaticRegionProvider; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Agim Emruli */ -public class AmazonWebserviceClientConfigurationUtilsTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class AmazonWebserviceClientConfigurationUtilsTest { @Test - public void registerAmazonWebserviceClient_withMinimalConfiguration_returnsDefaultBeanDefinition() + void registerAmazonWebserviceClient_withMinimalConfiguration_returnsDefaultBeanDefinition() throws Exception { // Arrange DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -67,7 +63,7 @@ public void registerAmazonWebserviceClient_withMinimalConfiguration_returnsDefau // @checkstyle:off @Test - public void registerAmazonWebserviceClient_withCustomRegionProviderConfiguration_returnsBeanDefinitionWithRegionConfiguredThatIsReturnedByTheRegionProvider() + void registerAmazonWebserviceClient_withCustomRegionProviderConfiguration_returnsBeanDefinitionWithRegionConfiguredThatIsReturnedByTheRegionProvider() throws Exception { // @checkstyle:on // Arrange @@ -96,7 +92,7 @@ public void registerAmazonWebserviceClient_withCustomRegionProviderConfiguration } @Test - public void registerAmazonWebserviceClient_withCustomRegionConfiguration_returnsBeanDefinitionWithRegionConfigured() + void registerAmazonWebserviceClient_withCustomRegionConfiguration_returnsBeanDefinitionWithRegionConfigured() throws Exception { // Arrange DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -121,32 +117,27 @@ public void registerAmazonWebserviceClient_withCustomRegionConfiguration_returns } @Test - public void registerAmazonWebserviceClient_withCustomRegionAndRegionProviderConfigured_reportsError() + void registerAmazonWebserviceClient_withCustomRegionAndRegionProviderConfigured_reportsError() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "Only region or regionProvider can be configured, but not both"); - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerSingleton( AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, new StaticAwsCredentialsProvider()); - BeanDefinitionHolder beanDefinitionHolder = AmazonWebserviceClientConfigurationUtils + // Assert + assertThatThrownBy(() -> AmazonWebserviceClientConfigurationUtils .registerAmazonWebserviceClient(new Object(), beanFactory, AmazonTestWebserviceClient.class.getName(), "someProvider", - Regions.EU_WEST_1.getName()); - - // Act - beanFactory.getBean(beanDefinitionHolder.getBeanName(), - AmazonTestWebserviceClient.class); + Regions.EU_WEST_1.getName())) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining( + "Only region or regionProvider can be configured, but not both"); - // Assert } @Test - public void generateBeanName_withInterfaceAndCapitalLetterInSequence_producesDeCapitalizedBeanName() + void generateBeanName_withInterfaceAndCapitalLetterInSequence_producesDeCapitalizedBeanName() throws Exception { // Arrange diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientFactoryBeanTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientFactoryBeanTest.java index 2b7308f91..80a749a49 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientFactoryBeanTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/config/AmazonWebserviceClientFactoryBeanTest.java @@ -18,7 +18,7 @@ import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.region.StaticRegionProvider; @@ -27,11 +27,10 @@ /** * @author Agim Emruli */ -public class AmazonWebserviceClientFactoryBeanTest { +class AmazonWebserviceClientFactoryBeanTest { @Test - public void getObject_withCustomRegion_returnsClientWithCustomRegion() - throws Exception { + void getObject_withCustomRegion_returnsClientWithCustomRegion() throws Exception { // Arrange AmazonWebserviceClientFactoryBean factoryBean = new AmazonWebserviceClientFactoryBean<>( @@ -49,7 +48,7 @@ public void getObject_withCustomRegion_returnsClientWithCustomRegion() } @Test - public void getObject_withRegionProvider_returnsClientWithRegionReturnedByProvider() + void getObject_withRegionProvider_returnsClientWithRegionReturnedByProvider() throws Exception { // Arrange diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/credentials/CredentialsProviderFactoryBeanTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/credentials/CredentialsProviderFactoryBeanTest.java index 7a7f98c76..6afecb675 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/credentials/CredentialsProviderFactoryBeanTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/credentials/CredentialsProviderFactoryBeanTest.java @@ -21,11 +21,10 @@ import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,21 +34,17 @@ * * @author Agim Emruli */ -public class CredentialsProviderFactoryBeanTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class CredentialsProviderFactoryBeanTest { @Test - public void testCreateWithNullCredentialsProvider() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("not be null"); - // noinspection ResultOfObjectAllocationIgnored - new CredentialsProviderFactoryBean(null); + void testCreateWithNullCredentialsProvider() throws Exception { + assertThatThrownBy(() -> new CredentialsProviderFactoryBean(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("not be null"); } @Test - public void getObject_withZeroConfiguredProviders_returnsDefaultAwsCredentialsProviderChain() + void getObject_withZeroConfiguredProviders_returnsDefaultAwsCredentialsProviderChain() throws Exception { // Arrange CredentialsProviderFactoryBean credentialsProviderFactoryBean = new CredentialsProviderFactoryBean(); @@ -67,7 +62,7 @@ public void getObject_withZeroConfiguredProviders_returnsDefaultAwsCredentialsPr } @Test - public void testCreateWithMultiple() throws Exception { + void testCreateWithMultiple() throws Exception { AWSCredentialsProvider first = mock(AWSCredentialsProvider.class); AWSCredentialsProvider second = mock(AWSCredentialsProvider.class); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/StackResourceRegistryDetectingResourceIdResolverTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/StackResourceRegistryDetectingResourceIdResolverTest.java index adc7b62a7..c960c320d 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/StackResourceRegistryDetectingResourceIdResolverTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/StackResourceRegistryDetectingResourceIdResolverTest.java @@ -19,21 +19,17 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class StackResourceRegistryDetectingResourceIdResolverTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class StackResourceRegistryDetectingResourceIdResolverTest { private static ListableBeanFactory makeListableBeanFactory( StackResourceRegistry... stackResourceRegistries) { @@ -66,7 +62,7 @@ private static StackResourceRegistry makeStackResourceRegistry( // @checkstyle:off @Test - public void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndNoStackResourceRegistryAvailable_returnsLogicalResourceIdAsPhysicalResourceId() + void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndNoStackResourceRegistryAvailable_returnsLogicalResourceIdAsPhysicalResourceId() throws Exception { // @checkstyle:on // Arrange @@ -85,7 +81,7 @@ public void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndNo // @checkstyle:off @Test - public void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndStackResourceRegistryAvailable_returnsLogicalResourceIdAsPhysicalResourceId() + void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndStackResourceRegistryAvailable_returnsLogicalResourceIdAsPhysicalResourceId() throws Exception { // @checkstyle:on // Arrange @@ -105,7 +101,7 @@ public void resolveToPhysicalResourceId_logicalResourceIdOfNonStackResourceAndSt // @checkstyle:off @Test - public void resolveToPhysicalResourceId_logicalResourceIdOfStackResourceAndStackResourceRegistryAvailable_returnsPhysicalResourceIdFromStackResourceRegistry() + void resolveToPhysicalResourceId_logicalResourceIdOfStackResourceAndStackResourceRegistryAvailable_returnsPhysicalResourceIdFromStackResourceRegistry() throws Exception { // @checkstyle:on // Arrange @@ -125,7 +121,7 @@ public void resolveToPhysicalResourceId_logicalResourceIdOfStackResourceAndStack // @checkstyle:off @Test - public void createInstance_multipleStackResourceRegistriesAvailable_throwsException() + void createInstance_multipleStackResourceRegistriesAvailable_throwsException() throws Exception { // @checkstyle:on // Arrange @@ -135,11 +131,9 @@ public void createInstance_multipleStackResourceRegistriesAvailable_throwsExcept makeStackResourceRegistry(), makeStackResourceRegistry())); // Assert - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage("Multiple stack resource registries found"); - - // Act - resourceIdResolver.afterPropertiesSet(); + assertThatThrownBy(resourceIdResolver::afterPropertiesSet) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Multiple stack resource registries found"); } } diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceTest.java index 7b1f7c326..026bc51b2 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceTest.java @@ -27,10 +27,10 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.util.SocketUtils; @@ -39,15 +39,15 @@ /** * @author Agim Emruli */ -public class AmazonEc2InstanceDataPropertySourceTest { +class AmazonEc2InstanceDataPropertySourceTest { private static final int HTTP_SERVER_TEST_PORT = SocketUtils.findAvailableTcpPort(); @SuppressWarnings("StaticNonFinalField") private static HttpServer httpServer; - @BeforeClass - public static void setupHttpServer() throws Exception { + @BeforeAll + static void setupHttpServer() throws Exception { InetSocketAddress address = new InetSocketAddress(HTTP_SERVER_TEST_PORT); httpServer = HttpServer.create(address, -1); httpServer.start(); @@ -55,8 +55,8 @@ public static void setupHttpServer() throws Exception { "http://" + address.getHostName() + ":" + address.getPort()); } - @AfterClass - public static void shutdownHttpServer() throws Exception { + @AfterAll + static void shutdownHttpServer() throws Exception { if (httpServer != null) { httpServer.stop(10); } @@ -76,7 +76,7 @@ private static void resetMetadataEndpointUrlOverwrite() { } @Test - public void getProperty_userDataWithDefaultFormatting_ReturnsUserDataKeys() + void getProperty_userDataWithDefaultFormatting_ReturnsUserDataKeys() throws Exception { // Arrange httpServer.createContext("/latest/user-data/", new StringWritingHttpHandler( @@ -96,8 +96,7 @@ public void getProperty_userDataWithDefaultFormatting_ReturnsUserDataKeys() } @Test - public void getProperty_userDataWithCustomFormatting_ReturnsUserDataKeys() - throws Exception { + void getProperty_userDataWithCustomFormatting_ReturnsUserDataKeys() throws Exception { // Arrange httpServer.createContext("/latest/user-data/", new StringWritingHttpHandler( "keyA=valueD,keyB=valueE".getBytes("UTF-8"))); @@ -119,7 +118,7 @@ public void getProperty_userDataWithCustomFormatting_ReturnsUserDataKeys() } @Test - public void getProperty_knownAttribute_returnsAttributeValue() throws Exception { + void getProperty_knownAttribute_returnsAttributeValue() throws Exception { // Arrange httpServer.createContext("/latest/meta-data/instance-id", new StringWritingHttpHandler("i1234567".getBytes("UTF-8"))); @@ -136,7 +135,7 @@ public void getProperty_knownAttribute_returnsAttributeValue() throws Exception } @Test - public void getProperty_knownAttributeWithSubAttribute_returnsAttributeValue() + void getProperty_knownAttributeWithSubAttribute_returnsAttributeValue() throws Exception { // Arrange httpServer.createContext("/latest/meta-data/services/domain", @@ -154,7 +153,7 @@ public void getProperty_knownAttributeWithSubAttribute_returnsAttributeValue() } @Test - public void getProperty_unknownAttribute_returnsNull() throws Exception { + void getProperty_unknownAttribute_returnsNull() throws Exception { // Arrange httpServer.createContext("/latest/meta-data/instance-id", new StringWritingHttpHandler("i1234567".getBytes("UTF-8"))); @@ -171,8 +170,8 @@ public void getProperty_unknownAttribute_returnsNull() throws Exception { httpServer.removeContext("/latest/meta-data/instance-id"); } - @After - public void clearMetadataCache() throws Exception { + @AfterEach + void clearMetadataCache() throws Exception { Field metadataCacheField = EC2MetadataUtils.class.getDeclaredField("cache"); metadataCacheField.setAccessible(true); metadataCacheField.set(null, new HashMap()); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanTest.java index 30f6554f9..e7df61d2c 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanTest.java @@ -25,7 +25,7 @@ import com.amazonaws.services.ec2.model.Filter; import com.amazonaws.services.ec2.model.ResourceType; import com.amazonaws.services.ec2.model.TagDescription; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -34,10 +34,10 @@ /** * @author Agim Emruli */ -public class AmazonEc2InstanceUserTagsFactoryBeanTest { +class AmazonEc2InstanceUserTagsFactoryBeanTest { @Test - public void getObject_userTagDataAvailable_objectContainsAllAvailableKeys() + void getObject_userTagDataAvailable_objectContainsAllAvailableKeys() throws Exception { // Arrange AmazonEC2 amazonEC2 = mock(AmazonEC2.class); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceRegistryFactoryBeanTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceRegistryFactoryBeanTest.java index 32dddde7e..9f521832d 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceRegistryFactoryBeanTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceRegistryFactoryBeanTest.java @@ -26,7 +26,7 @@ import com.amazonaws.services.cloudformation.model.ListStackResourcesRequest; import com.amazonaws.services.cloudformation.model.ListStackResourcesResult; import com.amazonaws.services.cloudformation.model.StackResourceSummary; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.stack.ListableStackResourceFactory; import org.springframework.cloud.aws.core.env.stack.StackResource; @@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class StackResourceRegistryFactoryBeanTest { +class StackResourceRegistryFactoryBeanTest { private static final String STACK_NAME = "myStack"; @@ -120,7 +120,7 @@ private static StackResourceSummary makeStackResourceSummary(String logicalResou } @Test - public void createInstance_stackWithTwoResources_returnsStackResourceRegistryWithTwoResources() + void createInstance_stackWithTwoResources_returnsStackResourceRegistryWithTwoResources() throws Exception { // Arrange Map resourceIdMappings = new HashMap<>(); @@ -142,7 +142,7 @@ public void createInstance_stackWithTwoResources_returnsStackResourceRegistryWit } @Test - public void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages() + void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages() throws Exception { // Arrange AmazonCloudFormation cloudFormationClient = mock(AmazonCloudFormation.class); @@ -171,8 +171,7 @@ public void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWit } @Test - public void createInstance_stackWithTwoResources_listsBothResources() - throws Exception { + void createInstance_stackWithTwoResources_listsBothResources() throws Exception { // Arrange Map resourceIdMappings = new HashMap<>(); resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne"); @@ -197,7 +196,7 @@ public void createInstance_stackWithTwoResources_listsBothResources() } @Test - public void createInstance_stackWithName_returnsStackResourceRegistryWithStackName() + void createInstance_stackWithName_returnsStackResourceRegistryWithStackName() throws Exception { // Arrange StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean( @@ -213,7 +212,7 @@ public void createInstance_stackWithName_returnsStackResourceRegistryWithStackNa // @checkstyle:off @Test - public void createInstance_stackWithNoResources_returnsStackResourceRegistryAnsweringWithNullForNonExistingLogicalResourceId() + void createInstance_stackWithNoResources_returnsStackResourceRegistryAnsweringWithNullForNonExistingLogicalResourceId() throws Exception { // @checkstyle:on // Arrange @@ -230,7 +229,7 @@ public void createInstance_stackWithNoResources_returnsStackResourceRegistryAnsw } @Test - public void createInstance_stackWithNestedStack() throws Exception { + void createInstance_stackWithNestedStack() throws Exception { // Arrange Map resourceIdMappings = new HashMap<>(); resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne"); @@ -264,7 +263,7 @@ public void createInstance_stackWithNestedStack() throws Exception { } @Test - public void createInstance_stackWithNestedStack_dontReturnDuplicateResourceId() + void createInstance_stackWithNestedStack_dontReturnDuplicateResourceId() throws Exception { // Arrange Map resourceIdMappings = new HashMap<>(); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceUserTagsFactoryBeanTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceUserTagsFactoryBeanTest.java index e7070d80b..ec54ae67c 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceUserTagsFactoryBeanTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/env/stack/config/StackResourceUserTagsFactoryBeanTest.java @@ -23,7 +23,7 @@ import com.amazonaws.services.cloudformation.model.DescribeStacksResult; import com.amazonaws.services.cloudformation.model.Stack; import com.amazonaws.services.cloudformation.model.Tag; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -32,10 +32,10 @@ /** * @author Agim Emruli */ -public class StackResourceUserTagsFactoryBeanTest { +class StackResourceUserTagsFactoryBeanTest { @Test - public void getObject_stackWithTagsDefined_createTagsMap() throws Exception { + void getObject_stackWithTagsDefined_createTagsMap() throws Exception { // Arrange AmazonCloudFormation cloudFormation = mock(AmazonCloudFormation.class); StackNameProvider stackNameProvider = mock(StackNameProvider.class); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ClientFactoryTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ClientFactoryTest.java index 13bf33d12..01a38ee52 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ClientFactoryTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ClientFactoryTest.java @@ -19,55 +19,45 @@ import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Agim Emruli */ -public class AmazonS3ClientFactoryTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class AmazonS3ClientFactoryTest { @Test - public void createClientForEndpointUrl_withNullEndpoint_throwsIllegalArgumentException() { + void createClientForEndpointUrl_withNullEndpoint_throwsIllegalArgumentException() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard() .withRegion(Regions.DEFAULT_REGION).build(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("Endpoint Url must not be null"); - - // Act - amazonS3ClientFactory.createClientForEndpointUrl(amazonS3, null); - - // Prepare + // Assert + assertThatThrownBy( + () -> amazonS3ClientFactory.createClientForEndpointUrl(amazonS3, null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Endpoint Url must not be null"); } @Test - public void createClientForEndpointUrl_withNullAmazonS3Client_throwsIllegalArgumentException() { + void createClientForEndpointUrl_withNullAmazonS3Client_throwsIllegalArgumentException() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("AmazonS3 must not be null"); - - // Act - amazonS3ClientFactory.createClientForEndpointUrl(null, - "https://s3.amazonaws.com"); - - // Prepare + // Assert + assertThatThrownBy(() -> amazonS3ClientFactory.createClientForEndpointUrl(null, + "https://s3.amazonaws.com")).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("AmazonS3 must not be null"); } @Test - public void createClientForEndpointUrl_withDefaultRegionUrl_createClientForDefaultRegion() { + void createClientForEndpointUrl_withDefaultRegionUrl_createClientForDefaultRegion() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard() @@ -82,7 +72,7 @@ public void createClientForEndpointUrl_withDefaultRegionUrl_createClientForDefau } @Test - public void createClientForEndpointUrl_withCustomRegionUrl_createClientForCustomRegion() { + void createClientForEndpointUrl_withCustomRegionUrl_createClientForCustomRegion() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_1) @@ -97,7 +87,7 @@ public void createClientForEndpointUrl_withCustomRegionUrl_createClientForCustom } @Test - public void createClientForEndpointUrl_withProxiedClient_createClientForCustomRegion() { + void createClientForEndpointUrl_withProxiedClient_createClientForCustomRegion() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); AmazonS3 amazonS3 = AmazonS3ProxyFactory.createProxy( @@ -112,7 +102,7 @@ public void createClientForEndpointUrl_withProxiedClient_createClientForCustomRe } @Test - public void createClientForEndpointUrl_withCustomRegionUrlAndCachedClient_returnsCachedClient() { + void createClientForEndpointUrl_withCustomRegionUrlAndCachedClient_returnsCachedClient() { // Arrange AmazonS3ClientFactory amazonS3ClientFactory = new AmazonS3ClientFactory(); AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_1) diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ProxyFactoryTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ProxyFactoryTest.java index 53f7dfaa4..84c106c47 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ProxyFactoryTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/AmazonS3ProxyFactoryTest.java @@ -25,7 +25,7 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.aop.Advisor; import org.springframework.aop.framework.Advised; @@ -38,10 +38,10 @@ /** * @author Greg Turnquist */ -public class AmazonS3ProxyFactoryTest { +class AmazonS3ProxyFactoryTest { @Test - public void verifyBasicAdvice() throws Exception { + void verifyBasicAdvice() throws Exception { AmazonS3 amazonS3 = mock(AmazonS3.class); assertThat(AopUtils.isAopProxy(amazonS3)).isFalse(); @@ -57,7 +57,7 @@ public void verifyBasicAdvice() throws Exception { } @Test - public void verifyDoubleWrappingHandled() throws Exception { + void verifyDoubleWrappingHandled() throws Exception { AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -73,7 +73,7 @@ public void verifyDoubleWrappingHandled() throws Exception { } @Test - public void verifyPolymorphicHandling() { + void verifyPolymorphicHandling() { AmazonS3 amazonS3 = mock(AmazonS3.class); AmazonS3 proxy1 = AmazonS3ProxyFactory.createProxy(amazonS3); @@ -90,7 +90,7 @@ public void verifyPolymorphicHandling() { @SuppressWarnings("unchecked") @Test - public void verifyAddingRedirectAdviceToExistingProxy() { + void verifyAddingRedirectAdviceToExistingProxy() { AmazonS3 amazonS3 = mock(AmazonS3.class); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/PathMatchingSimpleStorageResourcePatternResolverTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/PathMatchingSimpleStorageResourcePatternResolverTest.java index 90d219e26..a39296e56 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/PathMatchingSimpleStorageResourcePatternResolverTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/PathMatchingSimpleStorageResourcePatternResolverTest.java @@ -28,7 +28,7 @@ import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.S3ObjectSummary; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.springframework.core.io.DefaultResourceLoader; @@ -48,10 +48,10 @@ * @author Greg Turnquist * @since 1.0 */ -public class PathMatchingSimpleStorageResourcePatternResolverTest { +class PathMatchingSimpleStorageResourcePatternResolverTest { @Test - public void testWildcardInBucketName() throws Exception { + void testWildcardInBucketName() throws Exception { AmazonS3 amazonS3 = prepareMockForTestWildcardInBucketName(); ResourcePatternResolver resourceLoader = getResourceLoader(amazonS3); @@ -65,7 +65,7 @@ public void testWildcardInBucketName() throws Exception { } @Test - public void testWildcardInKey() throws IOException { + void testWildcardInKey() throws IOException { AmazonS3 amazonS3 = prepareMockForTestWildcardInKey(); ResourcePatternResolver resourceLoader = getResourceLoader(amazonS3); @@ -84,7 +84,7 @@ public void testWildcardInKey() throws IOException { } @Test - public void testLoadingClasspathFile() throws Exception { + void testLoadingClasspathFile() throws Exception { AmazonS3 amazonS3 = mock(AmazonS3.class); ResourcePatternResolver resourceLoader = getResourceLoader(amazonS3); @@ -101,7 +101,7 @@ public void testLoadingClasspathFile() throws Exception { } @Test - public void testTruncatedListings() throws Exception { + void testTruncatedListings() throws Exception { AmazonS3 amazonS3 = prepareMockForTestTruncatedListings(); ResourcePatternResolver resourceLoader = getResourceLoader(amazonS3); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageNameUtilsTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageNameUtilsTest.java index 13d70546d..8636c0956 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageNameUtilsTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageNameUtilsTest.java @@ -16,11 +16,10 @@ package org.springframework.cloud.aws.core.io.s3; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.springframework.cloud.aws.core.io.s3.SimpleStorageNameUtils.getBucketNameFromLocation; import static org.springframework.cloud.aws.core.io.s3.SimpleStorageNameUtils.getLocationForBucketAndObject; import static org.springframework.cloud.aws.core.io.s3.SimpleStorageNameUtils.getLocationForBucketAndObjectAndVersionId; @@ -32,13 +31,10 @@ /** * @author Agim Emruli */ -public class SimpleStorageNameUtilsTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class SimpleStorageNameUtilsTest { @Test - public void testIsSimpleStorageResource() throws Exception { + void testIsSimpleStorageResource() throws Exception { assertThat(isSimpleStorageResource("s3://foo/bar")).isTrue(); assertThat(isSimpleStorageResource("S3://foo/bar")).isTrue(); assertThat(isSimpleStorageResource("f3://foo/bar")).isFalse(); @@ -46,14 +42,14 @@ public void testIsSimpleStorageResource() throws Exception { } @Test - public void testIsSimpleStorageResourceNUll() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage(" must not be null"); - isSimpleStorageResource(null); + void testIsSimpleStorageResourceNUll() throws Exception { + assertThatThrownBy(() -> isSimpleStorageResource(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(" must not be null"); } @Test - public void testGetBucketNameFromLocation() throws Exception { + void testGetBucketNameFromLocation() throws Exception { assertThat(getBucketNameFromLocation("s3://foo/bar")).isEqualTo("foo"); assertThat(getBucketNameFromLocation("s3://fo*/bar")).isEqualTo("fo*"); @@ -65,42 +61,42 @@ public void testGetBucketNameFromLocation() throws Exception { } @Test - public void testGetBucketNameNotNull() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage(" must not be null"); - getBucketNameFromLocation(null); + void testGetBucketNameNotNull() throws Exception { + assertThatThrownBy(() -> getBucketNameFromLocation(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(" must not be null"); } @Test - public void testNonLocationForBucket() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("not a valid S3 location"); - getBucketNameFromLocation("foo://fo*"); + void testNonLocationForBucket() throws Exception { + assertThatThrownBy(() -> getBucketNameFromLocation("foo://fo*")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("not a valid S3 location"); } @Test - public void testNonValidBucket() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("valid bucket name"); - getBucketNameFromLocation("s3://fo*"); + void testNonValidBucket() throws Exception { + assertThatThrownBy(() -> getBucketNameFromLocation("s3://fo*")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("valid bucket name"); } @Test - public void testEmptyValidBucket() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("valid bucket name"); - getBucketNameFromLocation("s3:///"); + void testEmptyValidBucket() throws Exception { + assertThatThrownBy(() -> getBucketNameFromLocation("s3:///")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("valid bucket name"); } @Test - public void testGetObjectNameNull() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage(" must not be null"); - getObjectNameFromLocation(null); + void testGetObjectNameNull() throws Exception { + assertThatThrownBy(() -> getObjectNameFromLocation(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(" must not be null"); } @Test - public void testGetObjectNameFromLocation() throws Exception { + void testGetObjectNameFromLocation() throws Exception { assertThat(getObjectNameFromLocation("s3://foo/bar")).isEqualTo("bar"); assertThat(getObjectNameFromLocation("s3://foo/ba*")).isEqualTo("ba*"); assertThat(getObjectNameFromLocation("s3://foo/")).isEqualTo(""); @@ -120,7 +116,7 @@ public void testGetObjectNameFromLocation() throws Exception { } @Test - public void testGetVersionIdFromLocation() throws Exception { + void testGetVersionIdFromLocation() throws Exception { assertThat(getVersionIdFromLocation("s3://foo/bar^versionIdValue")) .isEqualTo("versionIdValue"); assertThat(getVersionIdFromLocation("s3://foo/bar/ba*/boo.txt/^versionIdValue")) @@ -128,21 +124,21 @@ public void testGetVersionIdFromLocation() throws Exception { } @Test - public void testEmptyValidBucketForLocation() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("valid bucket name"); - getObjectNameFromLocation("s3:///"); + void testEmptyValidBucketForLocation() throws Exception { + assertThatThrownBy(() -> getObjectNameFromLocation("s3:///")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("valid bucket name"); } @Test - public void testEmptyValidBucketForLocationWithKey() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("valid bucket name"); - getObjectNameFromLocation("s3:///foo"); + void testEmptyValidBucketForLocationWithKey() throws Exception { + assertThatThrownBy(() -> getObjectNameFromLocation("s3:///foo")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("valid bucket name"); } @Test - public void testGetLocationForObjectNameAndBucket() throws Exception { + void testGetLocationForObjectNameAndBucket() throws Exception { assertThat(getLocationForBucketAndObject("foo", "bar")).isEqualTo("s3://foo/bar"); assertThat(getLocationForBucketAndObject("foo", "bar/baz")) .isEqualTo("s3://foo/bar/baz"); @@ -151,7 +147,7 @@ public void testGetLocationForObjectNameAndBucket() throws Exception { } @Test - public void testGetLocationForObjectNameAndBucketAndVersionId() throws Exception { + void testGetLocationForObjectNameAndBucketAndVersionId() throws Exception { assertThat( getLocationForBucketAndObjectAndVersionId("foo", "bar", "versionIdValue")) .isEqualTo("s3://foo/bar^versionIdValue"); @@ -162,7 +158,7 @@ public void testGetLocationForObjectNameAndBucketAndVersionId() throws Exception } @Test - public void testStripProtocol() throws Exception { + void testStripProtocol() throws Exception { assertThat(stripProtocol("s3://foo/bar")).isEqualTo("foo/bar"); assertThat(stripProtocol("s3://foo/bar/baz")).isEqualTo("foo/bar/baz"); assertThat(stripProtocol("s3://foo/bar.txt")).isEqualTo("foo/bar.txt"); @@ -172,10 +168,10 @@ public void testStripProtocol() throws Exception { } @Test - public void testStripProtocolNull() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage(" must not be null"); - stripProtocol(null); + void testStripProtocolNull() throws Exception { + assertThatThrownBy(() -> stripProtocol(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(" must not be null"); } } diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageProtocolResolverTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageProtocolResolverTest.java index bbd5d912c..335f8b5da 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageProtocolResolverTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageProtocolResolverTest.java @@ -19,7 +19,7 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.GetObjectMetadataRequest; import com.amazonaws.services.s3.model.ObjectMetadata; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -37,10 +37,10 @@ * @author Alain Sahli * @since 1.0 */ -public class SimpleStorageProtocolResolverTest { +class SimpleStorageProtocolResolverTest { @Test - public void testGetResourceWithExistingResource() { + void testGetResourceWithExistingResource() { AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -57,7 +57,7 @@ public void testGetResourceWithExistingResource() { } @Test - public void testGetResourceWithNonExistingResource() { + void testGetResourceWithNonExistingResource() { AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -70,7 +70,7 @@ public void testGetResourceWithNonExistingResource() { } @Test - public void testGetResourceWithVersionId() { + void testGetResourceWithVersionId() { AmazonS3 amazonS3 = mock(AmazonS3.class); SimpleStorageProtocolResolver resourceLoader = new SimpleStorageProtocolResolver( @@ -88,7 +88,7 @@ public void testGetResourceWithVersionId() { } @Test - public void testGetResourceWithDifferentPatterns() { + void testGetResourceWithDifferentPatterns() { AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -106,7 +106,7 @@ public void testGetResourceWithDifferentPatterns() { } @Test - public void testGetResourceWithMalFormedUrl() { + void testGetResourceWithMalFormedUrl() { AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -125,7 +125,7 @@ public void testGetResourceWithMalFormedUrl() { } @Test - public void testValidS3Pattern() { + void testValidS3Pattern() { AmazonS3 amazonS3 = mock(AmazonS3.class); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java index 1363f07be..1927ada76 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/io/s3/SimpleStorageResourceTest.java @@ -33,14 +33,13 @@ import com.amazonaws.services.s3.model.PutObjectResult; import com.amazonaws.services.s3.model.Region; import com.amazonaws.services.s3.model.S3Object; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.springframework.core.task.SyncTaskExecutor; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -49,13 +48,10 @@ /** * @author Agim Emruli */ -public class SimpleStorageResourceTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class SimpleStorageResourceTest { @Test - public void exists_withExistingObjectMetadata_returnsTrue() throws Exception { + void exists_withExistingObjectMetadata_returnsTrue() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))) @@ -70,7 +66,7 @@ public void exists_withExistingObjectMetadata_returnsTrue() throws Exception { } @Test - public void exists_withoutExistingObjectMetadata_returnsFalse() throws Exception { + void exists_withoutExistingObjectMetadata_returnsFalse() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))) @@ -85,7 +81,7 @@ public void exists_withoutExistingObjectMetadata_returnsFalse() throws Exception } @Test - public void contentLength_withExistingResource_returnsContentLengthOfObjectMetaData() + void contentLength_withExistingResource_returnsContentLengthOfObjectMetaData() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -103,7 +99,7 @@ public void contentLength_withExistingResource_returnsContentLengthOfObjectMetaD } @Test - public void lastModified_withExistingResource_returnsLastModifiedDateOfResource() + void lastModified_withExistingResource_returnsLastModifiedDateOfResource() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -123,43 +119,39 @@ public void lastModified_withExistingResource_returnsLastModifiedDateOfResource( } @Test - public void contentLength_fileDoesNotExists_reportsError() throws Exception { + void contentLength_fileDoesNotExists_reportsError() throws Exception { // Arrange - this.expectedException.expect(FileNotFoundException.class); - this.expectedException.expectMessage("not found"); - AmazonS3 amazonS3 = mock(AmazonS3.class); when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))) .thenReturn(null); SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3, "bucket", "object", new SyncTaskExecutor()); - // Act - simpleStorageResource.contentLength(); - // Assert + assertThatThrownBy(simpleStorageResource::contentLength) + .isInstanceOf(FileNotFoundException.class) + .hasMessageContaining("not found"); + } @Test - public void lastModified_fileDoestNotExist_reportsError() throws Exception { + void lastModified_fileDoestNotExist_reportsError() throws Exception { // Arrange - this.expectedException.expect(FileNotFoundException.class); - this.expectedException.expectMessage("not found"); - AmazonS3 amazonS3 = mock(AmazonS3.class); when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))) .thenReturn(null); + SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3, "bucket", "object", new SyncTaskExecutor()); - // Act - simpleStorageResource.lastModified(); - // Assert + assertThatThrownBy(simpleStorageResource::lastModified) + .isInstanceOf(FileNotFoundException.class) + .hasMessageContaining("not found"); } @Test - public void getFileName_existingObject_returnsFileNameWithoutBucketNameFromParameterWithoutActuallyFetchingTheFile() + void getFileName_existingObject_returnsFileNameWithoutBucketNameFromParameterWithoutActuallyFetchingTheFile() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -175,8 +167,7 @@ public void getFileName_existingObject_returnsFileNameWithoutBucketNameFromParam } @Test - public void getInputStream_existingObject_returnsInputStreamWithContent() - throws Exception { + void getInputStream_existingObject_returnsInputStreamWithContent() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); ObjectMetadata objectMetadata = mock(ObjectMetadata.class); @@ -198,7 +189,7 @@ public void getInputStream_existingObject_returnsInputStreamWithContent() } @Test - public void getDescription_withoutObjectMetaData_returnsDescriptiveDescription() + void getDescription_withoutObjectMetaData_returnsDescriptiveDescription() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -216,7 +207,7 @@ public void getDescription_withoutObjectMetaData_returnsDescriptiveDescription() } @Test - public void getUrl_existingObject_returnsUrlWithS3Prefix() throws Exception { + void getUrl_existingObject_returnsUrlWithS3Prefix() throws Exception { AmazonS3Client amazonS3 = mock(AmazonS3Client.class); @@ -233,7 +224,7 @@ public void getUrl_existingObject_returnsUrlWithS3Prefix() throws Exception { } @Test - public void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception { + void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception { AmazonS3Client amazonS3 = mock(AmazonS3Client.class); @@ -248,10 +239,7 @@ public void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception { } @Test - public void getFile_existingObject_throwsMeaningFullException() throws Exception { - - this.expectedException.expect(UnsupportedOperationException.class); - this.expectedException.expectMessage("getInputStream()"); + void getFile_existingObject_throwsMeaningFullException() throws Exception { AmazonS3Client amazonS3 = mock(AmazonS3Client.class); @@ -260,13 +248,15 @@ public void getFile_existingObject_throwsMeaningFullException() throws Exception "bucket", "object", new SyncTaskExecutor()); // Assert - simpleStorageResource.getFile(); + + assertThatThrownBy(simpleStorageResource::getFile) + .isInstanceOf(UnsupportedOperationException.class) + .hasMessageContaining("getInputStream()"); } @Test - public void createRelative_existingObject_returnsRelativeCreatedFile() - throws IOException { + void createRelative_existingObject_returnsRelativeCreatedFile() throws IOException { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); @@ -284,7 +274,7 @@ public void createRelative_existingObject_returnsRelativeCreatedFile() } @Test - public void writeFile_forNewFile_writesFileContent() throws Exception { + void writeFile_forNewFile_writesFileContent() throws Exception { // Arrange AmazonS3 amazonS3 = mock(AmazonS3.class); SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3, @@ -314,7 +304,7 @@ public void writeFile_forNewFile_writesFileContent() throws Exception { } @Test - public void getUri_encodes_objectName() throws Exception { + void getUri_encodes_objectName() throws Exception { AmazonS3 s3 = mock(AmazonS3.class); when(s3.getRegion()).thenReturn(Region.US_West_2); SimpleStorageResource resource = new SimpleStorageResource(s3, "bucketName", diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/naming/AmazonResourceNameTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/naming/AmazonResourceNameTest.java index 07cce9432..416f2cd8c 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/naming/AmazonResourceNameTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/naming/AmazonResourceNameTest.java @@ -18,11 +18,10 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.springframework.cloud.aws.core.naming.AmazonResourceName.Builder; import static org.springframework.cloud.aws.core.naming.AmazonResourceName.fromString; @@ -34,42 +33,38 @@ * @author Agim Emruli * @since 1.0 */ -public class AmazonResourceNameTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class AmazonResourceNameTest { @Test - public void testNameIsNull() { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("name must not be null"); - fromString(null); + void testNameIsNull() { + assertThatThrownBy(() -> fromString(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("name must not be null"); } @Test - public void testWithoutArnQualifier() { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException - .expectMessage("must have an arn qualifier at the beginning"); - fromString("foo:aws:iam::123456789012:David"); + void testWithoutArnQualifier() { + assertThatThrownBy(() -> fromString("foo:aws:iam::123456789012:David")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("must have an arn qualifier at the beginning"); } @Test - public void testWithoutAwsQualifier() { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("must have a valid partition name"); - fromString("arn:axs:iam::123456789012:David"); + void testWithoutAwsQualifier() { + assertThatThrownBy(() -> fromString("arn:axs:iam::123456789012:David")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("must have a valid partition name"); } @Test - public void testWithCustomPartitionName() { + void testWithCustomPartitionName() { AmazonResourceName resourceName = fromString( "arn:aws-cn:iam::123456789012:David"); assertThat(resourceName.getPartition()).isEqualTo("aws-cn"); } @Test - public void testDynamoDb() { + void testDynamoDb() { String arn = "arn:aws:dynamodb:us-east-1:123456789012:table/books_table"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("dynamodb"); @@ -81,7 +76,7 @@ public void testDynamoDb() { } @Test - public void testDynamoDbBuilder() { + void testDynamoDbBuilder() { Builder builder = new Builder(); builder.withService("dynamodb"); builder.withRegion(Region.getRegion(Regions.US_EAST_1)); @@ -94,7 +89,7 @@ public void testDynamoDbBuilder() { } @Test - public void testElasticBeansTalkBuilder() { + void testElasticBeansTalkBuilder() { Builder builder = new Builder(); builder.withService("elasticbeanstalk"); builder.withRegion(Region.getRegion(Regions.US_EAST_1)); @@ -106,7 +101,7 @@ public void testElasticBeansTalkBuilder() { } @Test - public void testElasticBeansTalk() { + void testElasticBeansTalk() { String arn = "arn:aws:elasticbeanstalk:us-east-1::solutionstack/32bit Amazon Linux running Tomcat 7"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("elasticbeanstalk"); @@ -119,7 +114,7 @@ public void testElasticBeansTalk() { } @Test - public void testIamService() { + void testIamService() { String arn = "arn:aws:iam::123456789012:server-certificate/ProdServerCert"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("iam"); @@ -131,7 +126,7 @@ public void testIamService() { } @Test - public void testRdsService() { + void testRdsService() { String arn = "arn:aws:rds:us-west-2:123456789012:db:mysql-db"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("rds"); @@ -143,7 +138,7 @@ public void testRdsService() { } @Test - public void testRoute53Service() { + void testRoute53Service() { String arn = "arn:aws:route53:::hostedzone/Z148QEXAMPLE8V"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("route53"); @@ -155,7 +150,7 @@ public void testRoute53Service() { } @Test - public void testS3Service() { + void testS3Service() { String arn = "arn:aws:s3:::my_corporate_bucket/Development/*"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("s3"); @@ -167,7 +162,7 @@ public void testS3Service() { } @Test - public void testSnsService() { + void testSnsService() { String arn = "arn:aws:sns:us-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("sns"); @@ -180,7 +175,7 @@ public void testSnsService() { } @Test - public void testSqsService() { + void testSqsService() { String arn = "arn:aws:sqs:us-east-1:123456789012:queue1"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("sqs"); @@ -192,7 +187,7 @@ public void testSqsService() { } @Test - public void testGovCloudAwsQualifier() { + void testGovCloudAwsQualifier() { String arn = "arn:aws-us-gov:sns:us-gov-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce"; AmazonResourceName resourceName = fromString(arn); assertThat(resourceName.getService()).isEqualTo("sns"); diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/Ec2MetadataRegionProviderTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/Ec2MetadataRegionProviderTest.java index fb9eee4a7..a808ad824 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/Ec2MetadataRegionProviderTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/Ec2MetadataRegionProviderTest.java @@ -18,23 +18,18 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Agim Emruli */ -public class Ec2MetadataRegionProviderTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class Ec2MetadataRegionProviderTest { @Test - public void getRegion_availabilityZoneWithMatchingRegion_returnsRegion() - throws Exception { + void getRegion_availabilityZoneWithMatchingRegion_returnsRegion() throws Exception { // Arrange Ec2MetadataRegionProvider regionProvider = new Ec2MetadataRegionProvider() { @@ -52,13 +47,8 @@ protected Region getCurrentRegion() { } @Test - public void getRegion_noMetadataAvailable_throwsIllegalStateException() - throws Exception { + void getRegion_noMetadataAvailable_throwsIllegalStateException() throws Exception { // Arrange - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage( - "There is no EC2 meta data available, because the application is not running in the EC2 environment"); - Ec2MetadataRegionProvider regionProvider = new Ec2MetadataRegionProvider() { @Override @@ -67,10 +57,11 @@ protected Region getCurrentRegion() { } }; - // Act - regionProvider.getRegion(); - // Assert + assertThatThrownBy(regionProvider::getRegion) + .isInstanceOf(IllegalStateException.class).hasMessageContaining( + "There is no EC2 meta data available, because the application is not running in the EC2 environment"); + } } diff --git a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/StaticRegionProviderTest.java b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/StaticRegionProviderTest.java index 506691ef4..b337671dc 100644 --- a/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/StaticRegionProviderTest.java +++ b/spring-cloud-aws-core/src/test/java/org/springframework/cloud/aws/core/region/StaticRegionProviderTest.java @@ -18,17 +18,17 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; /** * */ -public class StaticRegionProviderTest { +class StaticRegionProviderTest { @Test - public void testGetRegion() throws Exception { + void testGetRegion() throws Exception { assertThat(new StaticRegionProvider(Regions.US_EAST_1.getName()).getRegion()) .isSameAs(Region.getRegion(Regions.US_EAST_1)); } diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/BootElastiCacheAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/BootElastiCacheAwsTest.java index 05345ff4b..11f12f7b0 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/BootElastiCacheAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/BootElastiCacheAwsTest.java @@ -24,7 +24,7 @@ * @author Agim Emruli */ @SpringBootTest(classes = BootElastiCacheAwsTest.BootElastiCacheAwsTestConfig.class) -public class BootElastiCacheAwsTest extends ElastiCacheAwsTest { +class BootElastiCacheAwsTest extends ElastiCacheAwsTest { @SpringBootApplication @PropertySource({ "classpath:Integration-test-config.properties", diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheAwsTest.java index a45e15643..59a401792 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/ElastiCacheAwsTest.java @@ -16,19 +16,19 @@ package org.springframework.cloud.aws.cache; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.support.profile.AmazonWebserviceProfileValueSource; import org.springframework.cloud.aws.support.profile.IfAmazonWebserviceEnvironment; import org.springframework.test.annotation.ProfileValueSourceConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ProfileValueSourceConfiguration(AmazonWebserviceProfileValueSource.class) public abstract class ElastiCacheAwsTest { @@ -36,7 +36,7 @@ public abstract class ElastiCacheAwsTest { @Autowired private CachingService cachingService; - @Before + @BeforeEach public void resetInvocationCount() throws Exception { this.cachingService.resetInvocationCount(); } diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/JavaElastiCacheAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/JavaElastiCacheAwsTest.java index d49776220..5a850f378 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/JavaElastiCacheAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/cache/JavaElastiCacheAwsTest.java @@ -28,7 +28,7 @@ * @author Agim Emruli */ @ContextConfiguration(classes = JavaElastiCacheAwsTest.JavaElastiCacheAwsTestConfig.class) -public class JavaElastiCacheAwsTest extends ElastiCacheAwsTest { +class JavaElastiCacheAwsTest extends ElastiCacheAwsTest { @Configuration @EnableElastiCache(@CacheClusterConfig(name = "CacheCluster")) diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootPathMatchingResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootPathMatchingResourceLoaderAwsTest.java index f2def254a..0bebe20f3 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootPathMatchingResourceLoaderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootPathMatchingResourceLoaderAwsTest.java @@ -26,7 +26,7 @@ * @author Agim Emruli */ @SpringBootTest(classes = BootPathMatchingResourceLoaderAwsTest.BootPathMatchingResourceLoaderAwsTestConfig.class) -public class BootPathMatchingResourceLoaderAwsTest +class BootPathMatchingResourceLoaderAwsTest extends PathMatchingResourceLoaderAwsTest { @SpringBootApplication diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootResourceLoaderAwsTest.java index fb65e37c5..f17996bef 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootResourceLoaderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/BootResourceLoaderAwsTest.java @@ -27,7 +27,7 @@ */ @SpringBootTest(classes = BootResourceLoaderAwsTest.BootResourceLoaderAwsTestConfig.class, properties = { "cloud.aws.loader.corePoolSize=10", "cloud.aws.loader.queueCapacity=0" }) -public class BootResourceLoaderAwsTest extends ResourceLoaderAwsTest { +class BootResourceLoaderAwsTest extends ResourceLoaderAwsTest { @SpringBootApplication @Import(IntegrationTestConfig.class) diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/JavaPathMatchingResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/JavaPathMatchingResourceLoaderAwsTest.java index 3149ac59f..54243181c 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/JavaPathMatchingResourceLoaderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/JavaPathMatchingResourceLoaderAwsTest.java @@ -25,7 +25,7 @@ * @author Agim Emruli */ @ContextConfiguration(classes = JavaPathMatchingResourceLoaderAwsTest.JavaPathMatchingResourceLoaderAwsTestConfig.class) -public class JavaPathMatchingResourceLoaderAwsTest +class JavaPathMatchingResourceLoaderAwsTest extends PathMatchingResourceLoaderAwsTest { @ContextConfiguration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/PathMatchingResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/PathMatchingResourceLoaderAwsTest.java index 05149fb69..fb6d63cb3 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/PathMatchingResourceLoaderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/PathMatchingResourceLoaderAwsTest.java @@ -26,17 +26,18 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.ObjectMetadata; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; import org.springframework.cloud.aws.core.io.s3.PathMatchingSimpleStorageResourcePatternResolver; import org.springframework.context.ApplicationContext; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; /** * @author Alain Sahli @@ -44,8 +45,8 @@ * @since 1.0 */ @SuppressWarnings("SpringJavaAutowiringInspection") -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class PathMatchingResourceLoaderAwsTest { +@ExtendWith(SpringExtension.class) +abstract class PathMatchingResourceLoaderAwsTest { private static final List FILES_FOR_HIERARCHY = Arrays.asList( "foo1/bar1/baz1/test1.txt", "foo1/bar1/test1.txt", "foo1/test1.txt", @@ -75,16 +76,16 @@ public void testWildcardsInKey() throws Exception { String protocolAndBucket = "s3://" + bucketName; try { - assertEquals("test the '?' wildcard", 1, this.resourceLoader - .getResources(protocolAndBucket + "/foo1/bar?/test1.txt").length); - assertEquals("test the '*' wildcard", 1, this.resourceLoader - .getResources(protocolAndBucket + "/foo*/bar2/test2.txt").length); - assertEquals("test the '**' wildcard", 4, this.resourceLoader - .getResources(protocolAndBucket + "/**/test1.txt").length); - assertEquals("test a mix of '**' and '?'", 6, this.resourceLoader - .getResources(protocolAndBucket + "/**/test?.txt").length); - assertEquals("test all together", 2, this.resourceLoader - .getResources(protocolAndBucket + "/**/baz*/test?.txt").length); + assertEquals(1, this.resourceLoader + .getResources(protocolAndBucket + "/foo1/bar?/test1.txt").length, "test the '?' wildcard"); + assertEquals(1, this.resourceLoader + .getResources(protocolAndBucket + "/foo*/bar2/test2.txt").length, "test the '*' wildcard"); + assertEquals(4, this.resourceLoader + .getResources(protocolAndBucket + "/**/test1.txt").length, "test the '**' wildcard"); + assertEquals(6, this.resourceLoader + .getResources(protocolAndBucket + "/**/test?.txt").length, "test a mix of '**' and '?'"); + assertEquals(2, this.resourceLoader + .getResources(protocolAndBucket + "/**/baz*/test?.txt").length, "test all together"); } finally { deleteTestFiles(bucketName); @@ -102,14 +103,14 @@ public void testWildcardsInBucket() throws Exception { String bucketPrefix = firstBucket.substring(0, firstBucket.lastIndexOf("-") - 2); try { createTestFiles(firstBucket, secondBucket, thirdBucket); - assertEquals("test the '?' wildcard", 1, + assertEquals(1, this.resourceLoader.getResources("s3://" + bucketPrefix + "??" + firstBucket.substring(firstBucket.lastIndexOf("-")) - + "/test1.txt").length); - assertEquals("test the '*' wildcard", 3, this.resourceLoader - .getResources("s3://" + bucketPrefix + "*/test1.txt").length); - assertEquals("test the '**' wildcard", 4 * 3, - this.resourceLoader.getResources("s3://**/test1.txt").length); + + "/test1.txt").length, "test the '?' wildcard"); + assertEquals(3, this.resourceLoader + .getResources("s3://" + bucketPrefix + "*/test1.txt").length, "test the '*' wildcard"); + assertEquals(4 * 3, + this.resourceLoader.getResources("s3://**/test1.txt").length, "test the '**' wildcard"); } finally { deleteTestFiles(firstBucket, secondBucket, thirdBucket); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/ResourceLoaderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/ResourceLoaderAwsTest.java index 69241767b..bfeef3ab4 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/ResourceLoaderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/context/support/io/ResourceLoaderAwsTest.java @@ -36,9 +36,9 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.ObjectMetadata; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; @@ -46,20 +46,20 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.WritableResource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.DigestUtils; import org.springframework.util.FileCopyUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class ResourceLoaderAwsTest { +@ExtendWith(SpringExtension.class) +abstract class ResourceLoaderAwsTest { private static final String S3_PREFIX = "s3://"; @@ -77,7 +77,7 @@ public abstract class ResourceLoaderAwsTest { private StackResourceRegistry stackResourceRegistry; @Test - public void testUploadAndDownloadOfSmallFileWithInjectedResourceLoader() + void testUploadAndDownloadOfSmallFileWithInjectedResourceLoader() throws Exception { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); @@ -95,7 +95,7 @@ public void testUploadAndDownloadOfSmallFileWithInjectedResourceLoader() } @Test - public void testUploadFileWithRelativePath() throws Exception { + void testUploadFileWithRelativePath() throws Exception { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); uploadFileTestFile(bucketName, "testUploadFileWithRelativePathParent", @@ -131,7 +131,7 @@ private void uploadFileTestFile(String bucketName, String objectKey, String cont } @Test - public void testUploadFileWithMoreThenFiveMegabytes() throws Exception { + void testUploadFileWithMoreThenFiveMegabytes() throws Exception { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); Resource resource = this.resourceLoader.getResource( @@ -147,7 +147,7 @@ public void testUploadFileWithMoreThenFiveMegabytes() throws Exception { } @Test - public void testUploadBigFileAndCompareChecksum() + void testUploadBigFileAndCompareChecksum() throws IOException, NoSuchAlgorithmException { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); @@ -192,7 +192,7 @@ public void testUploadBigFileAndCompareChecksum() } @Test - public void exists_withNonExistingObject_shouldReturnFalse() throws Exception { + void exists_withNonExistingObject_shouldReturnFalse() throws Exception { // Arrange String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); @@ -203,7 +203,7 @@ public void exists_withNonExistingObject_shouldReturnFalse() throws Exception { } @Test - public void exists_withNonExistingBucket_shouldReturnFalse() throws Exception { + void exists_withNonExistingBucket_shouldReturnFalse() throws Exception { assertFalse(this.resourceLoader .getResource( S3_PREFIX + "dummy-bucket-does-not-really-exist/dummy-file.txt") @@ -212,8 +212,8 @@ public void exists_withNonExistingBucket_shouldReturnFalse() throws Exception { // Cleans up the bucket. Because if the bucket is not cleaned up, then the bucket will // not be deleted after the test run. - @After - public void tearDown() { + @AfterEach + void tearDown() { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); for (String createdObject : this.createdObjects) { diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceAwsTest.java index ef78e5e34..ff110def9 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceDataPropertySourceAwsTest.java @@ -25,25 +25,25 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.ReflectionUtils; import org.springframework.util.SocketUtils; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) public abstract class AmazonEc2InstanceDataPropertySourceAwsTest { private static final int HTTP_SERVER_TEST_PORT = SocketUtils.findAvailableTcpPort(); @@ -52,8 +52,8 @@ public abstract class AmazonEc2InstanceDataPropertySourceAwsTest { @Autowired private SimpleConfigurationBean simpleConfigurationBean; - @BeforeClass - public static void setupHttpServer() throws Exception { + @BeforeAll + static void setupHttpServer() throws Exception { InetSocketAddress address = new InetSocketAddress(HTTP_SERVER_TEST_PORT); httpServer = HttpServer.create(address, -1); httpServer.createContext("/latest/user-data", new StringWritingHttpHandler( @@ -66,8 +66,8 @@ public static void setupHttpServer() throws Exception { restContextInstanceDataCondition(); } - @AfterClass - public static void shutdownHttpServer() throws Exception { + @AfterAll + static void shutdownHttpServer() throws Exception { if (httpServer != null) { httpServer.stop(10); } @@ -95,11 +95,11 @@ private static void restContextInstanceDataCondition() throws IllegalAccessExcep } @Test - public void testInstanceDataResolution() throws Exception { - Assert.assertEquals("value1", this.simpleConfigurationBean.getValue1()); - Assert.assertEquals("value2", this.simpleConfigurationBean.getValue2()); - Assert.assertEquals("value3", this.simpleConfigurationBean.getValue3()); - Assert.assertEquals("i123456", this.simpleConfigurationBean.getValue4()); + void testInstanceDataResolution() throws Exception { + Assertions.assertEquals("value1", this.simpleConfigurationBean.getValue1()); + Assertions.assertEquals("value2", this.simpleConfigurationBean.getValue2()); + Assertions.assertEquals("value3", this.simpleConfigurationBean.getValue3()); + Assertions.assertEquals("i123456", this.simpleConfigurationBean.getValue4()); } private static class StringWritingHttpHandler implements HttpHandler { diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceIdProviderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceIdProviderAwsTest.java index e94ad2a97..000b1dda7 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceIdProviderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceIdProviderAwsTest.java @@ -18,9 +18,9 @@ import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.support.TestStackInstanceIdService; @@ -31,20 +31,20 @@ public class AmazonEc2InstanceIdProviderAwsTest { private TestStackInstanceIdService testStackInstanceIdService; - @Before - public void enableInstanceIdMetadataService() { + @BeforeEach + void enableInstanceIdMetadataService() { this.testStackInstanceIdService = TestStackInstanceIdService .fromInstanceId("i-abcdefg"); this.testStackInstanceIdService.enable(); } - @After - public void disableInstanceIdMetadataService() { + @AfterEach + void disableInstanceIdMetadataService() { this.testStackInstanceIdService.disable(); } @Test - public void getCurrentInstanceId_instanceIdAvailableViaMetadataService_returnsInstanceIdFromMetadataService() + void getCurrentInstanceId_instanceIdAvailableViaMetadataService_returnsInstanceIdFromMetadataService() throws IOException { // Arrange AmazonEc2InstanceIdProvider amazonEc2InstanceIdProvider = new AmazonEc2InstanceIdProvider(); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest.java index 4110965c3..937b5ccef 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/AmazonEc2InstanceUserTagsFactoryBeanAwsTest.java @@ -16,23 +16,23 @@ package org.springframework.cloud.aws.core.env.ec2; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.cloud.aws.support.TestStackInstanceIdService; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; /** * */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration public class AmazonEc2InstanceUserTagsFactoryBeanAwsTest { @@ -42,32 +42,32 @@ public class AmazonEc2InstanceUserTagsFactoryBeanAwsTest { @Autowired private ConfigurableApplicationContext context; - @Before - public void enableInstanceIdMetadataService() { + @BeforeEach + void enableInstanceIdMetadataService() { this.testStackInstanceIdService.enable(); } - @After - public void disableInstanceIdMetadataService() { + @AfterEach + void disableInstanceIdMetadataService() { this.testStackInstanceIdService.disable(); } @Test - public void testGetUserProperties() throws Exception { + void testGetUserProperties() throws Exception { - Assert.assertEquals("tagv1", + Assertions.assertEquals("tagv1", this.context.getBeanFactory().getBeanExpressionResolver().evaluate( "#{instanceData['tag1']}", new BeanExpressionContext(this.context.getBeanFactory(), null))); - Assert.assertEquals("tagv2", + Assertions.assertEquals("tagv2", this.context.getBeanFactory().getBeanExpressionResolver().evaluate( "#{instanceData['tag2']}", new BeanExpressionContext(this.context.getBeanFactory(), null))); - Assert.assertEquals("tagv3", + Assertions.assertEquals("tagv3", this.context.getBeanFactory().getBeanExpressionResolver().evaluate( "#{instanceData['tag3']}", new BeanExpressionContext(this.context.getBeanFactory(), null))); - Assert.assertEquals("tagv4", + Assertions.assertEquals("tagv4", this.context.getBeanFactory().getBeanExpressionResolver().evaluate( "#{instanceData['tag4']}", new BeanExpressionContext(this.context.getBeanFactory(), null))); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/JavaAmazonEc2InstanceDataPropertySourceAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/JavaAmazonEc2InstanceDataPropertySourceAwsTest.java index e4d728e7a..5fd679233 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/JavaAmazonEc2InstanceDataPropertySourceAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/ec2/JavaAmazonEc2InstanceDataPropertySourceAwsTest.java @@ -26,7 +26,7 @@ * @author Agim Emruli */ @ContextConfiguration(classes = JavaAmazonEc2InstanceDataPropertySourceAwsTest.JavaAmazonEc2InstanceDataPropertySourceAwsTestConfig.class) -public class JavaAmazonEc2InstanceDataPropertySourceAwsTest +class JavaAmazonEc2InstanceDataPropertySourceAwsTest extends AmazonEc2InstanceDataPropertySourceAwsTest { @Configuration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/BootStackConfigurationAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/BootStackConfigurationAwsTest.java index d075d99b8..07960789d 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/BootStackConfigurationAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/BootStackConfigurationAwsTest.java @@ -24,7 +24,7 @@ * @author Agim Emruli */ @SpringBootTest(classes = BootStackConfigurationAwsTest.BootStackConfigurationAwsTestConfig.class) -public class BootStackConfigurationAwsTest extends StackConfigurationAwsTest { +class BootStackConfigurationAwsTest extends StackConfigurationAwsTest { @SpringBootApplication @PropertySource({ "classpath:Integration-test-config.properties", diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/JavaStackConfigurationAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/JavaStackConfigurationAwsTest.java index c310e75d1..990e9e259 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/JavaStackConfigurationAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/JavaStackConfigurationAwsTest.java @@ -27,7 +27,7 @@ * @author Agim Emruli */ @ContextConfiguration(classes = JavaStackConfigurationAwsTest.JavaStackConfigurationAwsTestConfig.class) -public class JavaStackConfigurationAwsTest extends StackConfigurationAwsTest { +class JavaStackConfigurationAwsTest extends StackConfigurationAwsTest { @Configuration @EnableStackConfiguration(stackName = TestStackEnvironment.DEFAULT_STACK_NAME) diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackConfigurationAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackConfigurationAwsTest.java index e38adc59d..a5ec19755 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackConfigurationAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackConfigurationAwsTest.java @@ -18,21 +18,21 @@ import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.cloud.aws.support.TestStackEnvironment; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class StackConfigurationAwsTest { +@ExtendWith(SpringExtension.class) +abstract class StackConfigurationAwsTest { @Autowired private ListableStackResourceFactory stackResourceFactory; @@ -41,7 +41,7 @@ public abstract class StackConfigurationAwsTest { private ResourceIdResolver resourceIdResolver; @Test - public void resourcesByType_withResourceType_containsMinimumResources() + void resourcesByType_withResourceType_containsMinimumResources() throws Exception { // Arrange @@ -58,7 +58,7 @@ public void resourcesByType_withResourceType_containsMinimumResources() } @Test - public void lookupPhysicalResourceId_withEC2Instance_returnsPhysicalName() + void lookupPhysicalResourceId_withEC2Instance_returnsPhysicalName() throws Exception { // Arrange @@ -72,7 +72,7 @@ public void lookupPhysicalResourceId_withEC2Instance_returnsPhysicalName() } @Test - public void getAllResources_withConfiguredStack_returnsNonEmptyResourceList() + void getAllResources_withConfiguredStack_returnsNonEmptyResourceList() throws Exception { // Arrange @@ -85,7 +85,7 @@ public void getAllResources_withConfiguredStack_returnsNonEmptyResourceList() } @Test - public void getStackName_withManuallyConfiguredStackName_returnsManuallyConfiguredStackName() + void getStackName_withManuallyConfiguredStackName_returnsManuallyConfiguredStackName() throws Exception { // Arrange @@ -96,7 +96,9 @@ public void getStackName_withManuallyConfiguredStackName_returnsManuallyConfigur assertEquals(TestStackEnvironment.DEFAULT_STACK_NAME, stackName); } - public void resourceIdResolver_configuredByDefault_notNull() { + + @Test + void resourceIdResolver_configuredByDefault_notNull() { // Arrange // Act diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest.java index 217c340c9..7789a39c3 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/core/env/stack/StackResourceUserTagsAwsTest.java @@ -16,20 +16,20 @@ package org.springframework.cloud.aws.core.env.stack; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.aws.support.TestStackEnvironment; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; /** * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration public class StackResourceUserTagsAwsTest { @@ -43,11 +43,11 @@ public class StackResourceUserTagsAwsTest { private TestStackEnvironment testStackEnvironment; @Test - public void getObject_retrieveAttributesOfStackStartedByTestEnvironment_returnsStackUserTags() + void getObject_retrieveAttributesOfStackStartedByTestEnvironment_returnsStackUserTags() throws Exception { if (this.testStackEnvironment.isStackCreatedAutomatically()) { - Assert.assertEquals("value1", this.stackTag1); - Assert.assertEquals("value2", this.stackTag2); + Assertions.assertEquals("value1", this.stackTag1); + Assertions.assertEquals("value2", this.stackTag2); } } diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/BootDataSourceFactoryBeanAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/BootDataSourceFactoryBeanAwsTest.java index f6b834ccd..105d4ac14 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/BootDataSourceFactoryBeanAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/BootDataSourceFactoryBeanAwsTest.java @@ -24,7 +24,7 @@ * @author Agim Emruli */ @SpringBootTest(classes = BootDataSourceFactoryBeanAwsTest.BootDataSourceFactoryBeanAwsTestConfig.class) -public class BootDataSourceFactoryBeanAwsTest extends DataSourceFactoryBeanAwsTest { +class BootDataSourceFactoryBeanAwsTest extends DataSourceFactoryBeanAwsTest { @SpringBootApplication @PropertySource({ "classpath:Integration-test-config.properties", diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/DataSourceFactoryBeanAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/DataSourceFactoryBeanAwsTest.java index e0f46a638..27990a9c7 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/DataSourceFactoryBeanAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/DataSourceFactoryBeanAwsTest.java @@ -18,13 +18,13 @@ import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * AWS backed integration test for the datasource feature of the jdbc module @@ -32,14 +32,14 @@ * @author Agim Emruli * @since 1.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class DataSourceFactoryBeanAwsTest { +@ExtendWith(SpringExtension.class) +abstract class DataSourceFactoryBeanAwsTest { @Autowired private DatabaseService databaseService; @Test - public void testWriteAndReadWithReadReplicaEnabled() throws Exception { + void testWriteAndReadWithReadReplicaEnabled() throws Exception { Date lastAccessDatabase = this.databaseService.updateLastAccessDatabase(); Date checkDatabase = this.databaseService.getLastUpdate(lastAccessDatabase); assertEquals(lastAccessDatabase.getTime(), checkDatabase.getTime()); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/JavaDataSourceFactoryBeanAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/JavaDataSourceFactoryBeanAwsTest.java index fa9894724..b53beacb6 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/JavaDataSourceFactoryBeanAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/jdbc/JavaDataSourceFactoryBeanAwsTest.java @@ -27,7 +27,7 @@ * @author Agim Emruli */ @ContextConfiguration(classes = JavaDataSourceFactoryBeanAwsTest.JavaDataSourceFactoryBeanAwsTestConfig.class) -public class JavaDataSourceFactoryBeanAwsTest extends DataSourceFactoryBeanAwsTest { +class JavaDataSourceFactoryBeanAwsTest extends DataSourceFactoryBeanAwsTest { @Configuration @EnableRdsInstance(dbInstanceIdentifier = "RdsSingleMicroInstance", password = "${rdsPassword}") diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/BootMailSenderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/BootMailSenderAwsTest.java index e4c9fa274..d50c98db3 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/BootMailSenderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/BootMailSenderAwsTest.java @@ -28,7 +28,7 @@ * @author Agim Emruli */ @SpringBootTest(classes = BootMailSenderAwsTest.BootMailSenderAwsTestConfig.class) -public class BootMailSenderAwsTest extends MailSenderAwsTest { +class BootMailSenderAwsTest extends MailSenderAwsTest { @SpringBootApplication @PropertySource({ "classpath:Integration-test-config.properties", diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/MailSenderAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/MailSenderAwsTest.java index ed3f74caf..634edd730 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/MailSenderAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/mail/MailSenderAwsTest.java @@ -16,8 +16,8 @@ package org.springframework.cloud.aws.mail; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -26,7 +26,7 @@ import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; /** * Test that uses the Amazon Simple Mail service to send mail. @@ -44,8 +44,8 @@ * * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class MailSenderAwsTest { +@ExtendWith(SpringExtension.class) +abstract class MailSenderAwsTest { @Autowired private MailSender mailSender; @@ -60,7 +60,7 @@ public abstract class MailSenderAwsTest { private String recipientAddress; @Test - public void send_sendMailWithoutAnyAttachmentUsingTheSimpleMailApi_noExceptionThrownDuringSendAndForget() + void send_sendMailWithoutAnyAttachmentUsingTheSimpleMailApi_noExceptionThrownDuringSendAndForget() throws Exception { SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom(this.senderAddress); @@ -72,7 +72,7 @@ public void send_sendMailWithoutAnyAttachmentUsingTheSimpleMailApi_noExceptionTh } @Test - public void send_sendMailWithAttachmentUsingTheJavaMailMimeMessageFormat_noExceptionThrownDuringMessaegConstructionAndSend() + void send_sendMailWithAttachmentUsingTheJavaMailMimeMessageFormat_noExceptionThrownDuringMessaegConstructionAndSend() throws Exception { this.javaMailSender.send(mimeMessage -> { MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java index c8eb53594..908b271db 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/AbstractContainerTest.java @@ -19,8 +19,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; @@ -33,15 +33,15 @@ abstract class AbstractContainerTest { @Autowired protected SimpleMessageListenerContainer simpleMessageListenerContainer; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { if (!this.simpleMessageListenerContainer.isRunning()) { this.simpleMessageListenerContainer.start(); } } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.simpleMessageListenerContainer.isRunning()) { CountDownLatch countDownLatch = new CountDownLatch(1); this.simpleMessageListenerContainer.stop(countDownLatch::countDown); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootMessageListenerContainerAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootMessageListenerContainerAwsTest.java index 12f00567a..4cc485f1f 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootMessageListenerContainerAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootMessageListenerContainerAwsTest.java @@ -31,7 +31,7 @@ * @author Alain Sahli */ @SpringBootTest(classes = BootMessageListenerContainerAwsTest.MessageListenerContainerAwsTestConfiguration.class) -public class BootMessageListenerContainerAwsTest extends MessageListenerContainerAwsTest { +class BootMessageListenerContainerAwsTest extends MessageListenerContainerAwsTest { @Configuration @EnableAutoConfiguration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootNotificationMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootNotificationMessagingTemplateIntegrationTest.java index 4f1640ec8..15ac0a613 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootNotificationMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootNotificationMessagingTemplateIntegrationTest.java @@ -30,7 +30,7 @@ * @author Alain Sahli */ @SpringBootTest(classes = BootNotificationMessagingTemplateIntegrationTest.NotificationMessagingTemplateIntegrationTestConfiguration.class) -public class BootNotificationMessagingTemplateIntegrationTest +class BootNotificationMessagingTemplateIntegrationTest extends NotificationMessagingTemplateIntegrationTest { @Configuration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueListenerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueListenerTest.java index c10f42123..b0dfa557c 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueListenerTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueListenerTest.java @@ -32,7 +32,7 @@ * @author Alain Sahli */ @SpringBootTest(classes = BootQueueListenerTest.QueueListenerTestConfiguration.class) -public class BootQueueListenerTest extends QueueListenerTest { +class BootQueueListenerTest extends QueueListenerTest { @Configuration @EnableAutoConfiguration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueMessagingTemplateIntegrationTest.java index aa759e883..d2d1dcff7 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/BootQueueMessagingTemplateIntegrationTest.java @@ -31,7 +31,7 @@ * @author Alain Sahli */ @SpringBootTest(classes = BootQueueMessagingTemplateIntegrationTest.QueueMessagingTemplateIntegrationTestConfiguration.class) -public class BootQueueMessagingTemplateIntegrationTest +class BootQueueMessagingTemplateIntegrationTest extends QueueMessagingTemplateIntegrationTest { @Configuration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaMessageListenerContainerAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaMessageListenerContainerAwsTest.java index c696041aa..0c594ec7a 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaMessageListenerContainerAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaMessageListenerContainerAwsTest.java @@ -32,7 +32,7 @@ * @author Alain Sahli */ @ContextConfiguration(classes = JavaMessageListenerContainerAwsTest.MessageListenerContainerAwsTestConfiguration.class) -public class JavaMessageListenerContainerAwsTest extends MessageListenerContainerAwsTest { +class JavaMessageListenerContainerAwsTest extends MessageListenerContainerAwsTest { @Configuration @EnableSqs diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaNotificationMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaNotificationMessagingTemplateIntegrationTest.java index 3256c7173..ea766d3f6 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaNotificationMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaNotificationMessagingTemplateIntegrationTest.java @@ -32,7 +32,7 @@ * @author Alain Sahli */ @ContextConfiguration(classes = JavaNotificationMessagingTemplateIntegrationTest.NotificationMessagingTemplateIntegrationTestConfiguration.class) -public class JavaNotificationMessagingTemplateIntegrationTest +class JavaNotificationMessagingTemplateIntegrationTest extends NotificationMessagingTemplateIntegrationTest { @Configuration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueListenerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueListenerTest.java index af8b45702..147749230 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueListenerTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueListenerTest.java @@ -33,7 +33,7 @@ * @author Alain Sahli */ @ContextConfiguration(classes = JavaQueueListenerTest.JavaQueueListenerTestConfiguration.class) -public class JavaQueueListenerTest extends QueueListenerTest { +class JavaQueueListenerTest extends QueueListenerTest { @Configuration @EnableSqs diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueMessagingTemplateIntegrationTest.java index 6e382f861..ba8619c36 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/JavaQueueMessagingTemplateIntegrationTest.java @@ -32,7 +32,7 @@ * @author Alain Sahli */ @ContextConfiguration(classes = JavaQueueMessagingTemplateIntegrationTest.QueueMessagingTemplateIntegrationTestConfiguration.class) -public class JavaQueueMessagingTemplateIntegrationTest +class JavaQueueMessagingTemplateIntegrationTest extends QueueMessagingTemplateIntegrationTest { @Configuration diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/MessageListenerContainerAwsTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/MessageListenerContainerAwsTest.java index 0b5c23ccc..60ec7df33 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/MessageListenerContainerAwsTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/MessageListenerContainerAwsTest.java @@ -25,22 +25,22 @@ import com.amazonaws.services.sqs.AmazonSQSAsync; import com.amazonaws.services.sqs.model.SendMessageBatchRequest; import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; import org.springframework.core.task.TaskExecutor; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class MessageListenerContainerAwsTest extends AbstractContainerTest { +@ExtendWith(SpringExtension.class) +abstract class MessageListenerContainerAwsTest extends AbstractContainerTest { private static final int BATCH_MESSAGE_SIZE = 10; @@ -61,7 +61,7 @@ public abstract class MessageListenerContainerAwsTest extends AbstractContainerT @Autowired private StackResourceRegistry stackResourceRegistry; - @Before + @BeforeEach public void insertTotalNumberOfMessagesIntoTheLoadTestQueue() throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(TOTAL_BATCHES); @@ -76,7 +76,7 @@ public void insertTotalNumberOfMessagesIntoTheLoadTestQueue() } @Test - public void listenToAllMessagesUntilTheyAreReceivedOrTimeOut() throws Exception { + void listenToAllMessagesUntilTheyAreReceivedOrTimeOut() throws Exception { assertTrue(this.messageReceiver.getCountDownLatch().await(5, TimeUnit.MINUTES)); } diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/NotificationMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/NotificationMessagingTemplateIntegrationTest.java index 21d4275f4..2053fe4ce 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/NotificationMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/NotificationMessagingTemplateIntegrationTest.java @@ -19,9 +19,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; @@ -29,15 +29,15 @@ import org.springframework.cloud.aws.messaging.config.annotation.NotificationSubject; import org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate; import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Alain Sahli */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) public abstract class NotificationMessagingTemplateIntegrationTest extends AbstractContainerTest { @@ -47,13 +47,13 @@ public abstract class NotificationMessagingTemplateIntegrationTest @Autowired private NotificationReceiver notificationReceiver; - @Before - public void resetMocks() throws Exception { + @BeforeEach + void resetMocks() throws Exception { this.notificationReceiver.reset(); } @Test - public void send_validTextMessage_shouldBeDelivered() throws Exception { + void send_validTextMessage_shouldBeDelivered() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); this.notificationReceiver.setCountDownLatch(countDownLatch); @@ -71,7 +71,7 @@ public void send_validTextMessage_shouldBeDelivered() throws Exception { } @Test - public void send_validTextMessageWithoutDestination_shouldBeDeliveredToDefaultDestination() + void send_validTextMessageWithoutDestination_shouldBeDeliveredToDefaultDestination() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueListenerTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueListenerTest.java index 0829a219f..b99ee6fba 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueListenerTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueListenerTest.java @@ -25,8 +25,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,11 +41,11 @@ import org.springframework.messaging.handler.annotation.MessageExceptionHandler; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Agim Emruli @@ -54,8 +54,8 @@ */ @SuppressWarnings({ "AbstractClassWithoutAbstractMethods", "SpringJavaAutowiringInspection" }) -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class QueueListenerTest extends AbstractContainerTest { +@ExtendWith(SpringExtension.class) +abstract class QueueListenerTest extends AbstractContainerTest { @Autowired private MessageListener messageListener; @@ -73,7 +73,7 @@ public abstract class QueueListenerTest extends AbstractContainerTest { private ManualDeletionPolicyTestListener manualDeletionPolicyTestListener; @Test - public void messageMapping_singleMessageOnQueue_messageReceived() throws Exception { + void messageMapping_singleMessageOnQueue_messageReceived() throws Exception { // Arrange this.messageListener.setCountDownLatch(new CountDownLatch(1)); this.messageListener.getReceivedMessages().clear(); @@ -88,7 +88,7 @@ public void messageMapping_singleMessageOnQueue_messageReceived() throws Excepti } @Test - public void send_simpleString_shouldBeReceivedWithoutDoubleQuotes() throws Exception { + void send_simpleString_shouldBeReceivedWithoutDoubleQuotes() throws Exception { // Arrange this.messageListener.setCountDownLatch(new CountDownLatch(1)); this.messageListener.getReceivedMessages().clear(); @@ -102,7 +102,7 @@ public void send_simpleString_shouldBeReceivedWithoutDoubleQuotes() throws Excep } @Test - public void sendToAnnotation_WithAValidDestination_messageIsSent() throws Exception { + void sendToAnnotation_WithAValidDestination_messageIsSent() throws Exception { // Arrange this.messageListener.setCountDownLatch(new CountDownLatch(1)); this.messageListener.getReceivedMessages().clear(); @@ -119,7 +119,7 @@ public void sendToAnnotation_WithAValidDestination_messageIsSent() throws Except } @Test - public void receiveMessage_withArgumentAnnotatedWithHeaderOrHeaders_shouldReceiveHeaderValues() + void receiveMessage_withArgumentAnnotatedWithHeaderOrHeaders_shouldReceiveHeaderValues() throws Exception { // Arrange this.messageListener.setCountDownLatch(new CountDownLatch(1)); @@ -148,7 +148,7 @@ public void receiveMessage_withArgumentAnnotatedWithHeaderOrHeaders_shouldReceiv } @Test - public void redrivePolicy_withMessageMappingThrowingAnException_messageShouldAppearInDeadLetterQueue() + void redrivePolicy_withMessageMappingThrowingAnException_messageShouldAppearInDeadLetterQueue() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -162,7 +162,7 @@ public void redrivePolicy_withMessageMappingThrowingAnException_messageShouldApp } @Test - public void manualDeletion_withAcknowledgmentCalled_shouldSucceedAndDeleteMessage() + void manualDeletion_withAcknowledgmentCalled_shouldSucceedAndDeleteMessage() throws Exception { // Act this.queueMessagingTemplate.convertAndSend("ManualDeletionQueue", "Message"); diff --git a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueMessagingTemplateIntegrationTest.java b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueMessagingTemplateIntegrationTest.java index 49545d8fb..136ea1efe 100644 --- a/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueMessagingTemplateIntegrationTest.java +++ b/spring-cloud-aws-integration-test/src/test/java/org/springframework/cloud/aws/messaging/QueueMessagingTemplateIntegrationTest.java @@ -22,20 +22,20 @@ import javax.annotation.Resource; import com.fasterxml.jackson.annotation.JsonProperty; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Agim Emruli * @author Alain Sahli */ -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class QueueMessagingTemplateIntegrationTest { +@ExtendWith(SpringExtension.class) +abstract class QueueMessagingTemplateIntegrationTest { private static final String JSON_QUEUE_NAME = "JsonQueue"; @@ -50,7 +50,7 @@ public abstract class QueueMessagingTemplateIntegrationTest { private QueueMessagingTemplate messagingTemplateWithCustomConverter; @Test - public void sendAndReceive_stringMessageWithProvidedDestination_shouldUseTheProvidedDestination() + void sendAndReceive_stringMessageWithProvidedDestination_shouldUseTheProvidedDestination() throws Exception { // Arrange String messageContent = "testMessage"; @@ -66,7 +66,7 @@ public void sendAndReceive_stringMessageWithProvidedDestination_shouldUseTheProv } @Test - public void sendAndReceive_ObjectMessageWithDefaultDestination_shouldUseTheStreamQueue() + void sendAndReceive_ObjectMessageWithDefaultDestination_shouldUseTheStreamQueue() throws Exception { // Arrange List payload = Collections.singletonList("myString"); @@ -81,7 +81,7 @@ public void sendAndReceive_ObjectMessageWithDefaultDestination_shouldUseTheStrea } @Test - public void sendAndReceive_JsonMessageWithDefaultDestination_shouldUseTheJsonQueue() + void sendAndReceive_JsonMessageWithDefaultDestination_shouldUseTheJsonQueue() throws Exception { // Arrange DummyObject payload = new DummyObject("Hello", 100); @@ -97,7 +97,7 @@ public void sendAndReceive_JsonMessageWithDefaultDestination_shouldUseTheJsonQue } @Test - public void convertAndSend_aStringWithJsonConverter_shouldSerializeAndDeserializeCorrectly() + void convertAndSend_aStringWithJsonConverter_shouldSerializeAndDeserializeCorrectly() throws Exception { // Act this.defaultQueueMessagingTemplate.convertAndSend(JSON_QUEUE_NAME, "A String"); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfigurationTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfigurationTest.java index 8eb9e0d03..dd7290f49 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfigurationTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfigurationTest.java @@ -26,8 +26,8 @@ import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; import com.amazonaws.services.rds.model.DescribeDBInstancesResult; import com.amazonaws.services.rds.model.Endpoint; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.aws.jdbc.datasource.TomcatJdbcDataSourceFactory; @@ -41,19 +41,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -public class AmazonRdsInstanceConfigurationTest { +class AmazonRdsInstanceConfigurationTest { private AnnotationConfigApplicationContext context; - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { if (this.context != null) { this.context.close(); } } @Test - public void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresFactoryBeanWithoutReadReplica() + void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresFactoryBeanWithoutReadReplica() throws Exception { // Arrange @@ -68,7 +68,7 @@ public void configureBean_withDefaultClientSpecifiedAndNoReadReplica_configuresF } @Test - public void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceWithCustomDatabaseName() + void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceWithCustomDatabaseName() throws Exception { // Arrange @@ -88,7 +88,7 @@ public void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceW } @Test - public void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceWithCustomDataSourceFactory() + void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceWithCustomDataSourceFactory() throws Exception { // Arrange @@ -111,7 +111,7 @@ public void configureBean_withCustomDatabaseNameConfigured_configuresDataSourceW // @checkstyle:off @Test - public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithExpressions_configuresFactoryBeanWithoutReadReplicaAndResolvedExpressions() + void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithExpressions_configuresFactoryBeanWithoutReadReplicaAndResolvedExpressions() throws Exception { // @checkstyle:on // Arrange @@ -137,7 +137,7 @@ public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithExpressi // @checkstyle:off @Test - public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithPlaceHolder_configuresFactoryBeanWithoutReadReplicaAndResolvedPlaceHolders() + void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithPlaceHolder_configuresFactoryBeanWithoutReadReplicaAndResolvedPlaceHolders() throws Exception { // @checkstyle:on // Arrange @@ -162,7 +162,7 @@ public void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithPlaceHol } @Test - public void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFactoryBeanWithReadReplicaEnabled() + void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFactoryBeanWithReadReplicaEnabled() throws Exception { // Arrange @@ -178,10 +178,10 @@ public void configureBean_withDefaultClientSpecifiedAndReadReplica_configuresFac } @EnableRdsInstance(dbInstanceIdentifier = "test", password = "secret") - public static class ApplicationConfigurationWithoutReadReplica { + static class ApplicationConfigurationWithoutReadReplica { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -203,10 +203,10 @@ public AmazonRDS amazonRDS() { @EnableRdsInstance(dbInstanceIdentifier = "test", password = "secret", databaseName = "fooDb") - public static class ApplicationConfigurationWithoutReadReplicaAndCustomDbName { + static class ApplicationConfigurationWithoutReadReplicaAndCustomDbName { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -227,10 +227,10 @@ public AmazonRDS amazonRDS() { } @EnableRdsInstance(dbInstanceIdentifier = "test", password = "secret") - public static class ApplicationConfigurationWithoutReadReplicaAndCustomDataSourceFactory { + static class ApplicationConfigurationWithoutReadReplicaAndCustomDataSourceFactory { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -249,7 +249,7 @@ public AmazonRDS amazonRDS() { } @Bean - public RdsInstanceConfigurer instanceConfigurer() { + RdsInstanceConfigurer instanceConfigurer() { return () -> { TomcatJdbcDataSourceFactory dataSourceFactory = new TomcatJdbcDataSourceFactory(); dataSourceFactory.setInitialSize(0); @@ -263,12 +263,12 @@ public RdsInstanceConfigurer instanceConfigurer() { // @checkstyle:off @EnableRdsInstance(dbInstanceIdentifier = "#{environment.dbInstanceIdentifier}", password = "#{environment.password}", username = "#{environment.username}") - public static class ApplicationConfigurationWithoutReadReplicaAndExpressions { + static class ApplicationConfigurationWithoutReadReplicaAndExpressions { // @checkstyle:on @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -291,7 +291,7 @@ public AmazonRDS amazonRDS() { // @checkstyle:off @EnableRdsInstance(dbInstanceIdentifier = "${dbInstanceIdentifier}", password = "${password}", username = "${username}") - public static class ApplicationConfigurationWithoutReadReplicaAndPlaceHolder { + static class ApplicationConfigurationWithoutReadReplicaAndPlaceHolder { // @checkstyle:on @@ -301,7 +301,7 @@ static PropertySourcesPlaceholderConfigurer configurer() { } @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -323,10 +323,10 @@ public AmazonRDS amazonRDS() { @EnableRdsInstance(dbInstanceIdentifier = "test", password = "secret", readReplicaSupport = true) - public static class ApplicationConfigurationWithReadReplica { + static class ApplicationConfigurationWithReadReplica { @Bean - public AmazonRDS amazonRDS() { + AmazonRDS amazonRDS() { AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class); when(client.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/ReadOnlyRoutingDataSourceTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/ReadOnlyRoutingDataSourceTest.java index 7efa35819..f27c5e79f 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/ReadOnlyRoutingDataSourceTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/ReadOnlyRoutingDataSourceTest.java @@ -22,7 +22,7 @@ import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.datasource.ConnectionProxy; import org.springframework.jdbc.datasource.DataSourceTransactionManager; @@ -38,10 +38,10 @@ /** * @author Agim Emruli */ -public class ReadOnlyRoutingDataSourceTest { +class ReadOnlyRoutingDataSourceTest { @Test - public void getConnection_NoReadReplicaAvailableNoTransactionActive_returnsDefaultDataSource() + void getConnection_NoReadReplicaAvailableNoTransactionActive_returnsDefaultDataSource() throws Exception { // Arrange @@ -67,7 +67,7 @@ public void getConnection_NoReadReplicaAvailableNoTransactionActive_returnsDefau } @Test - public void getConnection_NoReadReplicaAvailableReadOnlyTransactionActive_returnsDefaultDataSource() + void getConnection_NoReadReplicaAvailableReadOnlyTransactionActive_returnsDefaultDataSource() throws Exception { // Arrange @@ -107,7 +107,7 @@ public void getConnection_NoReadReplicaAvailableReadOnlyTransactionActive_return } @Test - public void getConnection_ReadReplicaAvailableReadOnlyTransactionActive_returnsReadReplicaDataSource() + void getConnection_ReadReplicaAvailableReadOnlyTransactionActive_returnsReadReplicaDataSource() throws Exception { // Arrange @@ -152,7 +152,7 @@ public void getConnection_ReadReplicaAvailableReadOnlyTransactionActive_returnsR } @Test - public void getConnection_ReadReplicaAvailableWriteTransactionActive_returnsDefaultDataSource() + void getConnection_ReadReplicaAvailableWriteTransactionActive_returnsDefaultDataSource() throws Exception { // Arrange diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/TomcatJdbcDataSourceFactoryTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/TomcatJdbcDataSourceFactoryTest.java index 84909b731..b81437844 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/TomcatJdbcDataSourceFactoryTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/TomcatJdbcDataSourceFactoryTest.java @@ -26,7 +26,7 @@ import org.apache.tomcat.jdbc.pool.ConnectionPool; import org.apache.tomcat.jdbc.pool.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; @@ -43,10 +43,10 @@ * @author Agim Emruli * @since 1.0 */ -public class TomcatJdbcDataSourceFactoryTest { +class TomcatJdbcDataSourceFactoryTest { @Test - public void testCreateWithDefaultSettings() throws Exception { + void testCreateWithDefaultSettings() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); DataSourceInformation dataSourceInformation = new DataSourceInformation( @@ -61,7 +61,7 @@ public void testCreateWithDefaultSettings() throws Exception { } @Test - public void testWithCustomDatabasePlatformSupport() throws Exception { + void testWithCustomDatabasePlatformSupport() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); tomcatJdbcDataSourceFactory @@ -96,7 +96,7 @@ protected Map getAuthenticationInfo() { } @Test - public void testCloseDataSource() throws Exception { + void testCloseDataSource() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); tomcatJdbcDataSourceFactory.setInitialSize(0); @@ -113,7 +113,7 @@ public void testCloseDataSource() throws Exception { } @Test - public void testSetDefaultIsolationLevelName() throws Exception { + void testSetDefaultIsolationLevelName() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); tomcatJdbcDataSourceFactory.setDefaultTransactionIsolationName("READ_COMMITTED"); @@ -122,7 +122,7 @@ public void testSetDefaultIsolationLevelName() throws Exception { } @Test - public void testAllPropertiesSet() throws Exception { + void testAllPropertiesSet() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); tomcatJdbcDataSourceFactory.setDbProperties(new Properties()); @@ -192,7 +192,7 @@ public void testAllPropertiesSet() throws Exception { @Test // Test that the setters are not usable which will be configured at runtime // during datasource creation - public void testInvalidPoolAttributes() throws Exception { + void testInvalidPoolAttributes() throws Exception { TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory(); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/support/MapBasedDatabasePlatformSupportTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/support/MapBasedDatabasePlatformSupportTest.java index 752c1abd1..f49a33122 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/support/MapBasedDatabasePlatformSupportTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/datasource/support/MapBasedDatabasePlatformSupportTest.java @@ -19,11 +19,10 @@ import java.util.Collections; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Unit test class for @@ -32,35 +31,33 @@ * @author Agim Emruli * @since 1.0 */ -public class MapBasedDatabasePlatformSupportTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class MapBasedDatabasePlatformSupportTest { @Test - public void testGetDriverClassNameForDatabase() throws Exception { + void testGetDriverClassNameForDatabase() throws Exception { assertThat(new SimpleDatabasePlatformSupport() .getDriverClassNameForDatabase(DatabaseType.MYSQL)) .isEqualTo("com.mysql.jdbc.Driver"); } @Test - public void testGetDriverNonConfiguredDatabasePlatform() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("No driver"); - new SimpleDatabasePlatformSupport() - .getDriverClassNameForDatabase(DatabaseType.ORACLE); + void testGetDriverNonConfiguredDatabasePlatform() throws Exception { + assertThatThrownBy(() -> new SimpleDatabasePlatformSupport() + .getDriverClassNameForDatabase(DatabaseType.ORACLE)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No driver"); } @Test - public void testNullDriver() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("must not be null"); - new SimpleDatabasePlatformSupport().getDriverClassNameForDatabase(null); + void testNullDriver() throws Exception { + assertThatThrownBy(() -> new SimpleDatabasePlatformSupport() + .getDriverClassNameForDatabase(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("must not be null"); } @Test - public void testGetDatabaseUrlForDatabase() throws Exception { + void testGetDatabaseUrlForDatabase() throws Exception { SimpleDatabasePlatformSupport simpleDatabasePlatformSupport = new SimpleDatabasePlatformSupport(); String url = simpleDatabasePlatformSupport.getDatabaseUrlForDatabase( DatabaseType.MYSQL, "localhost", 3306, "testDb"); @@ -68,14 +65,13 @@ public void testGetDatabaseUrlForDatabase() throws Exception { } @Test - public void testGetDatabaseUrlWrongHostName() throws Exception { - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException - .expectMessage("Error constructing URI from Host:'localhost<'"); + void testGetDatabaseUrlWrongHostName() throws Exception { SimpleDatabasePlatformSupport simpleDatabasePlatformSupport = new SimpleDatabasePlatformSupport(); - String url = simpleDatabasePlatformSupport.getDatabaseUrlForDatabase( - DatabaseType.MYSQL, "localhost<", 3306, "testDb"); - assertThat(url).isEqualTo("jdbc:mysql://localhost:3306/testDb"); + assertThatThrownBy(() -> simpleDatabasePlatformSupport.getDatabaseUrlForDatabase( + DatabaseType.MYSQL, "localhost<", 3306, "testDb")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining( + "Error constructing URI from Host:'localhost<'"); } private static class SimpleDatabasePlatformSupport diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceFactoryBeanTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceFactoryBeanTest.java index 15cc7e801..706ea78e7 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceFactoryBeanTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceFactoryBeanTest.java @@ -24,9 +24,7 @@ import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; import com.amazonaws.services.rds.model.DescribeDBInstancesResult; import com.amazonaws.services.rds.model.Endpoint; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.cloud.aws.jdbc.datasource.DataSourceFactory; @@ -34,6 +32,7 @@ import org.springframework.cloud.aws.jdbc.datasource.support.DatabaseType; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -45,18 +44,12 @@ * @author Agim Emruli * @since 1.0 */ -public class AmazonRdsDataSourceFactoryBeanTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class AmazonRdsDataSourceFactoryBeanTest { @Test - public void afterPropertiesSet_noInstanceFound_reportsIllegalStateException() + void afterPropertiesSet_noInstanceFound_reportsIllegalStateException() throws Exception { // Arrange - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage("No database instance with id:'test'"); - AmazonRDS amazonRDS = mock(AmazonRDS.class); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) @@ -65,14 +58,14 @@ public void afterPropertiesSet_noInstanceFound_reportsIllegalStateException() AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean( amazonRDS, "test", "foo"); - // Act - amazonRdsDataSourceFactoryBean.afterPropertiesSet(); - // Assert + assertThatThrownBy(amazonRdsDataSourceFactoryBean::afterPropertiesSet) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("No database instance with id:'test'"); } @Test - public void newInstance_withResourceIdResolver_createsInstanceWithResolvedName() + void newInstance_withResourceIdResolver_createsInstanceWithResolvedName() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); @@ -110,7 +103,7 @@ public void newInstance_withResourceIdResolver_createsInstanceWithResolvedName() } @Test - public void afterPropertiesSet_noUserNameSet_createsInstanceWithUserNameFromMetaData() + void afterPropertiesSet_noUserNameSet_createsInstanceWithUserNameFromMetaData() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); @@ -145,8 +138,7 @@ public void afterPropertiesSet_noUserNameSet_createsInstanceWithUserNameFromMeta } @Test - public void destroyInstance_shutdownInitiated_destroysDynamicDataSource() - throws Exception { + void destroyInstance_shutdownInitiated_destroysDynamicDataSource() throws Exception { AmazonRDS amazonRDS = mock(AmazonRDS.class); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); DataSource dataSource = mock(DataSource.class); @@ -176,7 +168,7 @@ public void destroyInstance_shutdownInitiated_destroysDynamicDataSource() } @Test - public void afterPropertiesSet_customUserNameSet_createsInstanceWithCustomUserNameAndIgnoresMetaDataUserName() + void afterPropertiesSet_customUserNameSet_createsInstanceWithCustomUserNameAndIgnoresMetaDataUserName() throws Exception { AmazonRDS amazonRDS = mock(AmazonRDS.class); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceUserTagsFactoryBeanTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceUserTagsFactoryBeanTest.java index 9b96c835c..72d8e04bb 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceUserTagsFactoryBeanTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsDataSourceUserTagsFactoryBeanTest.java @@ -28,7 +28,7 @@ import com.amazonaws.services.rds.model.ListTagsForResourceRequest; import com.amazonaws.services.rds.model.ListTagsForResourceResult; import com.amazonaws.services.rds.model.Tag; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.ResourceIdResolver; @@ -39,10 +39,10 @@ /** * @author Agim Emruli */ -public class AmazonRdsDataSourceUserTagsFactoryBeanTest { +class AmazonRdsDataSourceUserTagsFactoryBeanTest { @Test - public void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned() + void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); @@ -75,7 +75,7 @@ public void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCus } @Test - public void getObject_instanceWithOutTags_emptyMapReturned() throws Exception { + void getObject_instanceWithOutTags_emptyMapReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); @@ -105,7 +105,7 @@ public void getObject_instanceWithOutTags_emptyMapReturned() throws Exception { } @Test - public void getObject_instanceWithTagsAndNoResourceIdResolverAndDefaultRegion_mapWithTagsReturned() + void getObject_instanceWithTagsAndNoResourceIdResolverAndDefaultRegion_mapWithTagsReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java index 9ae0e36d3..e070863d1 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/rds/AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest.java @@ -25,7 +25,7 @@ import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; import com.amazonaws.services.rds.model.DescribeDBInstancesResult; import com.amazonaws.services.rds.model.Endpoint; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.jdbc.datasource.DataSourceFactory; import org.springframework.cloud.aws.jdbc.datasource.DataSourceInformation; @@ -42,10 +42,10 @@ /** * @author Agim Emruli */ -public class AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest { +class AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest { @Test - public void afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter() + void afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); @@ -78,7 +78,7 @@ public void afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRou } @Test - public void afterPropertiesSet_instanceWithReadReplica_createsDataSourceRouter() + void afterPropertiesSet_instanceWithReadReplica_createsDataSourceRouter() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/DatabaseInstanceStatusRetryPolicyTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/DatabaseInstanceStatusRetryPolicyTest.java index cb3ec37ab..81e5e63d3 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/DatabaseInstanceStatusRetryPolicyTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/DatabaseInstanceStatusRetryPolicyTest.java @@ -21,9 +21,7 @@ import com.amazonaws.services.rds.model.DBInstanceNotFoundException; import com.amazonaws.services.rds.model.DescribeDBInstancesRequest; import com.amazonaws.services.rds.model.DescribeDBInstancesResult; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.dao.TransientDataAccessResourceException; @@ -31,6 +29,7 @@ import org.springframework.retry.context.RetryContextSupport; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,14 +39,10 @@ * @author Agim Emruli */ @SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion") -public class DatabaseInstanceStatusRetryPolicyTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class DatabaseInstanceStatusRetryPolicyTest { @Test - public void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() - throws Exception { + void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); @@ -70,7 +65,7 @@ public void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() } @Test - public void canRetry_withResourceIdResolver_returnsTrue() throws Exception { + void canRetry_withResourceIdResolver_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); @@ -98,7 +93,7 @@ public void canRetry_withResourceIdResolver_returnsTrue() throws Exception { } @Test - public void canRetry_retryNotPossibleDueToNoDatabase_returnsFalse() throws Exception { + void canRetry_retryNotPossibleDueToNoDatabase_returnsFalse() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); @@ -121,13 +116,9 @@ public void canRetry_retryNotPossibleDueToNoDatabase_returnsFalse() throws Excep } @Test - public void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException() + void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException() throws Exception { // Arrange - this.expectedException.expect(IllegalStateException.class); - this.expectedException - .expectMessage("Multiple databases found for same identifier"); - AmazonRDS amazonRDS = mock(AmazonRDS.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( @@ -146,11 +137,14 @@ public void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsExceptio new TransientDataAccessResourceException("not available")); // Assert - policy.canRetry(retryContext); + + assertThatThrownBy(() -> policy.canRetry(retryContext)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Multiple databases found for same identifier"); } @Test - public void canRetry_noExceptionRegistered_returnsTrue() throws Exception { + void canRetry_noExceptionRegistered_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/RdbmsRetryOperationsInterceptorTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/RdbmsRetryOperationsInterceptorTest.java index 49b578f63..645e5667c 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/RdbmsRetryOperationsInterceptorTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/RdbmsRetryOperationsInterceptorTest.java @@ -17,9 +17,7 @@ package org.springframework.cloud.aws.jdbc.retry; import org.aopalliance.intercept.MethodInvocation; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.aop.ProxyMethodInvocation; import org.springframework.retry.RetryContext; @@ -28,6 +26,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -38,13 +37,10 @@ * * @author Agim Emruli */ -public class RdbmsRetryOperationsInterceptorTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class RdbmsRetryOperationsInterceptorTest { @Test - public void testRetryContextIsAvailable() throws Throwable { + void testRetryContextIsAvailable() throws Throwable { RetryContext retryContext = mock(RetryContext.class); RetrySynchronizationManager.register(retryContext); @@ -62,7 +58,7 @@ public void testRetryContextIsAvailable() throws Throwable { } @Test - public void testRetryContextIsNotAvailable() throws Throwable { + void testRetryContextIsNotAvailable() throws Throwable { ProxyMethodInvocation methodInvocation = mock(ProxyMethodInvocation.class); @@ -81,15 +77,15 @@ public void testRetryContextIsNotAvailable() throws Throwable { } @Test - public void testRetryContextWithoutTransaction() throws Throwable { - this.expectedException.expect(RetryException.class); - this.expectedException.expectMessage("An active transaction was found"); - + void testRetryContextWithoutTransaction() throws Throwable { TransactionSynchronizationManager.setActualTransactionActive(true); try { RdbmsRetryOperationsInterceptor operationsInterceptor = new RdbmsRetryOperationsInterceptor(); MethodInvocation methodInvocation = mock(MethodInvocation.class); - operationsInterceptor.invoke(methodInvocation); + + assertThatThrownBy(() -> operationsInterceptor.invoke(methodInvocation)) + .isInstanceOf(RetryException.class) + .hasMessageContaining("An active transaction was found"); } finally { TransactionSynchronizationManager.setActualTransactionActive(false); diff --git a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/SqlRetryPolicyTest.java b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/SqlRetryPolicyTest.java index 8723b6287..9af1697b3 100644 --- a/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/SqlRetryPolicyTest.java +++ b/spring-cloud-aws-jdbc/src/test/java/org/springframework/cloud/aws/jdbc/retry/SqlRetryPolicyTest.java @@ -19,7 +19,7 @@ import java.sql.SQLException; import java.sql.SQLTransientException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.dao.TransientDataAccessResourceException; @@ -33,10 +33,10 @@ * * @author Agim Emruli */ -public class SqlRetryPolicyTest { +class SqlRetryPolicyTest { @Test - public void testRetryTransientExceptions() throws Exception { + void testRetryTransientExceptions() throws Exception { SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy(); RetryContextSupport retryContext = new RetryContextSupport(null); @@ -48,7 +48,7 @@ public void testRetryTransientExceptions() throws Exception { } @Test - public void testNoRetryPersistentExceptions() throws Exception { + void testNoRetryPersistentExceptions() throws Exception { SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy(); RetryContextSupport retryContext = new RetryContextSupport(null); @@ -60,7 +60,7 @@ public void testNoRetryPersistentExceptions() throws Exception { } @Test - public void testWithNestedException() throws Exception { + void testWithNestedException() throws Exception { SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy(); RetryContextSupport retryContext = new RetryContextSupport(null); @@ -70,7 +70,7 @@ public void testWithNestedException() throws Exception { } @Test - public void testMaxRetriesReached() throws Exception { + void testMaxRetriesReached() throws Exception { SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy(); sqlRetryPolicy.setMaxNumberOfRetries(3); RetryContextSupport retryContext = new RetryContextSupport(null); diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java index 391189927..19fbfd315 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java @@ -22,8 +22,8 @@ import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; import com.amazonaws.services.sns.AmazonSNS; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.context.config.annotation.EnableContextRegion; import org.springframework.cloud.aws.messaging.endpoint.NotificationStatusHandlerMethodArgumentResolver; @@ -42,18 +42,18 @@ /** * @author Alain Sahli */ -public class SnsConfigurationTest { +class SnsConfigurationTest { private AnnotationConfigWebApplicationContext webApplicationContext; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { this.webApplicationContext = new AnnotationConfigWebApplicationContext(); this.webApplicationContext.setServletContext(new MockServletContext()); } @Test - public void enableSns_withMinimalConfig_shouldConfigureACompositeArgumentResolver() + void enableSns_withMinimalConfig_shouldConfigureACompositeArgumentResolver() throws Exception { // Arrange & Act this.webApplicationContext.register(MinimalSnsConfiguration.class); @@ -82,8 +82,7 @@ public void enableSns_withMinimalConfig_shouldConfigureACompositeArgumentResolve } @Test - public void enableSns_withProvidedCredentials_shouldBeUsedToCreateClient() - throws Exception { + void enableSns_withProvidedCredentials_shouldBeUsedToCreateClient() throws Exception { // Arrange & Act this.webApplicationContext.register(SnsConfigurationWithCredentials.class); this.webApplicationContext.refresh(); @@ -95,7 +94,7 @@ public void enableSns_withProvidedCredentials_shouldBeUsedToCreateClient() } @Test - public void enableSns_withCustomAmazonSnsClient_shouldBeUsedByTheArgumentResolver() + void enableSns_withCustomAmazonSnsClient_shouldBeUsedByTheArgumentResolver() throws Exception { // Arrange & Act this.webApplicationContext.register(SnsConfigurationWithCustomAmazonClient.class); @@ -116,8 +115,7 @@ public void enableSns_withCustomAmazonSnsClient_shouldBeUsedByTheArgumentResolve } @Test - public void enableSns_withRegionProvided_shouldBeUsedToCreateClient() - throws Exception { + void enableSns_withRegionProvided_shouldBeUsedToCreateClient() throws Exception { // Arrange & Act this.webApplicationContext.register(SnsConfigurationWithRegionProvider.class); this.webApplicationContext.refresh(); @@ -151,11 +149,11 @@ protected static class MinimalSnsConfiguration { @EnableSns protected static class SnsConfigurationWithCredentials { - public static final AWSCredentialsProvider AWS_CREDENTIALS_PROVIDER = mock( + static final AWSCredentialsProvider AWS_CREDENTIALS_PROVIDER = mock( AWSCredentialsProvider.class); @Bean - public AWSCredentialsProvider awsCredentialsProvider() { + AWSCredentialsProvider awsCredentialsProvider() { return AWS_CREDENTIALS_PROVIDER; } @@ -165,10 +163,10 @@ public AWSCredentialsProvider awsCredentialsProvider() { @EnableSns protected static class SnsConfigurationWithCustomAmazonClient { - public static final AmazonSNS AMAZON_SNS = mock(AmazonSNS.class); + static final AmazonSNS AMAZON_SNS = mock(AmazonSNS.class); @Bean - public AmazonSNS amazonSNS() { + AmazonSNS amazonSNS() { return AMAZON_SNS; } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java index 7bebb2d02..b9df0b2b8 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java @@ -25,9 +25,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsync; import com.amazonaws.services.sqs.AmazonSQSAsyncClient; import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.context.config.annotation.EnableContextRegion; import org.springframework.cloud.aws.core.env.ResourceIdResolver; @@ -55,13 +53,10 @@ /** * @author Alain Sahli */ -public class SqsConfigurationTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class SqsConfigurationTest { @Test - public void configuration_withMinimalBeans_shouldStartSqsListenerContainer() + void configuration_withMinimalBeans_shouldStartSqsListenerContainer() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -89,7 +84,7 @@ public void configuration_withMinimalBeans_shouldStartSqsListenerContainer() } @Test - public void configuration_withCustomAmazonClient_shouldBeUsedByTheContainer() + void configuration_withCustomAmazonClient_shouldBeUsedByTheContainer() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -102,7 +97,7 @@ public void configuration_withCustomAmazonClient_shouldBeUsedByTheContainer() } @Test - public void messageHandler_withFactoryConfiguration_shouldUseCustomValues() + void messageHandler_withFactoryConfiguration_shouldUseCustomValues() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -134,7 +129,7 @@ public void messageHandler_withFactoryConfiguration_shouldUseCustomValues() } @Test - public void configuration_withCustomConfigurationFactory_shouldBeUsedToCreateTheContainer() + void configuration_withCustomConfigurationFactory_shouldBeUsedToCreateTheContainer() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -168,7 +163,7 @@ public void configuration_withCustomConfigurationFactory_shouldBeUsedToCreateThe } @Test - public void configuration_withCustomSendToMessageTemplate_shouldUseTheConfiguredTemplate() + void configuration_withCustomSendToMessageTemplate_shouldUseTheConfiguredTemplate() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -185,7 +180,7 @@ public void configuration_withCustomSendToMessageTemplate_shouldUseTheConfigured } @Test - public void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception { + void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( MinimalConfiguration.class); @@ -200,7 +195,7 @@ public void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception { } @Test - public void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider() + void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( @@ -217,7 +212,7 @@ public void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCr } @Test - public void configuration_withRegionProvider_shouldUseItForClient() throws Exception { + void configuration_withRegionProvider_shouldUseItForClient() throws Exception { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( ConfigurationWithRegionProvider.class); @@ -234,10 +229,10 @@ public void configuration_withRegionProvider_shouldUseItForClient() throws Excep @EnableSqs @Configuration(proxyBeanMethods = false) - public static class MinimalConfiguration { + static class MinimalConfiguration { @Bean - public AWSCredentialsProvider awsCredentials() { + AWSCredentialsProvider awsCredentials() { return mock(AWSCredentialsProvider.class); } @@ -245,18 +240,18 @@ public AWSCredentialsProvider awsCredentials() { @EnableSqs @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithCustomAmazonClient { + static class ConfigurationWithCustomAmazonClient { - public static final AmazonSQSAsync CUSTOM_SQS_CLIENT = mock(AmazonSQSAsync.class, + static final AmazonSQSAsync CUSTOM_SQS_CLIENT = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @Bean - public AWSCredentialsProvider awsCredentials() { + AWSCredentialsProvider awsCredentials() { return mock(AWSCredentialsProvider.class); } @Bean - public AmazonSQSAsync amazonSQS() { + AmazonSQSAsync amazonSQS() { return CUSTOM_SQS_CLIENT; } @@ -264,23 +259,22 @@ public AmazonSQSAsync amazonSQS() { @EnableSqs @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithCustomizedMessageHandler - extends MinimalConfiguration { + static class ConfigurationWithCustomizedMessageHandler extends MinimalConfiguration { - public static final HandlerMethodReturnValueHandler CUSTOM_RETURN_VALUE_HANDLER = mock( + static final HandlerMethodReturnValueHandler CUSTOM_RETURN_VALUE_HANDLER = mock( HandlerMethodReturnValueHandler.class); - public static final HandlerMethodArgumentResolver CUSTOM_ARGUMENT_RESOLVER = mock( + static final HandlerMethodArgumentResolver CUSTOM_ARGUMENT_RESOLVER = mock( HandlerMethodArgumentResolver.class); - public static final AmazonSQSAsync CUSTOM_AMAZON_SQS = mock(AmazonSQSAsync.class, + static final AmazonSQSAsync CUSTOM_AMAZON_SQS = mock(AmazonSQSAsync.class, withSettings().stubOnly()); - public static final ResourceIdResolver CUSTOM_RESOURCE_ID_RESOLVER = mock( + static final ResourceIdResolver CUSTOM_RESOURCE_ID_RESOLVER = mock( ResourceIdResolver.class); @Bean - public QueueMessageHandlerFactory queueMessageHandlerFactory() { + QueueMessageHandlerFactory queueMessageHandlerFactory() { QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory(); factory.setArgumentResolvers( Collections.singletonList(CUSTOM_ARGUMENT_RESOLVER)); @@ -296,30 +290,30 @@ public QueueMessageHandlerFactory queueMessageHandlerFactory() { @EnableSqs @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithCustomContainerFactory { + static class ConfigurationWithCustomContainerFactory { - public static final AmazonSQSAsync AMAZON_SQS = mock(AmazonSQSAsync.class, + static final AmazonSQSAsync AMAZON_SQS = mock(AmazonSQSAsync.class, withSettings().stubOnly()); - public static final boolean AUTO_STARTUP = true; + static final boolean AUTO_STARTUP = true; - public static final int MAX_NUMBER_OF_MESSAGES = 1456; + static final int MAX_NUMBER_OF_MESSAGES = 1456; - public static final QueueMessageHandler MESSAGE_HANDLER; + static final QueueMessageHandler MESSAGE_HANDLER; - public static final ResourceIdResolver RESOURCE_ID_RESOLVER = mock( + static final ResourceIdResolver RESOURCE_ID_RESOLVER = mock( ResourceIdResolver.class); - public static final SimpleAsyncTaskExecutor TASK_EXECUTOR = new SimpleAsyncTaskExecutor(); + static final SimpleAsyncTaskExecutor TASK_EXECUTOR = new SimpleAsyncTaskExecutor(); - public static final int VISIBILITY_TIMEOUT = 1789; + static final int VISIBILITY_TIMEOUT = 1789; - public static final int WAIT_TIME_OUT = 12; + static final int WAIT_TIME_OUT = 12; - public static final DestinationResolver DESTINATION_RESOLVER = new DynamicQueueUrlDestinationResolver( + static final DestinationResolver DESTINATION_RESOLVER = new DynamicQueueUrlDestinationResolver( mock(AmazonSQSAsync.class, withSettings().stubOnly())); - public static final long BACK_OFF_TIME = 5000; + static final long BACK_OFF_TIME = 5000; static { QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); @@ -328,7 +322,7 @@ public static class ConfigurationWithCustomContainerFactory { } @Bean - public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() { + SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() { SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory(); factory.setAmazonSqs(amazonSQS()); factory.setAutoStartup(AUTO_STARTUP); @@ -345,7 +339,7 @@ public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFacto } @Bean - public AmazonSQSAsync amazonSQS() { + AmazonSQSAsync amazonSQS() { return AMAZON_SQS; } @@ -353,13 +347,13 @@ public AmazonSQSAsync amazonSQS() { @EnableSqs @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithCustomSendToMessageTemplate { + static class ConfigurationWithCustomSendToMessageTemplate { - public static final DestinationResolvingMessageSendingOperations SEND_TO_MESSAGE_TEMPLATE = mock( + static final DestinationResolvingMessageSendingOperations SEND_TO_MESSAGE_TEMPLATE = mock( DestinationResolvingMessageSendingOperations.class); @Bean - public QueueMessageHandlerFactory queueMessageHandlerFactory() { + QueueMessageHandlerFactory queueMessageHandlerFactory() { QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory(); factory.setSendToMessagingTemplate(SEND_TO_MESSAGE_TEMPLATE); @@ -370,14 +364,14 @@ public QueueMessageHandlerFactory queueMessageHandlerFactory() { @EnableSqs @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithMissingAwsCredentials { + static class ConfigurationWithMissingAwsCredentials { } @EnableSqs @EnableContextRegion(region = "eu-west-1") @Configuration(proxyBeanMethods = false) - public static class ConfigurationWithRegionProvider { + static class ConfigurationWithRegionProvider { } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/NotificationMessagingTemplateTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/NotificationMessagingTemplateTest.java index 5855c6fce..b1edebd57 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/NotificationMessagingTemplateTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/NotificationMessagingTemplateTest.java @@ -23,7 +23,7 @@ import com.amazonaws.services.sns.model.ListTopicsResult; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.model.Topic; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.messaging.core.DestinationResolver; import org.springframework.messaging.support.MessageBuilder; @@ -36,10 +36,10 @@ /** * @author Alain Sahli */ -public class NotificationMessagingTemplateTest { +class NotificationMessagingTemplateTest { @Test - public void send_validTextMessage_usesTopicChannel() throws Exception { + void send_validTextMessage_usesTopicChannel() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate( @@ -61,7 +61,7 @@ public void send_validTextMessage_usesTopicChannel() throws Exception { } @Test - public void send_validTextMessageWithCustomDestinationResolver_usesTopicChannel() + void send_validTextMessageWithCustomDestinationResolver_usesTopicChannel() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -80,7 +80,7 @@ public void send_validTextMessageWithCustomDestinationResolver_usesTopicChannel( } @Test - public void convertAndSend_withDestinationPayloadAndSubject_shouldSetSubject() + void convertAndSend_withDestinationPayloadAndSubject_shouldSetSubject() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -102,7 +102,7 @@ public void convertAndSend_withDestinationPayloadAndSubject_shouldSetSubject() } @Test - public void convertAndSend_withPayloadAndSubject_shouldSetSubject() throws Exception { + void convertAndSend_withPayloadAndSubject_shouldSetSubject() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannelTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannelTest.java index b7695fe67..a55a200bf 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannelTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannelTest.java @@ -37,9 +37,7 @@ import com.amazonaws.services.sqs.model.ReceiveMessageResult; import com.amazonaws.services.sqs.model.SendMessageRequest; import com.amazonaws.services.sqs.model.SendMessageResult; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.messaging.Message; @@ -52,6 +50,7 @@ import org.springframework.util.MimeType; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNotNull; import static org.mockito.Mockito.mock; @@ -64,13 +63,10 @@ * @author Alain Sahli * @since 1.0 */ -public class QueueMessageChannelTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class QueueMessageChannelTest { @Test - public void sendMessage_validTextMessage_returnsTrue() throws Exception { + void sendMessage_validTextMessage_returnsTrue() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); ArgumentCaptor sendMessageRequestArgumentCaptor = ArgumentCaptor @@ -94,8 +90,7 @@ public void sendMessage_validTextMessage_returnsTrue() throws Exception { } @Test - public void sendMessage_serviceThrowsError_throwsMessagingException() - throws Exception { + void sendMessage_serviceThrowsError_throwsMessagingException() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -109,15 +104,13 @@ public void sendMessage_serviceThrowsError_throwsMessagingException() .thenThrow(new AmazonServiceException("wanted error")); // Assert - this.expectedException.expect(MessagingException.class); - this.expectedException.expectMessage("wanted error"); - - // Act - messageChannel.send(stringMessage); + assertThatThrownBy(() -> messageChannel.send(stringMessage)) + .isInstanceOf(MessagingException.class) + .hasMessageContaining("wanted error"); } @Test - public void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute() + void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -144,7 +137,7 @@ public void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribut } @Test - public void sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute() + void sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -170,7 +163,7 @@ public void sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute() } @Test - public void receiveMessage_withoutTimeout_returnsTextMessage() throws Exception { + void receiveMessage_withoutTimeout_returnsTextMessage() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") @@ -193,8 +186,7 @@ public void receiveMessage_withoutTimeout_returnsTextMessage() throws Exception } @Test - public void receiveMessage_withSpecifiedTimeout_returnsTextMessage() - throws Exception { + void receiveMessage_withSpecifiedTimeout_returnsTextMessage() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") @@ -217,7 +209,7 @@ public void receiveMessage_withSpecifiedTimeout_returnsTextMessage() } @Test - public void receiveMessage_withSpecifiedTimeout_returnsNull() throws Exception { + void receiveMessage_withSpecifiedTimeout_returnsNull() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") @@ -237,7 +229,7 @@ public void receiveMessage_withSpecifiedTimeout_returnsNull() throws Exception { } @Test - public void receiveMessage_withoutDefaultTimeout_returnsNull() throws Exception { + void receiveMessage_withoutDefaultTimeout_returnsNull() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") @@ -257,7 +249,7 @@ public void receiveMessage_withoutDefaultTimeout_returnsNull() throws Exception } @Test - public void receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders() + void receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -287,7 +279,7 @@ public void receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders() } @Test - public void sendMessage_withStringMessageHeader_shouldBeSentAsQueueMessageAttribute() + void sendMessage_withStringMessageHeader_shouldBeSentAsQueueMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -316,7 +308,7 @@ public void sendMessage_withStringMessageHeader_shouldBeSentAsQueueMessageAttrib } @Test - public void receiveMessage_withStringMessageHeader_shouldBeReceivedAsQueueMessageAttribute() + void receiveMessage_withStringMessageHeader_shouldBeReceivedAsQueueMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -346,7 +338,7 @@ public void receiveMessage_withStringMessageHeader_shouldBeReceivedAsQueueMessag } @Test - public void sendMessage_withNumericMessageHeaders_shouldBeSentAsQueueMessageAttributes() + void sendMessage_withNumericMessageHeaders_shouldBeSentAsQueueMessageAttributes() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -415,7 +407,7 @@ public void sendMessage_withNumericMessageHeaders_shouldBeSentAsQueueMessageAttr } @Test - public void receiveMessage_withNumericMessageHeaders_shouldBeReceivedAsQueueMessageAttributes() + void receiveMessage_withNumericMessageHeaders_shouldBeReceivedAsQueueMessageAttributes() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -495,13 +487,10 @@ public void receiveMessage_withNumericMessageHeaders_shouldBeReceivedAsQueueMess } @Test - public void receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException() + void receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "Cannot convert String [17] to target class [java.util.concurrent.atomic.AtomicInteger]"); HashMap messageAttributes = new HashMap<>(); AtomicInteger atomicInteger = new AtomicInteger(17); @@ -523,19 +512,17 @@ public void receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnExc PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); - // Act - messageChannel.receive(); + // Assert + assertThatThrownBy(messageChannel::receive) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining( + "Cannot convert String [17] to target class [java.util.concurrent.atomic.AtomicInteger]"); } @Test - public void receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException() + void receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); - this.expectedException.expect(MessagingException.class); - this.expectedException.expectMessage( - "Message attribute with value '12' and data type 'Number.class.not.Found' could not be converted" - + " into a Number because target class was not found."); HashMap messageAttributes = new HashMap<>(); messageAttributes.put("classNotFound", @@ -556,12 +543,15 @@ public void receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThro PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); - // Act - messageChannel.receive(); + // Assert + assertThatThrownBy(messageChannel::receive).isInstanceOf(MessagingException.class) + .hasMessageContaining( + "Message attribute with value '12' and data type 'Number.class.not.Found' could not be converted" + + " into a Number because target class was not found."); } @Test - public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() + void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -590,7 +580,7 @@ public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttri } @Test - public void receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute() + void receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -620,7 +610,7 @@ public void receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferM } @Test - public void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception { + void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, @@ -643,8 +633,7 @@ public void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exceptio } @Test - public void receiveMessage_withIdOfTypeString_IdShouldBeConvertedToUuid() - throws Exception { + void receiveMessage_withIdOfTypeString_IdShouldBeConvertedToUuid() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); UUID uuid = UUID.randomUUID(); @@ -675,7 +664,7 @@ public void receiveMessage_withIdOfTypeString_IdShouldBeConvertedToUuid() @Test @SuppressWarnings("unchecked") - public void sendMessage_withTimeout_sendsMessageAsyncAndReturnsTrueOnceFutureCompleted() + void sendMessage_withTimeout_sendsMessageAsyncAndReturnsTrueOnceFutureCompleted() throws Exception { // Arrange Future future = mock(Future.class); @@ -697,7 +686,7 @@ public void sendMessage_withTimeout_sendsMessageAsyncAndReturnsTrueOnceFutureCom @Test @SuppressWarnings("unchecked") - public void sendMessage_withSendMessageAsyncTakingMoreTimeThanSpecifiedTimeout_returnsFalse() + void sendMessage_withSendMessageAsyncTakingMoreTimeThanSpecifiedTimeout_returnsFalse() throws Exception { // Arrange Future future = mock(Future.class); @@ -718,7 +707,7 @@ public void sendMessage_withSendMessageAsyncTakingMoreTimeThanSpecifiedTimeout_r @Test @SuppressWarnings("unchecked") - public void sendMessage_withExecutionExceptionWhileSendingAsyncMessage_throwMessageDeliveryException() + void sendMessage_withExecutionExceptionWhileSendingAsyncMessage_throwMessageDeliveryException() throws Exception { // Arrange Future future = mock(Future.class); @@ -731,15 +720,13 @@ public void sendMessage_withExecutionExceptionWhileSendingAsyncMessage_throwMess "http://testQueue"); // Assert - this.expectedException.expect(MessageDeliveryException.class); - - // Act - queueMessageChannel.send(MessageBuilder.withPayload("Hello").build(), 1000); - + assertThatThrownBy(() -> queueMessageChannel + .send(MessageBuilder.withPayload("Hello").build(), 1000)) + .isInstanceOf(MessageDeliveryException.class); } @Test - public void sendMessage_withDelayHeader_shouldSetDelayOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() + void sendMessage_withDelayHeader_shouldSetDelayOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -766,7 +753,7 @@ public void sendMessage_withDelayHeader_shouldSetDelayOnSendMessageRequestAndNot } @Test - public void sendMessage_withoutDelayHeader_shouldNotSetDelayOnSendMessageRequestAndNotSetHeaderAsMessageAttribute() + void sendMessage_withoutDelayHeader_shouldNotSetDelayOnSendMessageRequestAndNotSetHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -792,7 +779,7 @@ public void sendMessage_withoutDelayHeader_shouldNotSetDelayOnSendMessageRequest } @Test - public void sendMessage_withGroupIdHeader_shouldSetGroupIdOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() + void sendMessage_withGroupIdHeader_shouldSetGroupIdOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); @@ -820,7 +807,7 @@ public void sendMessage_withGroupIdHeader_shouldSetGroupIdOnSendMessageRequestAn // @checkstyle:off @Test - public void sendMessage_withDeduplicationIdHeader_shouldSetDeduplicationIdOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() + void sendMessage_withDeduplicationIdHeader_shouldSetDeduplicationIdOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() throws Exception { // @checkstyle:on // Arrange diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java index 6fdb0e76c..f586069ef 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java @@ -28,7 +28,7 @@ import com.amazonaws.services.sqs.model.SendMessageRequest; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.cloud.aws.core.env.ResourceIdResolver; @@ -41,6 +41,7 @@ import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -49,21 +50,22 @@ /** * @author Alain Sahli */ -public class QueueMessagingTemplateTest { +class QueueMessagingTemplateTest { - @Test(expected = IllegalStateException.class) - public void send_withoutDefaultDestination_throwAnException() { + @Test + void send_withoutDefaultDestination_throwAnException() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); Message stringMessage = MessageBuilder.withPayload("message content") .build(); - queueMessagingTemplate.send(stringMessage); + assertThatThrownBy(() -> queueMessagingTemplate.send(stringMessage)) + .isInstanceOf(IllegalStateException.class); } @Test - public void send_withDefaultDestination_usesDefaultDestination() { + void send_withDefaultDestination_usesDefaultDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -81,7 +83,7 @@ public void send_withDefaultDestination_usesDefaultDestination() { } @Test - public void send_withDestination_usesDestination() { + void send_withDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -98,7 +100,7 @@ public void send_withDestination_usesDestination() { } @Test - public void send_withCustomDestinationResolveAndDestination_usesDestination() { + void send_withCustomDestinationResolveAndDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs, @@ -116,17 +118,18 @@ public void send_withCustomDestinationResolveAndDestination_usesDestination() { .isEqualTo("MYQUEUE"); } - @Test(expected = IllegalStateException.class) - public void receive_withoutDefaultDestination_throwsAnException() { + @Test + void receive_withoutDefaultDestination_throwsAnException() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); - queueMessagingTemplate.receive(); + assertThatThrownBy(queueMessagingTemplate::receive) + .isInstanceOf(IllegalStateException.class); } @Test - public void receive_withDefaultDestination_useDefaultDestination() { + void receive_withDefaultDestination_useDefaultDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -142,7 +145,7 @@ public void receive_withDefaultDestination_useDefaultDestination() { } @Test - public void receive_withDestination_usesDestination() { + void receive_withDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -156,17 +159,18 @@ public void receive_withDestination_usesDestination() { .isEqualTo("https://queue-url.com"); } - @Test(expected = IllegalStateException.class) - public void receiveAndConvert_withoutDefaultDestination_throwsAnException() { + @Test + void receiveAndConvert_withoutDefaultDestination_throwsAnException() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); - queueMessagingTemplate.receiveAndConvert(String.class); + assertThatThrownBy(() -> queueMessagingTemplate.receiveAndConvert(String.class)) + .isInstanceOf(IllegalStateException.class); } @Test - public void receiveAndConvert_withDefaultDestination_usesDefaultDestinationAndConvertsMessage() { + void receiveAndConvert_withDefaultDestination_usesDefaultDestinationAndConvertsMessage() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -178,7 +182,7 @@ public void receiveAndConvert_withDefaultDestination_usesDefaultDestinationAndCo } @Test - public void receiveAndConvert_withDestination_usesDestinationAndConvertsMessage() { + void receiveAndConvert_withDestination_usesDestinationAndConvertsMessage() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); @@ -190,7 +194,7 @@ public void receiveAndConvert_withDestination_usesDestinationAndConvertsMessage( } @Test - public void instantiation_withConverter_shouldAddItToTheCompositeConverter() { + void instantiation_withConverter_shouldAddItToTheCompositeConverter() { // Arrange SimpleMessageConverter simpleMessageConverter = new SimpleMessageConverter(); @@ -208,7 +212,7 @@ public void instantiation_withConverter_shouldAddItToTheCompositeConverter() { } @Test - public void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString() + void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString() throws IOException { // Arrange @@ -241,7 +245,7 @@ public void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shoul } @Test - public void instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types() + void instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types() throws IOException { // Arrange diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java index 874c4e5b0..8e0aa8ef5 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java @@ -26,7 +26,7 @@ import com.amazonaws.services.sns.model.MessageAttributeValue; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.model.PublishResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.messaging.Message; @@ -44,10 +44,10 @@ /** * @author Alain Sahli */ -public class TopicMessageChannelTest { +class TopicMessageChannelTest { @Test - public void sendMessage_validTextMessageAndSubject_returnsTrue() throws Exception { + void sendMessage_validTextMessageAndSubject_returnsTrue() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -67,8 +67,7 @@ public void sendMessage_validTextMessageAndSubject_returnsTrue() throws Exceptio } @Test - public void sendMessage_validTextMessageWithoutSubject_returnsTrue() - throws Exception { + void sendMessage_validTextMessageWithoutSubject_returnsTrue() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -87,8 +86,7 @@ public void sendMessage_validTextMessageWithoutSubject_returnsTrue() } @Test - public void sendMessage_validTextMessageAndTimeout_timeoutIsIgnored() - throws Exception { + void sendMessage_validTextMessageAndTimeout_timeoutIsIgnored() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -107,7 +105,7 @@ public void sendMessage_validTextMessageAndTimeout_timeoutIsIgnored() } @Test - public void sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute() + void sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -135,7 +133,7 @@ public void sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttrib } @Test - public void sendMessage_withNumericMessageHeaders_shouldBeSentAsTopicMessageAttributes() + void sendMessage_withNumericMessageHeaders_shouldBeSentAsTopicMessageAttributes() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -203,7 +201,7 @@ public void sendMessage_withNumericMessageHeaders_shouldBeSentAsTopicMessageAttr } @Test - public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() + void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -231,7 +229,7 @@ public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttri } @Test - public void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception { + void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); TopicMessageChannel messageChannel = new TopicMessageChannel(amazonSns, diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplateTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplateTest.java index b7a0b255b..6b686a0b4 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplateTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplateTest.java @@ -19,12 +19,12 @@ import java.util.Collections; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.springframework.messaging.Message; @@ -43,20 +43,20 @@ /** * @author Alain Sahli */ -@RunWith(MockitoJUnitRunner.class) -public class AbstractMessageChannelMessagingSendingTemplateTest { +@ExtendWith(MockitoExtension.class) +class AbstractMessageChannelMessagingSendingTemplateTest { @Mock private DestinationResolver destinationResolver; @SuppressWarnings("unchecked") - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { reset(this.destinationResolver); } @Test - public void send_WithDestinationNameAndMessage_shouldResolveTheDestinationAndSendTheMessage() + void send_WithDestinationNameAndMessage_shouldResolveTheDestinationAndSendTheMessage() throws Exception { // Arrange MessageSendingTemplateTest messageSendingTemplate = new MessageSendingTemplateTest( @@ -82,7 +82,7 @@ public void send_WithDestinationNameAndMessage_shouldResolveTheDestinationAndSen } @Test - public void convertAndSend_WithDestinationNameAndPayload_shouldResolveTheDestinationAndSendTheConvertedMessage() + void convertAndSend_WithDestinationNameAndPayload_shouldResolveTheDestinationAndSendTheConvertedMessage() throws Exception { // Arrange MessageSendingTemplateTest messageSendingTemplate = new MessageSendingTemplateTest( @@ -103,7 +103,7 @@ public void convertAndSend_WithDestinationNameAndPayload_shouldResolveTheDestina } @Test - public void convertAndSend_WithDestinationNamePayloadAndHeaders_shouldResolveTheDestinationAndSendTheConvertedMessage() + void convertAndSend_WithDestinationNamePayloadAndHeaders_shouldResolveTheDestinationAndSendTheConvertedMessage() throws Exception { // Arrange MessageSendingTemplateTest messageSendingTemplate = new MessageSendingTemplateTest( @@ -129,7 +129,7 @@ public void convertAndSend_WithDestinationNamePayloadAndHeaders_shouldResolveThe // @checkstyle:off @Test - public void convertAndSend_WithDestinationNamePayloadAndPostProcessor_shouldResolveTheDestinationSendTheConvertedMessageAndCallPostProcessor() + void convertAndSend_WithDestinationNamePayloadAndPostProcessor_shouldResolveTheDestinationSendTheConvertedMessageAndCallPostProcessor() throws Exception { // @checkstyle:on // Arrange @@ -159,7 +159,7 @@ public void convertAndSend_WithDestinationNamePayloadAndPostProcessor_shouldReso // @checkstyle:off @Test - public void convertAndSend_WithDestinationNamePayloadHeadersAndPostProcessor_shouldResolveTheDestinationSendTheConvertedMessageAndCallPostProcessor() + void convertAndSend_WithDestinationNamePayloadHeadersAndPostProcessor_shouldResolveTheDestinationSendTheConvertedMessageAndCallPostProcessor() // @checkstyle:on throws Exception { // Arrange @@ -192,7 +192,7 @@ public void convertAndSend_WithDestinationNamePayloadHeadersAndPostProcessor_sho } @Test - public void send_WithPayload_shouldUseDefaultDestination() throws Exception { + void send_WithPayload_shouldUseDefaultDestination() throws Exception { // Arrange MessageSendingTemplateTest messageSendingTemplate = new MessageSendingTemplateTest( this.destinationResolver); @@ -235,7 +235,7 @@ protected MessageChannel resolveMessageChannel( return this.messageChannel; } - public MessageChannelTest getMessageChannel() { + MessageChannelTest getMessageChannel() { return this.messageChannel; } @@ -257,7 +257,7 @@ public boolean send(Message message, long timeout) { return false; } - public Message getSentMessage() { + Message getSentMessage() { return this.sentMessage; } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/BaseNotificationMessageHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/BaseNotificationMessageHandlerMethodArgumentResolverTest.java index 756bc416c..b91643898 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/BaseNotificationMessageHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/BaseNotificationMessageHandlerMethodArgumentResolverTest.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.core.io.ClassPathResource; @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class BaseNotificationMessageHandlerMethodArgumentResolverTest { +class BaseNotificationMessageHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_SubScriptionMessage_createsObjectWithAllFields() + void resolveArgument_SubScriptionMessage_createsObjectWithAllFields() throws Exception { // Arrange AbstractNotificationMessageHandlerMethodArgumentResolver resolver = null; @@ -108,7 +108,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Test - public void resolveArgument_NotificationMessage_createsObjectWithAllFields() + void resolveArgument_NotificationMessage_createsObjectWithAllFields() throws Exception { // Arrange AbstractNotificationMessageHandlerMethodArgumentResolver resolver; diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java index c4b523819..c32566db1 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest.java @@ -17,9 +17,9 @@ package org.springframework.cloud.aws.messaging.endpoint; import com.amazonaws.services.sns.AmazonSNS; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Import; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -46,10 +46,10 @@ /** * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = Config.class) -public class ComplexNotificationEndpointControllerTest { +class ComplexNotificationEndpointControllerTest { @Autowired private WebApplicationContext context; @@ -62,13 +62,13 @@ public class ComplexNotificationEndpointControllerTest { private MockMvc mockMvc; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); } @Test - public void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfirmedThroughSubscriptionStatus() + void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfirmedThroughSubscriptionStatus() throws Exception { // Arrange byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( @@ -93,7 +93,7 @@ public void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfir // @checkstyle:off @Test - public void notification_notificationReceivedAsMessageWithComplexContent_notificationSubjectAndMessagePassedToAnnotatedControllerMethod() + void notification_notificationReceivedAsMessageWithComplexContent_notificationSubjectAndMessagePassedToAnnotatedControllerMethod() throws Exception { // @checkstyle:on // Arrange @@ -118,7 +118,7 @@ public void notification_notificationReceivedAsMessageWithComplexContent_notific } @Test - public void notification_unsubscribeConfirmationReceivedAsMessage_reSubscriptionCalledByController() + void notification_unsubscribeConfirmationReceivedAsMessage_reSubscriptionCalledByController() throws Exception { // Arrange byte[] notificationJsonContent = FileCopyUtils.copyToByteArray( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationTestController.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationTestController.java index b8f5b0862..ebfcce2d5 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationTestController.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationTestController.java @@ -31,7 +31,7 @@ */ @Controller @RequestMapping("/myComplexTopic") -public class ComplexNotificationTestController { +class ComplexNotificationTestController { private String subject; @@ -46,43 +46,43 @@ Person getMessage() { } @NotificationSubscriptionMapping - public void handleSubscriptionMessage(NotificationStatus status) throws IOException { + void handleSubscriptionMessage(NotificationStatus status) throws IOException { // We subscribe to start receive the message status.confirmSubscription(); } @NotificationMessageMapping - public void handleNotificationMessage(@NotificationSubject String subject, + void handleNotificationMessage(@NotificationSubject String subject, @NotificationMessage Person message) { this.subject = subject; this.message = message; } @NotificationUnsubscribeConfirmationMapping - public void handleUnsubscribeMessage(NotificationStatus status) { + void handleUnsubscribeMessage(NotificationStatus status) { // e.g. the client has been unsubscribed and we want to "re-subscribe" status.confirmSubscription(); } - public static class Person { + static class Person { private String firstName; private String lastName; - public String getFirstName() { + String getFirstName() { return this.firstName; } - public void setFirstName(String firstName) { + void setFirstName(String firstName) { this.firstName = firstName; } - public String getLastName() { + String getLastName() { return this.lastName; } - public void setLastName(String lastName) { + void setLastName(String lastName) { this.lastName = lastName; } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java index 71cf1919d..88ab4dde0 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationEndpointControllerTest.java @@ -17,9 +17,9 @@ package org.springframework.cloud.aws.messaging.endpoint; import com.amazonaws.services.sns.AmazonSNS; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Import; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -46,10 +46,10 @@ /** * @author Agim Emruli */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = Config.class) -public class NotificationEndpointControllerTest { +class NotificationEndpointControllerTest { @Autowired private WebApplicationContext context; @@ -62,13 +62,13 @@ public class NotificationEndpointControllerTest { private MockMvc mockMvc; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); } @Test - public void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfirmedThroughSubscriptionStatus() + void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfirmedThroughSubscriptionStatus() throws Exception { // Arrange byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( @@ -92,7 +92,7 @@ public void subscribe_subscriptionConfirmationRequestReceived_subscriptionConfir } @Test - public void notification_notificationReceivedAsMessage_notificationSubjectAndMessagePassedToAnnotatedControllerMethod() + void notification_notificationReceivedAsMessage_notificationSubjectAndMessagePassedToAnnotatedControllerMethod() throws Exception { // Arrange byte[] notificationJsonContent = FileCopyUtils.copyToByteArray( @@ -112,7 +112,7 @@ public void notification_notificationReceivedAsMessage_notificationSubjectAndMes } @Test - public void notification_unsubscribeConfirmationReceivedAsMessage_reSubscriptionCalledByController() + void notification_unsubscribeConfirmationReceivedAsMessage_reSubscriptionCalledByController() throws Exception { // Arrange byte[] notificationJsonContent = FileCopyUtils.copyToByteArray( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationMessageHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationMessageHandlerMethodArgumentResolverTest.java index d3740c7d9..6db1a8f27 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationMessageHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationMessageHandlerMethodArgumentResolverTest.java @@ -16,9 +16,7 @@ package org.springframework.cloud.aws.messaging.endpoint; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.core.io.ClassPathResource; @@ -28,19 +26,13 @@ import org.springframework.web.context.request.ServletWebRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class NotificationMessageHandlerMethodArgumentResolverTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class NotificationMessageHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { + void resolveArgument_wrongMessageType_reportsErrors() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "@NotificationMessage annotated parameters are only allowed"); - NotificationMessageHandlerMethodArgumentResolver resolver = new NotificationMessageHandlerMethodArgumentResolver(); byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( @@ -54,15 +46,16 @@ public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { "subscriptionMethod", NotificationStatus.class), 0); - // Act - resolver.resolveArgument(methodParameter, null, - new ServletWebRequest(servletRequest), null); - // Assert + assertThatThrownBy(() -> resolver.resolveArgument(methodParameter, null, + new ServletWebRequest(servletRequest), null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining( + "@NotificationMessage annotated parameters are only allowed"); } @Test - public void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() + void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() throws Exception { // Arrange NotificationMessageHandlerMethodArgumentResolver resolver = new NotificationMessageHandlerMethodArgumentResolver(); @@ -87,8 +80,7 @@ public void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() } @Test - public void supportsParameter_withIntegerParameterType_shouldReturnFalse() - throws Exception { + void supportsParameter_withIntegerParameterType_shouldReturnFalse() throws Exception { // Arrange NotificationMessageHandlerMethodArgumentResolver resolver = new NotificationMessageHandlerMethodArgumentResolver(); MethodParameter methodParameter = new MethodParameter( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationStatusHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationStatusHandlerMethodArgumentResolverTest.java index 6fb27de92..3565b68d3 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationStatusHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationStatusHandlerMethodArgumentResolverTest.java @@ -17,9 +17,7 @@ package org.springframework.cloud.aws.messaging.endpoint; import com.amazonaws.services.sns.AmazonSNS; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.core.io.ClassPathResource; @@ -29,21 +27,16 @@ import org.springframework.web.context.request.ServletWebRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -public class NotificationStatusHandlerMethodArgumentResolverTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class NotificationStatusHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { + void resolveArgument_wrongMessageType_reportsErrors() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("NotificationStatus is only available"); - AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationStatusHandlerMethodArgumentResolver resolver = new NotificationStatusHandlerMethodArgumentResolver( amazonSns); @@ -59,15 +52,16 @@ public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { "subscriptionMethod", NotificationStatus.class), 0); - // Act - resolver.resolveArgument(methodParameter, null, - new ServletWebRequest(servletRequest), null); - // Assert + assertThatThrownBy(() -> resolver.resolveArgument(methodParameter, null, + new ServletWebRequest(servletRequest), null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("NotificationStatus is only available"); + } @Test - public void resolveArgument_subscriptionRequest_createsValidSubscriptionStatus() + void resolveArgument_subscriptionRequest_createsValidSubscriptionStatus() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationSubjectHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationSubjectHandlerMethodArgumentResolverTest.java index c5598ff20..a3f62f177 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationSubjectHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationSubjectHandlerMethodArgumentResolverTest.java @@ -18,9 +18,7 @@ import java.lang.reflect.Method; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; import org.springframework.cloud.aws.messaging.config.annotation.NotificationSubject; @@ -32,19 +30,13 @@ import org.springframework.web.context.request.ServletWebRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class NotificationSubjectHandlerMethodArgumentResolverTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class NotificationSubjectHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { + void resolveArgument_wrongMessageType_reportsErrors() throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage( - "@NotificationMessage annotated parameters are only allowed"); - NotificationSubjectHandlerMethodArgumentResolver resolver = new NotificationSubjectHandlerMethodArgumentResolver(); byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( @@ -58,15 +50,16 @@ public void resolveArgument_wrongMessageType_reportsErrors() throws Exception { "subscriptionMethod", NotificationStatus.class), 0); - // Act - resolver.resolveArgument(methodParameter, null, - new ServletWebRequest(servletRequest), null); - // Assert + assertThatThrownBy(() -> resolver.resolveArgument(methodParameter, null, + new ServletWebRequest(servletRequest), null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining( + "@NotificationMessage annotated parameters are only allowed"); } @Test - public void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() + void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() throws Exception { // Arrange NotificationSubjectHandlerMethodArgumentResolver resolver = new NotificationSubjectHandlerMethodArgumentResolver(); @@ -91,8 +84,7 @@ public void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() } @Test - public void supportsParameter_withWrongParameterType_shouldReturnFalse() - throws Exception { + void supportsParameter_withWrongParameterType_shouldReturnFalse() throws Exception { // Arrange NotificationSubjectHandlerMethodArgumentResolver resolver = new NotificationSubjectHandlerMethodArgumentResolver(); Method methodWithWrongParameterType = this.getClass() diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationTestController.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationTestController.java index 34f07bac7..292e8806d 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationTestController.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/NotificationTestController.java @@ -31,7 +31,7 @@ */ @Controller @RequestMapping("/mySampleTopic") -public class NotificationTestController { +class NotificationTestController { private String subject; @@ -46,20 +46,20 @@ String getMessage() { } @NotificationSubscriptionMapping - public void handleSubscriptionMessage(NotificationStatus status) throws IOException { + void handleSubscriptionMessage(NotificationStatus status) throws IOException { // We subscribe to start receive the message status.confirmSubscription(); } @NotificationMessageMapping - public void handleNotificationMessage(@NotificationSubject String subject, + void handleNotificationMessage(@NotificationSubject String subject, @NotificationMessage String message) { this.subject = subject; this.message = message; } @NotificationUnsubscribeConfirmationMapping - public void handleUnsubscribeMessage(NotificationStatus status) { + void handleUnsubscribeMessage(NotificationStatus status) { // e.g. the client has been unsubscribed and we want to "re-subscribe" status.confirmSubscription(); } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/config/NotificationHandlerMethodArgumentResolverFactoryBeanTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/config/NotificationHandlerMethodArgumentResolverFactoryBeanTest.java index 331742155..c817330d9 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/config/NotificationHandlerMethodArgumentResolverFactoryBeanTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/endpoint/config/NotificationHandlerMethodArgumentResolverFactoryBeanTest.java @@ -17,23 +17,19 @@ package org.springframework.cloud.aws.messaging.endpoint.config; import com.amazonaws.services.sns.AmazonSNS; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolverComposite; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; -public class NotificationHandlerMethodArgumentResolverFactoryBeanTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class NotificationHandlerMethodArgumentResolverFactoryBeanTest { @Test - public void getObjectType_defaultConfiguration_returnsHandlerMethodArgumentResolverType() + void getObjectType_defaultConfiguration_returnsHandlerMethodArgumentResolverType() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -48,7 +44,7 @@ public void getObjectType_defaultConfiguration_returnsHandlerMethodArgumentResol } @Test - public void getObject_withDefaultConfiguration_createCompositeResolverWithAllDelegatedResolvers() + void getObject_withDefaultConfiguration_createCompositeResolverWithAllDelegatedResolvers() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); @@ -66,16 +62,13 @@ public void getObject_withDefaultConfiguration_createCompositeResolverWithAllDel } @Test - public void createInstance_withNullSnsClient_reportsError() throws Exception { - // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("not be null"); - - // Act - // noinspection ResultOfObjectAllocationIgnored - new NotificationHandlerMethodArgumentResolverFactoryBean(null); - + void createInstance_withNullSnsClient_reportsError() throws Exception { // Assert + assertThatThrownBy( + () -> new NotificationHandlerMethodArgumentResolverFactoryBean(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("not be null"); + } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/MessageListenerContainerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/MessageListenerContainerTest.java index bed1d4aeb..ae0ba8a0e 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/MessageListenerContainerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/MessageListenerContainerTest.java @@ -25,9 +25,7 @@ import com.amazonaws.services.sqs.model.GetQueueAttributesResult; import com.amazonaws.services.sqs.model.GetQueueUrlRequest; import com.amazonaws.services.sqs.model.GetQueueUrlResult; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.slf4j.Logger; @@ -40,6 +38,7 @@ import org.springframework.messaging.core.DestinationResolver; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -52,13 +51,10 @@ * @author Alain Sahli * @since 1.0 */ -public class MessageListenerContainerTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class MessageListenerContainerTest { @Test - public void testAfterPropertiesSetIsSettingActiveFlag() throws Exception { + void testAfterPropertiesSetIsSettingActiveFlag() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -69,30 +65,28 @@ public void testAfterPropertiesSetIsSettingActiveFlag() throws Exception { } @Test - public void testAmazonSqsNullThrowsException() throws Exception { - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage("amazonSqs must not be null"); - + void testAmazonSqsNullThrowsException() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setMessageHandler(mock(QueueMessageHandler.class)); - container.afterPropertiesSet(); + assertThatThrownBy(container::afterPropertiesSet) + .isInstanceOf(IllegalStateException.class) + .hasMessage("amazonSqs must not be null"); } @Test - public void testMessageHandlerNullThrowsException() throws Exception { - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage("messageHandler must not be null"); - + void testMessageHandlerNullThrowsException() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); - container.afterPropertiesSet(); + assertThatThrownBy(container::afterPropertiesSet) + .isInstanceOf(IllegalStateException.class) + .hasMessage("messageHandler must not be null"); } @Test - public void testDestinationResolverIsCreatedIfNull() throws Exception { + void testDestinationResolverIsCreatedIfNull() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -107,7 +101,7 @@ public void testDestinationResolverIsCreatedIfNull() throws Exception { } @Test - public void testDisposableBeanResetActiveFlag() throws Exception { + void testDisposableBeanResetActiveFlag() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -120,7 +114,7 @@ public void testDisposableBeanResetActiveFlag() throws Exception { } @Test - public void testSetAndGetBeanName() throws Exception { + void testSetAndGetBeanName() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setBeanName("test"); @@ -128,7 +122,7 @@ public void testSetAndGetBeanName() throws Exception { } @Test - public void testCustomDestinationResolverSet() throws Exception { + void testCustomDestinationResolverSet() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -144,7 +138,7 @@ public void testCustomDestinationResolverSet() throws Exception { } @Test - public void testMaxNumberOfMessages() throws Exception { + void testMaxNumberOfMessages() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); assertThat(container.getMaxNumberOfMessages()).isNull(); container.setMaxNumberOfMessages(23); @@ -152,7 +146,7 @@ public void testMaxNumberOfMessages() throws Exception { } @Test - public void testVisibilityTimeout() throws Exception { + void testVisibilityTimeout() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); assertThat(container.getVisibilityTimeout()).isNull(); container.setVisibilityTimeout(32); @@ -160,7 +154,7 @@ public void testVisibilityTimeout() throws Exception { } @Test - public void testWaitTimeout() throws Exception { + void testWaitTimeout() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); assertThat(container.getWaitTimeOut()).isEqualTo(new Integer(20)); container.setWaitTimeOut(42); @@ -168,7 +162,7 @@ public void testWaitTimeout() throws Exception { } @Test - public void testIsAutoStartup() throws Exception { + void testIsAutoStartup() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); assertThat(container.isAutoStartup()).isTrue(); container.setAutoStartup(false); @@ -176,7 +170,7 @@ public void testIsAutoStartup() throws Exception { } @Test - public void testGetAndSetPhase() throws Exception { + void testGetAndSetPhase() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); assertThat(container.getPhase()).isEqualTo(Integer.MAX_VALUE); container.setPhase(23); @@ -184,7 +178,7 @@ public void testGetAndSetPhase() throws Exception { } @Test - public void testIsActive() throws Exception { + void testIsActive() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @@ -208,7 +202,7 @@ public void testIsActive() throws Exception { } @Test - public void receiveMessageRequests_withOneElement_created() throws Exception { + void receiveMessageRequests_withOneElement_created() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @@ -246,7 +240,7 @@ public void receiveMessageRequests_withOneElement_created() throws Exception { } @Test - public void receiveMessageRequests_withMultipleElements_created() throws Exception { + void receiveMessageRequests_withMultipleElements_created() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @@ -296,7 +290,7 @@ public void receiveMessageRequests_withMultipleElements_created() throws Excepti } @Test - public void testStartCallsDoStartMethod() throws Exception { + void testStartCallsDoStartMethod() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @@ -332,7 +326,7 @@ protected void doStop() { } @Test - public void testStopCallsDoStopMethod() throws Exception { + void testStopCallsDoStopMethod() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @@ -369,7 +363,7 @@ protected void doStop() { } @Test - public void testStopCallsDoStopMethodWithRunnable() throws Exception { + void testStopCallsDoStopMethodWithRunnable() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @@ -406,7 +400,7 @@ protected void doStop() { } @Test - public void doDestroy_WhenContainerIsDestroyed_shouldBeCalled() throws Exception { + void doDestroy_WhenContainerIsDestroyed_shouldBeCalled() throws Exception { // Arrange DestroyAwareAbstractMessageListenerContainer abstractMessageListenerContainer; abstractMessageListenerContainer = new DestroyAwareAbstractMessageListenerContainer(); @@ -419,7 +413,7 @@ public void doDestroy_WhenContainerIsDestroyed_shouldBeCalled() throws Exception } @Test - public void receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest() + void receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest() throws Exception { // Arrange AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); @@ -487,7 +481,7 @@ private static class MessageListener { @SuppressWarnings({ "UnusedDeclaration", "EmptyMethod" }) @SqsListener("testQueue") - public void listenerMethod(String ignore) { + void listenerMethod(String ignore) { } @@ -497,7 +491,7 @@ private static class AnotherMessageListener { @SuppressWarnings({ "UnusedDeclaration", "EmptyMethod" }) @SqsListener("anotherTestQueue") - public void listenerMethod(String ignore) { + void listenerMethod(String ignore) { } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java index 6f55b1aef..7ebed4613 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandlerTest.java @@ -30,11 +30,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.LoggerFactory; import org.springframework.beans.MutablePropertyValues; @@ -70,7 +70,7 @@ import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -87,14 +87,14 @@ * @author Maciej Walkowiak * @since 1.0 */ -@RunWith(MockitoJUnitRunner.class) -public class QueueMessageHandlerTest { +@ExtendWith(MockitoExtension.class) +class QueueMessageHandlerTest { @Mock private DestinationResolvingMessageSendingOperations messageTemplate; - @Before - public void setUp() { + @BeforeEach + void setUp() { // noinspection RedundantArrayCreation to avoid unchecked generic array creation // for varargs parameter with Java 8. reset(new DestinationResolvingMessageSendingOperations[] { @@ -102,7 +102,7 @@ public void setUp() { } @Test - public void receiveMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessage() { + void receiveMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessage() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class); @@ -120,7 +120,7 @@ public void receiveMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvoke } @Test - public void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted() { + void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted() { ApplicationContext applicationContext = new AnnotationConfigApplicationContext( QueueMessageHandlerWithJacksonConfiguration.class); @@ -144,7 +144,7 @@ public void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverte // @checkstyle:off @Test - public void receiveAndReplyMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessageAndReplySentBackToSendToDestination() { + void receiveAndReplyMessage_methodAnnotatedWithSqsListenerAnnotation_methodInvokedForIncomingMessageAndReplySentBackToSendToDestination() { // @checkstyle:on StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("incomingMessageHandler", @@ -177,7 +177,7 @@ private AbstractBeanDefinition getQueueMessageHandlerBeanDefinition() { } @Test - public void receiveAndReplayMessage_withExceptionThrownInSendTo_shouldCallExceptionHandler() { + void receiveAndReplayMessage_withExceptionThrownInSendTo_shouldCallExceptionHandler() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("incomingMessageHandler", @@ -208,7 +208,7 @@ public void receiveAndReplayMessage_withExceptionThrownInSendTo_shouldCallExcept } @Test - public void receiveMessage_methodAnnotatedWithSqsListenerContainingMultipleQueueNames_methodInvokedForEachQueueName() { + void receiveMessage_methodAnnotatedWithSqsListenerContainingMultipleQueueNames_methodInvokedForEachQueueName() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton( "incomingMessageHandlerWithMultipleQueueNames", @@ -236,7 +236,7 @@ public void receiveMessage_methodAnnotatedWithSqsListenerContainingMultipleQueue } @Test - public void receiveMessage_methodAnnotatedWithSqsListenerContainingExpression_methodInvokedOnResolvedExpression() { + void receiveMessage_methodAnnotatedWithSqsListenerContainingExpression_methodInvokedOnResolvedExpression() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getEnvironment().getPropertySources() @@ -266,7 +266,7 @@ public void receiveMessage_methodAnnotatedWithSqsListenerContainingExpression_me } @Test - public void receiveMessage_methodAnnotatedWithSqsListenerContainingPlaceholder_methodInvokedOnResolvedPlaceholder() { + void receiveMessage_methodAnnotatedWithSqsListenerContainingPlaceholder_methodInvokedOnResolvedPlaceholder() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getEnvironment().getPropertySources() @@ -299,7 +299,7 @@ public void receiveMessage_methodAnnotatedWithSqsListenerContainingPlaceholder_m } @Test - public void receiveMessage_withHeaderAnnotationAsArgument_shouldReceiveRequestedHeader() { + void receiveMessage_withHeaderAnnotationAsArgument_shouldReceiveRequestedHeader() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("messageHandlerWithHeaderAnnotation", @@ -324,7 +324,7 @@ public void receiveMessage_withHeaderAnnotationAsArgument_shouldReceiveRequested } @Test - public void receiveMessage_withWrongHeaderAnnotationValueAsArgument_shouldReceiveNullAsHeaderValue() { + void receiveMessage_withWrongHeaderAnnotationValueAsArgument_shouldReceiveNullAsHeaderValue() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("messageHandlerWithHeaderAnnotation", @@ -349,7 +349,7 @@ public void receiveMessage_withWrongHeaderAnnotationValueAsArgument_shouldReceiv } @Test - public void receiveMessage_withHeadersAsArgumentAnnotation_shouldReceiveAllHeaders() { + void receiveMessage_withHeadersAsArgumentAnnotation_shouldReceiveAllHeaders() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("messageHandlerWithHeadersAnnotation", @@ -378,7 +378,7 @@ public void receiveMessage_withHeadersAsArgumentAnnotation_shouldReceiveAllHeade } @Test - public void receiveMessage_withCustomArgumentResolvers_shouldCallThemBeforeTheDefaultOnes() + void receiveMessage_withCustomArgumentResolvers_shouldCallThemBeforeTheDefaultOnes() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -412,7 +412,7 @@ public void receiveMessage_withCustomArgumentResolvers_shouldCallThemBeforeTheDe } @Test - public void receiveMessage_withCustomReturnValueHandlers_shouldCallThemBeforeTheDefaultOnes() + void receiveMessage_withCustomReturnValueHandlers_shouldCallThemBeforeTheDefaultOnes() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -446,7 +446,7 @@ public void receiveMessage_withCustomReturnValueHandlers_shouldCallThemBeforeThe } @Test - public void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() { + void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("notificationMessageReceiver", @@ -476,7 +476,7 @@ public void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() } @Test - public void getMappingForMethod_methodWithEmptySqsListenerValue_shouldReturnNull() + void getMappingForMethod_methodWithEmptySqsListenerValue_shouldReturnNull() throws Exception { // Arrange QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); @@ -492,7 +492,7 @@ public void getMappingForMethod_methodWithEmptySqsListenerValue_shouldReturnNull } @Test - public void getMappingForMethod_methodWithMessageMappingAnnotation_shouldReturnMappingInformation() + void getMappingForMethod_methodWithMessageMappingAnnotation_shouldReturnMappingInformation() throws Exception { // Arrange QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); @@ -511,7 +511,7 @@ public void getMappingForMethod_methodWithMessageMappingAnnotation_shouldReturnM } @Test - public void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTypeAcknowledgment_warningMustBeLogged() + void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTypeAcknowledgment_warningMustBeLogged() throws Exception { // Arrange QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); @@ -542,7 +542,7 @@ public void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTyp // @checkstyle:off @Test - public void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_shouldMapMethodForEveryQueueNameReturnedByExpression() + void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_shouldMapMethodForEveryQueueNameReturnedByExpression() throws Exception { // @checkstyle:on // Arrange @@ -568,7 +568,7 @@ public void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_ } @Test - public void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustBeLogged() { + void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustBeLogged() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("sqsListenerWithoutMessageExceptionHandler", @@ -587,15 +587,12 @@ public void processHandlerMethodException_invocableHandlerMethodNotAvailable_err appender.setContext(log.getLoggerContext()); // Act - try { - messageHandler.handleMessage(MessageBuilder.withPayload("testContent") - .setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive") - .build()); - fail(); - } - catch (MessagingException e) { - // ignore - } + assertThatThrownBy( + () -> messageHandler + .handleMessage(MessageBuilder.withPayload("testContent") + .setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, + "receive") + .build())).isInstanceOf(MessagingException.class); // Assert assertThat(appender.list).hasSize(1); @@ -702,7 +699,7 @@ public static class DummyKeyValueHolder { private final String value; - public DummyKeyValueHolder(@JsonProperty("key") String key, + DummyKeyValueHolder(@JsonProperty("key") String key, @JsonProperty("value") String value) { this.key = key; this.value = value; diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SendToHandlerMethodReturnValueHandlerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SendToHandlerMethodReturnValueHandlerTest.java index 14c995b67..34add15fa 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SendToHandlerMethodReturnValueHandlerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SendToHandlerMethodReturnValueHandlerTest.java @@ -18,12 +18,10 @@ import java.lang.reflect.Method; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; @@ -36,6 +34,7 @@ import org.springframework.mock.env.MockPropertySource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; @@ -45,18 +44,14 @@ * @author Alain Sahli * @author Agim Emruli */ -@RunWith(MockitoJUnitRunner.class) -public class SendToHandlerMethodReturnValueHandlerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +@ExtendWith(MockitoExtension.class) +class SendToHandlerMethodReturnValueHandlerTest { @Mock private DestinationResolvingMessageSendingOperations messageTemplate; @Test - public void supportsReturnType_methodAnnotatedWithSendTo_trueIsReturned() - throws Exception { + void supportsReturnType_methodAnnotatedWithSendTo_trueIsReturned() throws Exception { // Arrange SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler; sendToHandlerMethodReturnValueHandler = new SendToHandlerMethodReturnValueHandler( @@ -73,7 +68,7 @@ public void supportsReturnType_methodAnnotatedWithSendTo_trueIsReturned() } @Test - public void supportsReturnType_methodWithoutSendToAnnotation_falseIsReturned() + void supportsReturnType_methodWithoutSendToAnnotation_falseIsReturned() throws Exception { // Arrange SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler; @@ -92,7 +87,7 @@ public void supportsReturnType_methodWithoutSendToAnnotation_falseIsReturned() } @Test - public void supportsReturnType_methodWithSendToAnnotationWithoutValue_trueIsReturned() + void supportsReturnType_methodWithSendToAnnotationWithoutValue_trueIsReturned() throws Exception { // Arrange SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler; @@ -111,26 +106,24 @@ public void supportsReturnType_methodWithSendToAnnotationWithoutValue_trueIsRetu } @Test - public void handleReturnValue_withNullMessageTemplate_exceptionIsThrown() - throws Exception { + void handleReturnValue_withNullMessageTemplate_exceptionIsThrown() throws Exception { // Arrange - this.expectedException.expect(IllegalStateException.class); - this.expectedException.expectMessage( - "A messageTemplate must be set to handle the return value."); - Method validSendToMethod = this.getClass().getDeclaredMethod("validSendToMethod"); MethodParameter methodParameter = new MethodParameter(validSendToMethod, -1); SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler; sendToHandlerMethodReturnValueHandler = new SendToHandlerMethodReturnValueHandler( null); - // Act - sendToHandlerMethodReturnValueHandler.handleReturnValue("Return me!", - methodParameter, MessageBuilder.withPayload("Nothing").build()); + // Assert + assertThatThrownBy(() -> sendToHandlerMethodReturnValueHandler.handleReturnValue( + "Return me!", methodParameter, + MessageBuilder.withPayload("Nothing").build())) + .isInstanceOf(IllegalStateException.class).hasMessage( + "A messageTemplate must be set to handle the return value."); } @Test - public void handleReturnValue_withNullReturnValue_NoMessageTemplateIsCalled() + void handleReturnValue_withNullReturnValue_NoMessageTemplateIsCalled() throws Exception { // Arrange Method validSendToMethod = this.getClass().getDeclaredMethod("validSendToMethod"); @@ -148,7 +141,7 @@ public void handleReturnValue_withNullReturnValue_NoMessageTemplateIsCalled() } @Test - public void handleReturnValue_withAMessageTemplateAndAValidMethodWithDestination_templateIsCalled() + void handleReturnValue_withAMessageTemplateAndAValidMethodWithDestination_templateIsCalled() throws Exception { // Arrange Method validSendToMethod = this.getClass().getDeclaredMethod("validSendToMethod"); @@ -167,7 +160,7 @@ public void handleReturnValue_withAMessageTemplateAndAValidMethodWithDestination } @Test - public void handleReturnValue_withExpressionInSendToName_templateIsCalled() + void handleReturnValue_withExpressionInSendToName_templateIsCalled() throws Exception { // Arrange Method validSendToMethod = this.getClass().getDeclaredMethod("expressionMethod"); @@ -196,7 +189,7 @@ public void handleReturnValue_withExpressionInSendToName_templateIsCalled() } @Test - public void handleReturnValue_withPlaceHolderInSendToName_templateIsCalled() + void handleReturnValue_withPlaceHolderInSendToName_templateIsCalled() throws Exception { // Arrange Method validSendToMethod = this.getClass().getDeclaredMethod("placeHolderMethod"); @@ -231,7 +224,7 @@ public void handleReturnValue_withPlaceHolderInSendToName_templateIsCalled() // @checkstyle:off @Test - public void handleReturnValue_withAMessageTemplateAndAValidMethodWithoutDestination_templateIsCalled() + void handleReturnValue_withAMessageTemplateAndAValidMethodWithoutDestination_templateIsCalled() throws Exception { // @checkstyle:on // Arrange diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainerTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainerTest.java index 9b813c5d0..a8ecf15db 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainerTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/SimpleMessageListenerContainerTest.java @@ -40,10 +40,8 @@ import com.amazonaws.services.sqs.model.QueueAttributeName; import com.amazonaws.services.sqs.model.ReceiveMessageRequest; import com.amazonaws.services.sqs.model.ReceiveMessageResult; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.stubbing.Answer; @@ -67,6 +65,7 @@ import org.springframework.util.StopWatch; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -84,10 +83,7 @@ * @author Alain Sahli * @since 1.0 */ -public class SimpleMessageListenerContainerTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class SimpleMessageListenerContainerTest { @Captor private ArgumentCaptor> stringMessageCaptor; @@ -139,13 +135,13 @@ private static void mockGetQueueUrl(AmazonSQSAsync sqs, String queueName, .thenReturn(new GetQueueUrlResult().withQueueUrl(queueUrl)); } - @Before - public void setUp() { + @BeforeEach + void setUp() { initMocks(this); } @Test - public void testWithDefaultTaskExecutorAndNoBeanName() throws Exception { + void testWithDefaultTaskExecutorAndNoBeanName() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -161,7 +157,7 @@ public void testWithDefaultTaskExecutorAndNoBeanName() throws Exception { } @Test - public void testWithDefaultTaskExecutorAndBeanName() throws Exception { + void testWithDefaultTaskExecutorAndBeanName() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -176,7 +172,7 @@ public void testWithDefaultTaskExecutorAndBeanName() throws Exception { } @Test - public void testWithDefaultTaskExecutorAndOneHandler() throws Exception { + void testWithDefaultTaskExecutorAndOneHandler() throws Exception { int testedMaxNumberOfMessages = 10; Map messageHandlerMethods = Collections @@ -211,7 +207,7 @@ public void testWithDefaultTaskExecutorAndOneHandler() throws Exception { } @Test - public void testCustomTaskExecutor() throws Exception { + void testCustomTaskExecutor() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); container.setTaskExecutor(taskExecutor); @@ -225,7 +221,7 @@ public void testCustomTaskExecutor() throws Exception { } @Test - public void testSimpleReceiveMessage() throws Exception { + void testSimpleReceiveMessage() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); AmazonSQSAsync sqs = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @@ -275,7 +271,7 @@ public void handleMessage(org.springframework.messaging.Message message) } @Test - public void testContainerDoesNotProcessMessageAfterBeingStopped() throws Exception { + void testContainerDoesNotProcessMessageAfterBeingStopped() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); container.setTaskExecutor(taskExecutor); @@ -311,7 +307,7 @@ public void handleMessage(org.springframework.messaging.Message message) } @Test - public void listener_withMultipleMessageHandlers_shouldBeCalled() throws Exception { + void listener_withMultipleMessageHandlers_shouldBeCalled() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(2); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer() { @@ -375,7 +371,7 @@ protected void executeMessage( } @Test - public void messageExecutor_withMessageWithAttributes_shouldPassThemAsHeaders() + void messageExecutor_withMessageWithAttributes_shouldPassThemAsHeaders() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -434,7 +430,7 @@ protected void executeMessage( } @Test - public void doDestroy_whenContainerCallsDestroy_DestroysDefaultTaskExecutor() + void doDestroy_whenContainerCallsDestroy_DestroysDefaultTaskExecutor() throws Exception { // Arrange SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer(); @@ -454,7 +450,7 @@ public void doDestroy_whenContainerCallsDestroy_DestroysDefaultTaskExecutor() } @Test - public void afterPropertiesSet_whenCalled_taskExecutorIsActive() throws Exception { + void afterPropertiesSet_whenCalled_taskExecutorIsActive() throws Exception { // Arrange SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); AmazonSQSAsync sqs = mock(AmazonSQSAsync.class, withSettings().stubOnly()); @@ -472,7 +468,7 @@ public void afterPropertiesSet_whenCalled_taskExecutorIsActive() throws Exceptio } @Test - public void messageExecutor_messageWithMimeTypeMessageAttribute_shouldSetItAsHeader() + void messageExecutor_messageWithMimeTypeMessageAttribute_shouldSetItAsHeader() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -537,7 +533,7 @@ protected void executeMessage( } @Test - public void queueMessageHandler_withJavaConfig_shouldScanTheListenerMethods() { + void queueMessageHandler_withJavaConfig_shouldScanTheListenerMethods() { // Arrange & Act AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( SqsTestConfig.class, TestMessageListener.class); @@ -551,7 +547,7 @@ public void queueMessageHandler_withJavaConfig_shouldScanTheListenerMethods() { } @Test - public void executeMessage_successfulExecution_shouldRemoveMessageFromQueue() + void executeMessage_successfulExecution_shouldRemoveMessageFromQueue() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -600,7 +596,7 @@ protected void executeMessage( } @Test - public void executeMessage_executionThrowsExceptionAndQueueHasAllDeletionPolicy_shouldRemoveMessageFromQueue() + void executeMessage_executionThrowsExceptionAndQueueHasAllDeletionPolicy_shouldRemoveMessageFromQueue() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -663,7 +659,7 @@ protected void executeMessage( } @Test - public void executeMessage_executionThrowsExceptionAndQueueHasRedrivePolicy_shouldNotRemoveMessageFromQueue() + void executeMessage_executionThrowsExceptionAndQueueHasRedrivePolicy_shouldNotRemoveMessageFromQueue() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -726,7 +722,7 @@ protected void executeMessage( } @Test - public void doStop_containerNotRunning_shouldNotThrowAnException() throws Exception { + void doStop_containerNotRunning_shouldNotThrowAnException() throws Exception { // Arrange SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); @@ -739,8 +735,7 @@ public void doStop_containerNotRunning_shouldNotThrowAnException() throws Except } @Test - public void receiveMessage_throwsAnException_operationShouldBeRetried() - throws Exception { + void receiveMessage_throwsAnException_operationShouldBeRetried() throws Exception { // Arrange Level previous = disableLogging(); @@ -791,7 +786,7 @@ public void handleMessage(org.springframework.messaging.Message message) } @Test - public void receiveMessage_withMessageListenerMethodAndNeverDeletionPolicy_waitsForAcknowledgmentBeforeDeletion() + void receiveMessage_withMessageListenerMethodAndNeverDeletionPolicy_waitsForAcknowledgmentBeforeDeletion() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -852,7 +847,7 @@ protected void executeMessage( } @Test - public void receiveMessage_withMessageListenerMethodAndVisibilityProlonging_callsChangeMessageVisibility() + void receiveMessage_withMessageListenerMethodAndVisibilityProlonging_callsChangeMessageVisibility() throws Exception { // Arrange CountDownLatch countDownLatch = new CountDownLatch(1); @@ -912,7 +907,7 @@ protected void executeMessage( } @Test - public void executeMessage_withDifferentDeletionPolicies_shouldActAccordingly() + void executeMessage_withDifferentDeletionPolicies_shouldActAccordingly() throws Exception { // Arrange Level previous = disableLogging(); @@ -1000,8 +995,7 @@ public void executeMessage_withDifferentDeletionPolicies_shouldActAccordingly() } @Test - public void stop_withALogicalQueueName_mustStopOnlyTheSpecifiedQueue() - throws Exception { + void stop_withALogicalQueueName_mustStopOnlyTheSpecifiedQueue() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("testMessageListener", @@ -1051,7 +1045,7 @@ public void stop_withALogicalQueueName_mustStopOnlyTheSpecifiedQueue() } @Test - public void stopAndStart_withContainerHavingARunningQueue_shouldRestartTheSpecifiedQueue() + void stopAndStart_withContainerHavingARunningQueue_shouldRestartTheSpecifiedQueue() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -1100,36 +1094,34 @@ public void stopAndStart_withContainerHavingARunningQueue_shouldRestartTheSpecif } @Test - public void stop_withQueueNameThatDoesNotExist_throwsAnException() throws Exception { + void stop_withQueueNameThatDoesNotExist_throwsAnException() throws Exception { // Arrange SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); container.setMessageHandler(new QueueMessageHandler()); container.afterPropertiesSet(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("foo"); - // Act - container.stop("foo"); + // Assert + assertThatThrownBy(() -> container.stop("foo")) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("foo"); } @Test - public void start_withQueueNameThatDoesNotExist_throwAnException() throws Exception { + void start_withQueueNameThatDoesNotExist_throwAnException() throws Exception { // Arrange SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly())); container.setMessageHandler(new QueueMessageHandler()); container.afterPropertiesSet(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("bar"); - // Act - container.start("bar"); + // Assert + assertThatThrownBy(() -> container.start("bar")) + .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("bar"); } @Test - public void start_withAQueueNameThatIsAlreadyRunning_shouldNotStartTheQueueAgainAndIgnoreTheCall() + void start_withAQueueNameThatIsAlreadyRunning_shouldNotStartTheQueueAgainAndIgnoreTheCall() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -1170,7 +1162,7 @@ public void start_withAQueueNameThatIsAlreadyRunning_shouldNotStartTheQueueAgain } @Test - public void stop_withAQueueNameThatIsNotRunning_shouldNotStopTheQueueAgainAndIgnoreTheCall() + void stop_withAQueueNameThatIsNotRunning_shouldNotStopTheQueueAgainAndIgnoreTheCall() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -1206,7 +1198,7 @@ public void stop_withAQueueNameThatIsNotRunning_shouldNotStopTheQueueAgainAndIgn } @Test - public void setQueueStopTimeout_withNotDefaultTimeout_mustBeUsedWhenStoppingAQueue() + void setQueueStopTimeout_withNotDefaultTimeout_mustBeUsedWhenStoppingAQueue() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -1256,7 +1248,7 @@ public void setQueueStopTimeout_withNotDefaultTimeout_mustBeUsedWhenStoppingAQue } @Test - public void stop_withContainerHavingMultipleQueuesRunning_shouldStopQueuesInParallel() + void stop_withContainerHavingMultipleQueuesRunning_shouldStopQueuesInParallel() throws Exception { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); @@ -1377,7 +1369,7 @@ public ReceiveMessageResult receiveMessage( } } - public void setReceiveMessageEnabled(boolean receiveMessageEnabled) { + void setReceiveMessageEnabled(boolean receiveMessageEnabled) { this.receiveMessageEnabled = receiveMessageEnabled; } @@ -1396,11 +1388,11 @@ private void handleMessage(String message) { this.countDownLatch.countDown(); } - public String getMessage() { + String getMessage() { return this.message; } - public CountDownLatch getCountDownLatch() { + CountDownLatch getCountDownLatch() { return this.countDownLatch; } @@ -1416,7 +1408,7 @@ private void handleMessage(String message) { this.message = message; } - public String getMessage() { + String getMessage() { return this.message; } @@ -1433,7 +1425,7 @@ private void handleMessage(String message) { @RuntimeUse @MessageExceptionHandler(RuntimeException.class) - public void handle() { + void handle() { // Empty body just to avoid unnecessary log output because no exception // handler was found. } @@ -1452,7 +1444,7 @@ private void handleMessage(String message) { @RuntimeUse @MessageExceptionHandler(RuntimeException.class) - public void handle() { + void handle() { // Empty body just to avoid unnecessary log output because no exception // handler was found. } @@ -1464,7 +1456,7 @@ public void handle() { protected static class SqsTestConfig { @Bean - public AmazonSQSAsync amazonSQS() { + AmazonSQSAsync amazonSQS() { AmazonSQSAsync mockAmazonSQS = mock(AmazonSQSAsync.class, withSettings().stubOnly()); mockGetQueueUrl(mockAmazonSQS, "testQueue", "http://testQueue.amazonaws.com"); @@ -1491,11 +1483,11 @@ private void manualSuccess(String message, Visibility visibility) { this.countDownLatch.countDown(); } - public void extend(int seconds) { + void extend(int seconds) { this.visibility.extend(seconds); } - public CountDownLatch getCountDownLatch() { + CountDownLatch getCountDownLatch() { return this.countDownLatch; } @@ -1514,11 +1506,11 @@ private void manualSuccess(String message, Acknowledgment acknowledgment) { this.countDownLatch.countDown(); } - public void acknowledge() { + void acknowledge() { this.acknowledgment.acknowledge(); } - public CountDownLatch getCountDownLatch() { + CountDownLatch getCountDownLatch() { return this.countDownLatch; } @@ -1588,7 +1580,7 @@ private void neverError(String message, Acknowledgment acknowledgment) { throw new RuntimeException("BOOM!"); } - public CountDownLatch getCountdownLatch() { + CountDownLatch getCountdownLatch() { return this.countdownLatch; } @@ -1612,7 +1604,7 @@ private void handleMessage(String message) throws InterruptedException { Thread.sleep(LISTENER_METHOD_WAIT_TIME); } - public CountDownLatch getCountDownLatch() { + CountDownLatch getCountDownLatch() { return this.countDownLatch; } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/AcknowledgmentHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/AcknowledgmentHandlerMethodArgumentResolverTest.java index ec58f5029..3d87e562a 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/AcknowledgmentHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/AcknowledgmentHandlerMethodArgumentResolverTest.java @@ -16,36 +16,33 @@ package org.springframework.cloud.aws.messaging.listener.support; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + /** * @author Alain Sahli * @since 1.1 */ -public class AcknowledgmentHandlerMethodArgumentResolverTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class AcknowledgmentHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_messageWithNoAcknowledgmentHeader_throwIllegalArgumentException() + void resolveArgument_messageWithNoAcknowledgmentHeader_throwIllegalArgumentException() throws Exception { // Arrange - AcknowledgmentHandlerMethodArgumentResolver acknowledgmentHandlerMethodArgumentResolver = null; + AcknowledgmentHandlerMethodArgumentResolver acknowledgmentHandlerMethodArgumentResolver; acknowledgmentHandlerMethodArgumentResolver = new AcknowledgmentHandlerMethodArgumentResolver( "Acknowledgment"); Message message = MessageBuilder.withPayload("no content").build(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("Acknowledgment"); - // Act - acknowledgmentHandlerMethodArgumentResolver.resolveArgument(null, message); + assertThatThrownBy(() -> acknowledgmentHandlerMethodArgumentResolver + .resolveArgument(null, message)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Acknowledgment"); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/VisibilityHandlerMethodArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/VisibilityHandlerMethodArgumentResolverTest.java index 640b3803c..dae7acc83 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/VisibilityHandlerMethodArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/listener/support/VisibilityHandlerMethodArgumentResolverTest.java @@ -16,24 +16,21 @@ package org.springframework.cloud.aws.messaging.listener.support; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + /** * @author Szymon Dembek * @since 1.3 */ -public class VisibilityHandlerMethodArgumentResolverTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class VisibilityHandlerMethodArgumentResolverTest { @Test - public void resolveArgument_messageWithNoVisibilityHeader_throwIllegalArgumentException() + void resolveArgument_messageWithNoVisibilityHeader_throwIllegalArgumentException() throws Exception { // Arrange VisibilityHandlerMethodArgumentResolver visibilityHandlerMethodArgumentResolver; @@ -41,11 +38,11 @@ public void resolveArgument_messageWithNoVisibilityHeader_throwIllegalArgumentEx "Visibility"); Message message = MessageBuilder.withPayload("no content").build(); - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("Visibility"); - - // Act - visibilityHandlerMethodArgumentResolver.resolveArgument(null, message); + // Assert + assertThatThrownBy(() -> visibilityHandlerMethodArgumentResolver + .resolveArgument(null, message)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Visibility"); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationMessageArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationMessageArgumentResolverTest.java index 24b4c0127..2bfc4d0eb 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationMessageArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationMessageArgumentResolverTest.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; import org.springframework.cloud.aws.messaging.config.annotation.NotificationMessage; @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class NotificationMessageArgumentResolverTest { +class NotificationMessageArgumentResolverTest { @Test - public void supportsParameter_withNotificationMessageMethodParameter_shouldReturnTrue() + void supportsParameter_withNotificationMessageMethodParameter_shouldReturnTrue() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( @@ -59,8 +59,7 @@ private void methodWithNotificationMessageArgument( } @Test - public void supportsParameter_withWrongMethodParameter_shouldReturnFalse() - throws Exception { + void supportsParameter_withWrongMethodParameter_shouldReturnFalse() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( new StringMessageConverter()); @@ -83,7 +82,7 @@ private void methodWithMissingAnnotation(String test) { } @Test - public void supportsParameter_withNonStringParameterType_shouldReturnTrue() + void supportsParameter_withNonStringParameterType_shouldReturnTrue() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( @@ -107,7 +106,7 @@ private void methodWithWrongParameterType(@NotificationMessage Long test) { } @Test - public void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage() + void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationSubjectArgumentResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationSubjectArgumentResolverTest.java index 3950a3b92..f24591dad 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationSubjectArgumentResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/NotificationSubjectArgumentResolverTest.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.support.documentation.RuntimeUse; import org.springframework.cloud.aws.messaging.config.annotation.NotificationSubject; @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class NotificationSubjectArgumentResolverTest { +class NotificationSubjectArgumentResolverTest { @Test - public void supportsParameter_withNotificationSubjectMethodParameter_shouldReturnTrue() + void supportsParameter_withNotificationSubjectMethodParameter_shouldReturnTrue() throws Exception { // Arrange NotificationSubjectArgumentResolver notificationSubjectArgumentResolver = new NotificationSubjectArgumentResolver(); @@ -57,8 +57,7 @@ private void methodWithNotificationSubjectArgument( } @Test - public void supportsParameter_withWrongMethodParameter_shouldReturnFalse() - throws Exception { + void supportsParameter_withWrongMethodParameter_shouldReturnFalse() throws Exception { // Arrange NotificationSubjectArgumentResolver notificationSubjectArgumentResolver = new NotificationSubjectArgumentResolver(); Method methodWithMissingAnnotation = this.getClass() @@ -80,8 +79,7 @@ private void methodWithMissingAnnotation(String subject) { } @Test - public void supportsParameter_withWrongParameterType_shouldReturnFalse() - throws Exception { + void supportsParameter_withWrongParameterType_shouldReturnFalse() throws Exception { // Arrange NotificationSubjectArgumentResolver notificationSubjectArgumentResolver = new NotificationSubjectArgumentResolver(); Method methodWithWrongParameterType = this.getClass() @@ -103,7 +101,7 @@ private void methodWithWrongParameterType(@NotificationSubject Long subject) { } @Test - public void resolveArgument_withValidRequestPayload_shouldReturnNotificationSubject() + void resolveArgument_withValidRequestPayload_shouldReturnNotificationSubject() throws Exception { // Arrange NotificationSubjectArgumentResolver notificationSubjectArgumentResolver = new NotificationSubjectArgumentResolver(); diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/NotificationRequestConverterTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/NotificationRequestConverterTest.java index e129cb69b..6d05ddec5 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/NotificationRequestConverterTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/NotificationRequestConverterTest.java @@ -18,41 +18,40 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.StringMessageConverter; import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Agim Emruli * @author Alain Sahli * @since 1.0 */ -public class NotificationRequestConverterTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class NotificationRequestConverterTest { @Test - public void testWriteMessageNotSupported() throws Exception { - this.expectedException.expect(UnsupportedOperationException.class); - new NotificationRequestConverter(new StringMessageConverter()).toMessage("test", - null); + void testWriteMessageNotSupported() throws Exception { + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .toMessage("test", null)) + .isInstanceOf(UnsupportedOperationException.class); } - @Test(expected = IllegalArgumentException.class) - public void fromMessage_withoutMessage_shouldThrowAnException() throws Exception { - new NotificationRequestConverter(new StringMessageConverter()).fromMessage(null, - String.class); + @Test + void fromMessage_withoutMessage_shouldThrowAnException() throws Exception { + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .fromMessage(null, String.class)) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception { + void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception { // Arrange ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); @@ -77,7 +76,7 @@ public void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Excep } @Test - public void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception { + void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception { // Arrange ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); @@ -98,47 +97,63 @@ public void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception { } @Test - public void testNoTypeSupplied() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("does not contain a Type attribute"); + void testNoTypeSupplied() throws Exception { ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Message", "Hello World!"); String payload = jsonObject.toString(); - new NotificationRequestConverter(new StringMessageConverter()) - .fromMessage(MessageBuilder.withPayload(payload).build(), String.class); + + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .fromMessage(MessageBuilder.withPayload(payload).build(), + String.class)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining( + "does not contain a Type attribute"); + } @Test - public void testWrongTypeSupplied() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("is not a valid notification"); + void testWrongTypeSupplied() throws Exception { ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Subscription"); jsonObject.put("Message", "Hello World!"); + String payload = jsonObject.toString(); - new NotificationRequestConverter(new StringMessageConverter()) - .fromMessage(MessageBuilder.withPayload(payload).build(), String.class); + + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .fromMessage(MessageBuilder.withPayload(payload).build(), + String.class)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining( + "is not a valid notification"); } @Test - public void testNoMessageAvailableSupplied() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("does not contain a message"); + void testNoMessageAvailableSupplied() throws Exception { ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Subject", "Hello World!"); String payload = jsonObject.toString(); - new NotificationRequestConverter(new StringMessageConverter()) - .fromMessage(MessageBuilder.withPayload(payload).build(), String.class); + + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .fromMessage(MessageBuilder.withPayload(payload).build(), + String.class)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining( + "does not contain a message"); } @Test - public void testNoValidJson() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("Could not read JSON"); + void testNoValidJson() throws Exception { String message = "foo"; - new NotificationRequestConverter(new StringMessageConverter()) - .fromMessage(MessageBuilder.withPayload(message).build(), String.class); + assertThatThrownBy( + () -> new NotificationRequestConverter(new StringMessageConverter()) + .fromMessage(MessageBuilder.withPayload(message).build(), + String.class)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining("Could not read JSON"); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/ObjectMessageConverterTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/ObjectMessageConverterTest.java index 37a2e0110..0ddef9e20 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/ObjectMessageConverterTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/converter/ObjectMessageConverterTest.java @@ -22,9 +22,7 @@ import java.util.Collections; import org.apache.commons.codec.binary.Base64; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -34,14 +32,12 @@ import org.springframework.util.MimeType; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * */ -public class ObjectMessageConverterTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class ObjectMessageConverterTest { private static MessageHeaders getMessageHeaders(String charsetName) { return new MessageHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, @@ -50,7 +46,7 @@ private static MessageHeaders getMessageHeaders(String charsetName) { } @Test - public void testToMessageAndFromMessage() throws Exception { + void testToMessageAndFromMessage() throws Exception { String content = "stringwithspecialcharsöäü€a8"; MySerializableClass sourceMessage = new MySerializableClass(content); MessageConverter messageConverter = new ObjectMessageConverter(); @@ -64,7 +60,7 @@ public void testToMessageAndFromMessage() throws Exception { } @Test - public void testToMessageAndFromMessageWithCustomEncoding() throws Exception { + void testToMessageAndFromMessageWithCustomEncoding() throws Exception { String content = "stringwithspecialcharsöäü€a8"; MySerializableClass sourceMessage = new MySerializableClass(content); MessageConverter messageConverter = new ObjectMessageConverter("ISO-8859-1"); @@ -78,29 +74,29 @@ public void testToMessageAndFromMessageWithCustomEncoding() throws Exception { assertThat(result.getContent()).isEqualTo(content); } - @Test(expected = UnsupportedCharsetException.class) - public void testWithWrongCharset() throws Exception { - // noinspection ResultOfObjectAllocationIgnored - new ObjectMessageConverter("someUnsupportedEncoding"); + @Test + void testWithWrongCharset() throws Exception { + assertThatThrownBy(() -> new ObjectMessageConverter("someUnsupportedEncoding")) + .isInstanceOf(UnsupportedCharsetException.class); } @Test - public void testPayloadIsNotAValidBase64Payload() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("not a valid base64 encoded stream"); + void testPayloadIsNotAValidBase64Payload() throws Exception { ObjectMessageConverter messageConverter = new ObjectMessageConverter(); - messageConverter.fromMessage(MessageBuilder.withPayload("test€").build(), null); + assertThatThrownBy(() -> messageConverter + .fromMessage(MessageBuilder.withPayload("test€").build(), null)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining("not a valid base64 encoded stream"); } @Test - public void testPayloadIsNotAValidObjectStream() throws Exception { - this.expectedException.expect(MessageConversionException.class); - this.expectedException.expectMessage("Error reading payload"); - + void testPayloadIsNotAValidObjectStream() throws Exception { ObjectMessageConverter messageConverter = new ObjectMessageConverter(); - messageConverter.fromMessage(MessageBuilder.withPayload("someStream").build(), - null); + assertThatThrownBy(() -> messageConverter + .fromMessage(MessageBuilder.withPayload("someStream").build(), null)) + .isInstanceOf(MessageConversionException.class) + .hasMessageContaining("Error reading payload"); } private static final class MySerializableClass implements Serializable { @@ -111,7 +107,7 @@ private MySerializableClass(String content) { this.content = content; } - public String getContent() { + String getContent() { return this.content; } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicQueueUrlDestinationResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicQueueUrlDestinationResolverTest.java index 7e66435f9..311264abd 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicQueueUrlDestinationResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicQueueUrlDestinationResolverTest.java @@ -23,20 +23,21 @@ import com.amazonaws.services.sqs.model.GetQueueUrlRequest; import com.amazonaws.services.sqs.model.GetQueueUrlResult; import com.amazonaws.services.sqs.model.QueueDoesNotExistException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import org.springframework.messaging.core.DestinationResolutionException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class DynamicQueueUrlDestinationResolverTest { +class DynamicQueueUrlDestinationResolverTest { @Test - public void testAutoCreate() throws Exception { + void testAutoCreate() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); String queueUrl = "https://foo/bar"; when(amazonSqs.createQueue(new CreateQueueRequest("foo"))) @@ -50,7 +51,7 @@ public void testAutoCreate() throws Exception { } @Test - public void testAbsoluteUrl() throws Exception { + void testAbsoluteUrl() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); @@ -60,7 +61,7 @@ public void testAbsoluteUrl() throws Exception { } @Test - public void testNoAutoCreate() throws Exception { + void testNoAutoCreate() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); String queueUrl = "https://foo/bar"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest("foo"))) @@ -73,7 +74,7 @@ public void testNoAutoCreate() throws Exception { } @Test - public void testInvalidDestinationName() throws Exception { + void testInvalidDestinationName() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); @@ -92,7 +93,7 @@ public void testInvalidDestinationName() throws Exception { } @Test - public void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception { + void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); @@ -114,7 +115,7 @@ public void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception { } @Test - public void resolveDestination_withResourceIdResolver_shouldUseIt() throws Exception { + void resolveDestination_withResourceIdResolver_shouldUseIt() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); when(resourceIdResolver.resolveToPhysicalResourceId(anyString())) @@ -130,7 +131,7 @@ public void resolveDestination_withResourceIdResolver_shouldUseIt() throws Excep } @Test - public void resolveDestination_withResourceIdResolver_nonUrlId_shouldGetUrlByResolvedName() + void resolveDestination_withResourceIdResolver_nonUrlId_shouldGetUrlByResolvedName() throws Exception { String queueUrl = "http://queue.com"; String resolvedQueueName = "some-queue-name"; @@ -149,9 +150,10 @@ public void resolveDestination_withResourceIdResolver_nonUrlId_shouldGetUrlByRes assertThat(physicalResourceId).isEqualTo("http://queue.com"); } - @Test(expected = IllegalArgumentException.class) - public void instantiation_withNullAmazonClient_shouldThrowAnError() throws Exception { - new DynamicQueueUrlDestinationResolver(null, null); + @Test + void instantiation_withNullAmazonClient_shouldThrowAnError() throws Exception { + assertThatThrownBy(() -> new DynamicQueueUrlDestinationResolver(null, null)) + .isInstanceOf(IllegalArgumentException.class); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicTopicDestinationResolverTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicTopicDestinationResolverTest.java index 4f5599a84..184f4d3f5 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicTopicDestinationResolverTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/support/destination/DynamicTopicDestinationResolverTest.java @@ -22,13 +22,12 @@ import com.amazonaws.services.sns.model.ListTopicsRequest; import com.amazonaws.services.sns.model.ListTopicsResult; import com.amazonaws.services.sns.model.Topic; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.core.env.ResourceIdResolver; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,20 +35,14 @@ * @author Agim Emruli * @since 1.0 */ -public class DynamicTopicDestinationResolverTest { - - @Rule - public final ExpectedException expectedException = ExpectedException.none(); +class DynamicTopicDestinationResolverTest { // @checkstyle:off @Test - public void resolveDestination_withNonExistentTopicAndWithoutMarkerReturnedOnListTopics_shouldThrowIllegalArgumentException() + void resolveDestination_withNonExistentTopicAndWithoutMarkerReturnedOnListTopics_shouldThrowIllegalArgumentException() throws Exception { // @checkstyle:on // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("No topic found for name :'test'"); - AmazonSNS sns = mock(AmazonSNS.class); when(sns.listTopics(new ListTopicsRequest(null))) .thenReturn(new ListTopicsResult()); @@ -57,19 +50,18 @@ public void resolveDestination_withNonExistentTopicAndWithoutMarkerReturnedOnLis DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver( sns); - // Act - resolver.resolveDestination("test"); + // Assert + assertThatThrownBy(() -> resolver.resolveDestination("test")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No topic found for name :'test'"); } // @checkstyle:off @Test - public void resolveDestination_withNonExistentTopicAndWithMarkerReturnedOnListTopics_shouldCallListMultipleTimeWithMarkerAndThrowIllegalArgumentException() + void resolveDestination_withNonExistentTopicAndWithMarkerReturnedOnListTopics_shouldCallListMultipleTimeWithMarkerAndThrowIllegalArgumentException() // @checkstyle:on throws Exception { // Arrange - this.expectedException.expect(IllegalArgumentException.class); - this.expectedException.expectMessage("No topic found for name :'test'"); - AmazonSNS sns = mock(AmazonSNS.class); when(sns.listTopics(new ListTopicsRequest(null))) .thenReturn(new ListTopicsResult().withNextToken("foo")); @@ -79,12 +71,14 @@ public void resolveDestination_withNonExistentTopicAndWithMarkerReturnedOnListTo DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver( sns); - // Act - resolver.resolveDestination("test"); + // Assert + assertThatThrownBy(() -> resolver.resolveDestination("test")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No topic found for name :'test'"); } @Test - public void resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListingTopic() + void resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListingTopic() throws Exception { // Arrange String topicArn = "arn:aws:sns:eu-west:123456789012:test"; @@ -104,7 +98,7 @@ public void resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListin } @Test - public void resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWhileListingTopic() + void resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWhileListingTopic() throws Exception { // Arrange @@ -127,7 +121,7 @@ public void resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWh } @Test - public void resolveDestination_withAlreadyExistingArn_returnsArnWithoutValidatingIt() + void resolveDestination_withAlreadyExistingArn_returnsArnWithoutValidatingIt() throws Exception { // Arrange String topicArn = "arn:aws:sns:eu-west:123456789012:test"; @@ -144,7 +138,7 @@ public void resolveDestination_withAlreadyExistingArn_returnsArnWithoutValidatin } @Test - public void resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly() + void resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly() throws Exception { // Arrange String topicArn = "arn:aws:sns:eu-west:123456789012:test"; @@ -165,8 +159,7 @@ public void resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly() } @Test - public void resolveDestination_withResourceIdResolver_shouldCallIt() - throws Exception { + void resolveDestination_withResourceIdResolver_shouldCallIt() throws Exception { // Arrange String physicalTopicName = "arn:aws:sns:eu-west:123456789012:myTopic"; String logicalTopicName = "myTopic"; diff --git a/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySourceTest.java b/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySourceTest.java index 64288a565..bd5351afc 100644 --- a/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySourceTest.java +++ b/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySourceTest.java @@ -20,14 +20,14 @@ import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest; import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult; import com.amazonaws.services.simplesystemsmanagement.model.Parameter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class AwsParamStorePropertySourceTest { +class AwsParamStorePropertySourceTest { private AWSSimpleSystemsManagement ssmClient = mock(AWSSimpleSystemsManagement.class); @@ -35,7 +35,7 @@ public class AwsParamStorePropertySourceTest { "/config/myservice/", ssmClient); @Test - public void followsNextToken() { + void followsNextToken() { GetParametersByPathResult firstResult = new GetParametersByPathResult() .withNextToken("next").withParameters( new Parameter().withName("/config/myservice/key1") diff --git a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java index 77da6b75e..c91b2324c 100644 --- a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java +++ b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceLocatorTest.java @@ -19,7 +19,7 @@ import com.amazonaws.services.secretsmanager.AWSSecretsManager; import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest; import com.amazonaws.services.secretsmanager.model.GetSecretValueResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.env.PropertySource; import org.springframework.mock.env.MockEnvironment; @@ -34,14 +34,14 @@ * * @author Anthony Foulfoin */ -public class AwsSecretsManagerPropertySourceLocatorTest { +class AwsSecretsManagerPropertySourceLocatorTest { private AWSSecretsManager smClient = mock(AWSSecretsManager.class); private MockEnvironment env = new MockEnvironment(); @Test - public void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecifiedName() { + void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecifiedName() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); when(smClient.getSecretValue(any(GetSecretValueRequest.class))) @@ -57,7 +57,7 @@ public void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecified } @Test - public void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() { + void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); when(smClient.getSecretValue(any(GetSecretValueRequest.class))) diff --git a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceTest.java b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceTest.java index d62c892c6..ffb36377c 100644 --- a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceTest.java +++ b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertySourceTest.java @@ -19,14 +19,14 @@ import com.amazonaws.services.secretsmanager.AWSSecretsManager; import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest; import com.amazonaws.services.secretsmanager.model.GetSecretValueResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class AwsSecretsManagerPropertySourceTest { +class AwsSecretsManagerPropertySourceTest { private AWSSecretsManager smClient = mock(AWSSecretsManager.class); @@ -34,7 +34,7 @@ public class AwsSecretsManagerPropertySourceTest { "/config/myservice", smClient); @Test - public void shouldParseSecretValue() { + void shouldParseSecretValue() { GetSecretValueResult secretValueResult = new GetSecretValueResult(); secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}"); From 7817a371ad911472901495d24fdf4a69add1c2b5 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 12 Jun 2020 02:33:50 +0200 Subject: [PATCH 34/47] Configure SQS to use existing ObjectMapper if present in application context. If ObjectMapper is not present, creates default Jackson ObjectMapper without the dependency to spring-web module. Fixes gh-533 Fixes gh-522 Fixes gh-540 Closes gh-592 --- .../config/QueueMessageHandlerFactory.java | 29 ++++++-- .../config/annotation/SqsConfiguration.java | 8 ++- ...essageChannelMessagingSendingTemplate.java | 12 +--- .../annotation/SqsConfigurationTest.java | 38 +++++++++- .../core/QueueMessagingTemplateTest.java | 69 +++---------------- 5 files changed, 80 insertions(+), 76 deletions(-) diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/QueueMessageHandlerFactory.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/QueueMessageHandlerFactory.java index 3fc6f57e2..93a578aaa 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/QueueMessageHandlerFactory.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/QueueMessageHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.AmazonSQSAsync; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.BeanFactory; import org.springframework.cloud.aws.core.env.ResourceIdResolver; @@ -55,6 +56,8 @@ public class QueueMessageHandlerFactory { private List messageConverters; + private ObjectMapper objectMapper; + public void setArgumentResolvers( List argumentResolvers) { this.argumentResolvers = argumentResolvers; @@ -123,10 +126,20 @@ public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } + /** + * Configures an {@link ObjectMapper} that is used by default + * {@link MappingJackson2MessageConverter} created if no {@link #messageConverters} + * are set. + * @param objectMapper - object mapper, can be null + */ + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + public QueueMessageHandler createQueueMessageHandler() { QueueMessageHandler queueMessageHandler = new QueueMessageHandler( - CollectionUtils.isEmpty(this.messageConverters) - ? Arrays.asList(getDefaultMappingJackson2MessageConverter()) + CollectionUtils.isEmpty(this.messageConverters) ? Arrays.asList( + getDefaultMappingJackson2MessageConverter(this.objectMapper)) : this.messageConverters); if (!CollectionUtils.isEmpty(this.argumentResolvers)) { @@ -159,7 +172,7 @@ public QueueMessageHandler createQueueMessageHandler() { private QueueMessagingTemplate getDefaultSendToQueueMessagingTemplate( AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) { return new QueueMessagingTemplate(amazonSqs, resourceIdResolver, - getDefaultMappingJackson2MessageConverter()); + getDefaultMappingJackson2MessageConverter(this.objectMapper)); } public List getMessageConverters() { @@ -176,10 +189,16 @@ public void setMessageConverters(List messageConverters) { this.messageConverters = messageConverters; } - private MappingJackson2MessageConverter getDefaultMappingJackson2MessageConverter() { + private MappingJackson2MessageConverter getDefaultMappingJackson2MessageConverter( + ObjectMapper objectMapper) { MappingJackson2MessageConverter jacksonMessageConverter = new MappingJackson2MessageConverter(); jacksonMessageConverter.setSerializedPayloadClass(String.class); jacksonMessageConverter.setStrictContentTypeMatch(true); + + if (objectMapper != null) { + jacksonMessageConverter.setObjectMapper(objectMapper); + } + return jacksonMessageConverter; } diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java index 8f48072eb..34351940a 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.java @@ -19,6 +19,7 @@ import java.util.Arrays; import com.amazonaws.services.sqs.AmazonSQSAsync; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ObjectProvider; @@ -54,12 +55,15 @@ public class SqsConfiguration { private final MappingJackson2MessageConverter mappingJackson2MessageConverter; + private final ObjectMapper objectMapper; + public SqsConfiguration( ObjectProvider simpleMessageListenerContainerFactory, ObjectProvider queueMessageHandlerFactory, BeanFactory beanFactory, ObjectProvider resourceIdResolver, - ObjectProvider mappingJackson2MessageConverter) { + ObjectProvider mappingJackson2MessageConverter, + ObjectProvider objectMapper) { this.simpleMessageListenerContainerFactory = simpleMessageListenerContainerFactory .getIfAvailable(SimpleMessageListenerContainerFactory::new); this.queueMessageHandlerFactory = queueMessageHandlerFactory @@ -68,6 +72,7 @@ public SqsConfiguration( this.resourceIdResolver = resourceIdResolver.getIfAvailable(); this.mappingJackson2MessageConverter = mappingJackson2MessageConverter .getIfAvailable(); + this.objectMapper = objectMapper.getIfAvailable(); } @Bean @@ -111,6 +116,7 @@ private QueueMessageHandler getMessageHandler(AmazonSQSAsync amazonSqs) { } this.queueMessageHandlerFactory.setBeanFactory(this.beanFactory); + this.queueMessageHandlerFactory.setObjectMapper(this.objectMapper); return this.queueMessageHandlerFactory.createQueueMessageHandler(); } diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplate.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplate.java index a3b3117ae..0a626440d 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplate.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/support/AbstractMessageChannelMessagingSendingTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessagingException; @@ -33,7 +32,6 @@ import org.springframework.messaging.core.DestinationResolver; import org.springframework.messaging.core.DestinationResolvingMessageSendingOperations; import org.springframework.messaging.core.MessagePostProcessor; -import org.springframework.util.ClassUtils; /** * @param message channel type @@ -45,10 +43,6 @@ public abstract class AbstractMessageChannelMessagingSendingTemplate implements DestinationResolvingMessageSendingOperations { - private static final boolean JACKSON_2_PRESENT = ClassUtils.isPresent( - "com.fasterxml.jackson.databind.ObjectMapper", - AbstractMessageChannelMessagingSendingTemplate.class.getClassLoader()); - private final DestinationResolver destinationResolver; protected AbstractMessageChannelMessagingSendingTemplate( @@ -120,10 +114,8 @@ protected void initMessageConverter(MessageConverter messageConverter) { if (messageConverter != null) { messageConverters.add(messageConverter); } - else if (JACKSON_2_PRESENT) { + else { MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter(); - mappingJackson2MessageConverter - .setObjectMapper(Jackson2ObjectMapperBuilder.json().build()); mappingJackson2MessageConverter.setSerializedPayloadClass(String.class); messageConverters.add(mappingJackson2MessageConverter); } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java index b9df0b2b8..3c77830d4 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SqsConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.cloud.aws.messaging.config.annotation; import java.util.Collections; +import java.util.List; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; @@ -25,6 +26,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsync; import com.amazonaws.services.sqs.AmazonSQSAsyncClient; import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springframework.cloud.aws.context.config.annotation.EnableContextRegion; @@ -40,6 +42,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.messaging.converter.MappingJackson2MessageConverter; +import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.core.DestinationResolver; import org.springframework.messaging.core.DestinationResolvingMessageSendingOperations; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; @@ -52,6 +56,7 @@ /** * @author Alain Sahli + * @author Maciej Walkowiak */ class SqsConfigurationTest { @@ -194,6 +199,25 @@ void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception { "messageHandler")).isEqualTo(queueMessageHandler); } + @Test + void configuration_withObjectMapper_shouldSetObjectMapperOnQueueMessageHandler() + throws Exception { + // Arrange & Act + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( + ConfigurationWithObjectMapper.class); + QueueMessageHandler queueMessageHandler = applicationContext + .getBean(QueueMessageHandler.class); + ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper.class); + List converters = (List) ReflectionTestUtils + .getField(queueMessageHandler, "messageConverters"); + MappingJackson2MessageConverter mappingJackson2MessageConverter = (MappingJackson2MessageConverter) converters + .get(0); + + // Assert + assertThat(mappingJackson2MessageConverter.getObjectMapper()) + .isEqualTo(objectMapper); + } + @Test void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider() throws Exception { @@ -375,4 +399,16 @@ static class ConfigurationWithRegionProvider { } + @EnableSqs + @EnableContextRegion(region = "eu-west-1") + @Configuration(proxyBeanMethods = false) + static class ConfigurationWithObjectMapper { + + @Bean + ObjectMapper objectMapper() { + return new ObjectMapper(); + } + + } + } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java index f586069ef..37ed35c75 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/QueueMessagingTemplateTest.java @@ -16,7 +16,6 @@ package org.springframework.cloud.aws.messaging.core; -import java.io.IOException; import java.time.LocalDate; import java.util.Locale; @@ -27,12 +26,10 @@ import com.amazonaws.services.sqs.model.ReceiveMessageResult; import com.amazonaws.services.sqs.model.SendMessageRequest; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.cloud.aws.core.env.ResourceIdResolver; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.converter.CompositeMessageConverter; import org.springframework.messaging.converter.MappingJackson2MessageConverter; @@ -205,72 +202,26 @@ void instantiation_withConverter_shouldAddItToTheCompositeConverter() { // Assert assertThat( ((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter()) - .getConverters().size()).isEqualTo(2); + .getConverters()).hasSize(2); assertThat( ((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter()) .getConverters().get(1)).isEqualTo(simpleMessageConverter); } @Test - void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString() - throws IOException { - - // Arrange - AmazonSQSAsync amazonSqs = createAmazonSqs(); - - ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); - - MappingJackson2MessageConverter simpleMessageConverter = new MappingJackson2MessageConverter(); - simpleMessageConverter.setSerializedPayloadClass(String.class); - simpleMessageConverter.setObjectMapper(objectMapper); - - QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( - amazonSqs, (ResourceIdResolver) null, simpleMessageConverter); - + void instantiation_withoutConverter_shouldAddDefaultJacksonConverterToTheCompositeConverter() { // Act - queueMessagingTemplate.convertAndSend("test", - new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1))); - - // Assert - ArgumentCaptor sendMessageRequestArgumentCaptor = ArgumentCaptor - .forClass(SendMessageRequest.class); - verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture()); - TestPerson testPerson = objectMapper.readValue( - sendMessageRequestArgumentCaptor.getValue().getMessageBody(), - TestPerson.class); - - assertThat(testPerson.getFirstName()).isEqualTo("Agim"); - assertThat(testPerson.getLastName()).isEqualTo("Emruli"); - assertThat(testPerson.getActiveSince()).isEqualTo(LocalDate.of(2017, 1, 1)); - } - - @Test - void instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types() - throws IOException { - - // Arrange - AmazonSQSAsync amazonSqs = createAmazonSqs(); - - ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); - QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( - amazonSqs); - - // Act - queueMessagingTemplate.convertAndSend("test", - new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1))); + createAmazonSqs(), (ResourceIdResolver) null, null); // Assert - ArgumentCaptor sendMessageRequestArgumentCaptor = ArgumentCaptor - .forClass(SendMessageRequest.class); - verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture()); - TestPerson testPerson = objectMapper.readValue( - sendMessageRequestArgumentCaptor.getValue().getMessageBody(), - TestPerson.class); - - assertThat(testPerson.getFirstName()).isEqualTo("Agim"); - assertThat(testPerson.getLastName()).isEqualTo("Emruli"); - assertThat(testPerson.getActiveSince()).isEqualTo(LocalDate.of(2017, 1, 1)); + assertThat( + ((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter()) + .getConverters()).hasSize(2); + assertThat( + ((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter()) + .getConverters().get(1)) + .isInstanceOf(MappingJackson2MessageConverter.class); } private AmazonSQSAsync createAmazonSqs() { From ddde60b44bc09d155ce926c5d366f45008752d30 Mon Sep 17 00:00:00 2001 From: MatejNedic Date: Mon, 8 Jun 2020 22:47:57 +0200 Subject: [PATCH 35/47] Drop dependency to javax.validation in Parameter Store and Secrets Manager. Fixes gh-576 Closes gh-585 --- .../pom.xml | 6 - .../paramstore/AwsParamStoreProperties.java | 57 ++++++++-- .../AwsParamStorePropertiesTest.java | 104 +++++++++++++++++ .../pom.xml | 6 - .../AwsSecretsManagerProperties.java | 59 ++++++++-- .../AwsSecretsManagerPropertiesTest.java | 105 ++++++++++++++++++ 6 files changed, 302 insertions(+), 35 deletions(-) create mode 100644 spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertiesTest.java create mode 100644 spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertiesTest.java diff --git a/spring-cloud-aws-parameter-store-config/pom.xml b/spring-cloud-aws-parameter-store-config/pom.xml index f1b066530..d0f702a29 100644 --- a/spring-cloud-aws-parameter-store-config/pom.xml +++ b/spring-cloud-aws-parameter-store-config/pom.xml @@ -50,12 +50,6 @@ aws-java-sdk-ssm - - javax.validation - validation-api - true - - org.springframework.boot spring-boot-configuration-processor diff --git a/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStoreProperties.java b/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStoreProperties.java index 8870cf765..4ce0ef235 100644 --- a/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStoreProperties.java +++ b/spring-cloud-aws-parameter-store-config/src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStoreProperties.java @@ -16,42 +16,49 @@ package org.springframework.cloud.aws.paramstore; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import java.util.regex.Pattern; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; /** * Configuration properties for the AWS Parameter Store integration. Mostly based on the * Spring Cloud Consul Configuration equivalent. * * @author Joris Kuipers + * @author Matej Nedic * @since 2.0.0 */ @ConfigurationProperties(AwsParamStoreProperties.CONFIG_PREFIX) -@Validated -public class AwsParamStoreProperties { +public class AwsParamStoreProperties implements Validator { /** * Configuration prefix. */ public static final String CONFIG_PREFIX = "aws.paramstore"; + /** + * Pattern used for prefix validation. + */ + private static final Pattern PREFIX_PATTERN = Pattern + .compile("(/[a-zA-Z0-9.\\-_]+)*"); + + /** + * Pattern used for profileSeparator validation. + */ + private static final Pattern PROFILE_SEPARATOR_PATTERN = Pattern + .compile("[a-zA-Z0-9.\\-_/]+"); + /** * Prefix indicating first level for every property. Value must start with a forward * slash followed by a valid path segment or be empty. Defaults to "/config". */ - @NotNull - @Pattern(regexp = "(/[a-zA-Z0-9.\\-_]+)*") private String prefix = "/config"; - @NotEmpty private String defaultContext = "application"; - @NotNull - @Pattern(regexp = "[a-zA-Z0-9.\\-_/]+") private String profileSeparator = "_"; /** Throw exceptions during config lookup if true, otherwise, log warnings. */ @@ -66,6 +73,34 @@ public class AwsParamStoreProperties { /** Is AWS Parameter Store support enabled. */ private boolean enabled = true; + @Override + public boolean supports(Class clazz) { + return AwsParamStoreProperties.class.isAssignableFrom(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "prefix", "NotEmpty", + "prefix should not be empty or null."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "defaultContext", "NotEmpty", + "defaultContext should not be empty or null."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "profileSeparator", "NotEmpty", + "profileSeparator should not be empty or null."); + + AwsParamStoreProperties awsParamStoreProperties = (AwsParamStoreProperties) target; + + if (!PREFIX_PATTERN.matcher(awsParamStoreProperties.getPrefix()).matches()) { + errors.rejectValue("prefix", "Pattern", + "The prefix must have pattern of: " + PREFIX_PATTERN.toString()); + } + if (!PROFILE_SEPARATOR_PATTERN + .matcher(awsParamStoreProperties.getProfileSeparator()).matches()) { + errors.rejectValue("profileSeparator", "Pattern", + "The profileSeparator must have pattern of: " + + PROFILE_SEPARATOR_PATTERN.toString()); + } + } + public String getPrefix() { return prefix; } diff --git a/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertiesTest.java b/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertiesTest.java new file mode 100644 index 000000000..0bb39a33e --- /dev/null +++ b/spring-cloud-aws-parameter-store-config/src/test/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertiesTest.java @@ -0,0 +1,104 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.paramstore; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AwsParamStoreProperties}. + * + * @author Matej Nedic + * @author Maciej Walkowiak + */ +public class AwsParamStorePropertiesTest { + + @ParameterizedTest + @MethodSource("invalidProperties") + public void validationFails(AwsParamStoreProperties properties, String field, + String errorCode) { + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + + properties.validate(properties, errors); + + assertThat(errors.getFieldError(field)).isNotNull(); + assertThat(errors.getFieldError(field).getCode()).isEqualTo(errorCode); + } + + @Test + void validationSucceeds() { + AwsParamStoreProperties properties = new AwsParamStorePropertiesBuilder() + .withPrefix("/con").withDefaultContext("app").withProfileSeparator("_") + .build(); + + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + properties.validate(properties, errors); + + assertThat(errors.getAllErrors()).isEmpty(); + } + + private static Stream invalidProperties() { + return Stream.of( + Arguments.of(new AwsParamStorePropertiesBuilder().withPrefix("").build(), + "prefix", "NotEmpty"), + Arguments.of( + new AwsParamStorePropertiesBuilder().withPrefix("!.").build(), + "prefix", "Pattern"), + Arguments.of(new AwsParamStorePropertiesBuilder().withDefaultContext("") + .build(), "defaultContext", "NotEmpty"), + Arguments.of(new AwsParamStorePropertiesBuilder().withProfileSeparator("") + .build(), "profileSeparator", "NotEmpty"), + Arguments.of(new AwsParamStorePropertiesBuilder() + .withProfileSeparator("!_").build(), "profileSeparator", + "Pattern")); + } + + private static class AwsParamStorePropertiesBuilder { + + private final AwsParamStoreProperties properties = new AwsParamStoreProperties(); + + AwsParamStorePropertiesBuilder withPrefix(String prefix) { + this.properties.setPrefix(prefix); + return this; + } + + AwsParamStorePropertiesBuilder withDefaultContext(String defaultContext) { + this.properties.setDefaultContext(defaultContext); + return this; + } + + AwsParamStorePropertiesBuilder withProfileSeparator(String profileSeparator) { + this.properties.setProfileSeparator(profileSeparator); + return this; + } + + AwsParamStoreProperties build() { + return this.properties; + } + + } + +} diff --git a/spring-cloud-aws-secrets-manager-config/pom.xml b/spring-cloud-aws-secrets-manager-config/pom.xml index 753e6e77a..13abb4d71 100644 --- a/spring-cloud-aws-secrets-manager-config/pom.xml +++ b/spring-cloud-aws-secrets-manager-config/pom.xml @@ -50,12 +50,6 @@ aws-java-sdk-secretsmanager - - javax.validation - validation-api - true - - org.springframework.boot spring-boot-configuration-processor diff --git a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java index 348e414c0..c33d33576 100644 --- a/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java +++ b/spring-cloud-aws-secrets-manager-config/src/main/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerProperties.java @@ -16,42 +16,49 @@ package org.springframework.cloud.aws.secretsmanager; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import java.util.regex.Pattern; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; /** * Configuration properties for the AWS Secrets Manager integration. Mostly based on the * Spring Cloud Consul Configuration equivalent. * * @author Fabio Maia + * @author Matej Nedic * @since 2.0.0 */ -@ConfigurationProperties(AwsSecretsManagerProperties.CONFIG_PREFIX) -@Validated -public class AwsSecretsManagerProperties { +@ConfigurationProperties(prefix = AwsSecretsManagerProperties.CONFIG_PREFIX) +public class AwsSecretsManagerProperties implements Validator { /** * Configuration prefix. */ public static final String CONFIG_PREFIX = "aws.secretsmanager"; + /** + * Pattern used for prefix validation. + */ + private static final Pattern PREFIX_PATTERN = Pattern + .compile("(/[a-zA-Z0-9.\\-_]+)*"); + + /** + * Pattern used for profileSeparator validation. + */ + private static final Pattern PROFILE_SEPARATOR_PATTERN = Pattern + .compile("[a-zA-Z0-9.\\-_]+"); + /** * Prefix indicating first level for every property. Value must start with a forward * slash followed by a valid path segment or be empty. Defaults to "/secret". */ - @NotNull - @Pattern(regexp = "(/[a-zA-Z0-9.\\-_]+)*") private String prefix = "/secret"; - @NotEmpty private String defaultContext = "application"; - @NotNull - @Pattern(regexp = "[a-zA-Z0-9.\\-_]+") private String profileSeparator = "_"; /** Throw exceptions during config lookup if true, otherwise, log warnings. */ @@ -66,6 +73,34 @@ public class AwsSecretsManagerProperties { /** Is AWS Secrets Manager support enabled. */ private boolean enabled = true; + @Override + public boolean supports(Class clazz) { + return AwsSecretsManagerProperties.class.isAssignableFrom(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "prefix", "NotEmpty", + "prefix should not be empty or null."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "defaultContext", "NotEmpty", + "defaultContext should not be empty or null."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "profileSeparator", "NotEmpty", + "profileSeparator should not be empty or null."); + + AwsSecretsManagerProperties awsSecretsManagerProperties = (AwsSecretsManagerProperties) target; + + if (!PREFIX_PATTERN.matcher(awsSecretsManagerProperties.getPrefix()).matches()) { + errors.rejectValue("prefix", "Pattern", + "The prefix must have pattern of: " + PREFIX_PATTERN.toString()); + } + if (!PROFILE_SEPARATOR_PATTERN + .matcher(awsSecretsManagerProperties.getProfileSeparator()).matches()) { + errors.rejectValue("profileSeparator", "Pattern", + "The profileSeparator must have pattern of: " + + PROFILE_SEPARATOR_PATTERN.toString()); + } + } + public String getPrefix() { return prefix; } diff --git a/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertiesTest.java b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertiesTest.java new file mode 100644 index 000000000..4b1642a91 --- /dev/null +++ b/spring-cloud-aws-secrets-manager-config/src/test/java/org/springframework/cloud/aws/secretsmanager/AwsSecretsManagerPropertiesTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.secretsmanager; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AwsSecretsManagerProperties}. + * + * @author Matej Nedic + * @author Maciej Walkowiak + */ +public class AwsSecretsManagerPropertiesTest { + + @Test + void validationSucceeds() { + AwsSecretsManagerProperties properties = new AwsSecretsManagerPropertiesBuilder() + .withPrefix("/sec").withDefaultContext("app").withProfileSeparator("_") + .build(); + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + properties.validate(properties, errors); + assertThat(errors.getAllErrors()).isEmpty(); + } + + @ParameterizedTest + @MethodSource("invalidProperties") + public void validationFails(AwsSecretsManagerProperties properties, String field, + String errorCode) { + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + + properties.validate(properties, errors); + + assertThat(errors.getFieldError(field)).isNotNull(); + assertThat(errors.getFieldError(field).getCode()).isEqualTo(errorCode); + } + + private static Stream invalidProperties() { + return Stream.of( + Arguments.of( + new AwsSecretsManagerPropertiesBuilder().withPrefix("").build(), + "prefix", "NotEmpty"), + Arguments.of( + new AwsSecretsManagerPropertiesBuilder().withPrefix("!.").build(), + "prefix", "Pattern"), + Arguments.of(new AwsSecretsManagerPropertiesBuilder() + .withDefaultContext("").build(), "defaultContext", "NotEmpty"), + Arguments.of(new AwsSecretsManagerPropertiesBuilder() + .withProfileSeparator("").build(), "profileSeparator", + "NotEmpty"), + Arguments.of( + new AwsSecretsManagerPropertiesBuilder() + .withProfileSeparator("!_").build(), + "profileSeparator", "Pattern")); + } + + private static class AwsSecretsManagerPropertiesBuilder { + + private final AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties(); + + AwsSecretsManagerPropertiesBuilder withPrefix(String prefix) { + this.properties.setPrefix(prefix); + return this; + } + + AwsSecretsManagerPropertiesBuilder withDefaultContext(String defaultContext) { + this.properties.setDefaultContext(defaultContext); + return this; + } + + AwsSecretsManagerPropertiesBuilder withProfileSeparator(String profileSeparator) { + this.properties.setProfileSeparator(profileSeparator); + return this; + } + + AwsSecretsManagerProperties build() { + return this.properties; + } + + } + +} From ff28c4bb0830f561a5206510a3a10b56d161b3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Tue, 7 Jul 2020 22:19:02 -0500 Subject: [PATCH 36/47] Update version --- .../cloud/aws/core/SpringCloudClientConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/SpringCloudClientConfiguration.java b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/SpringCloudClientConfiguration.java index 065b8c6e6..5c14ed825 100644 --- a/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/SpringCloudClientConfiguration.java +++ b/spring-cloud-aws-core/src/main/java/org/springframework/cloud/aws/core/SpringCloudClientConfiguration.java @@ -26,7 +26,7 @@ public final class SpringCloudClientConfiguration { private static final String NAME = "spring-cloud-aws"; - private static final String VERSION = "2.3.0"; + private static final String VERSION = "3.0.0"; private SpringCloudClientConfiguration() { From 4d0b38609176ab4264d4aa7fa52febd4d6cea8f0 Mon Sep 17 00:00:00 2001 From: jarp Date: Mon, 7 Sep 2020 14:24:12 -0500 Subject: [PATCH 37/47] feat(aws-appconfig): add appconfig & starter-appconfig modules --- pom.xml | 2 ++ spring-cloud-aws-dependencies/pom.xml | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 23f1f1915..e7a726593 100644 --- a/pom.xml +++ b/pom.xml @@ -59,11 +59,13 @@ spring-cloud-aws-messaging spring-cloud-aws-autoconfigure spring-cloud-aws-parameter-store-config + spring-cloud-aws-appconfig-config spring-cloud-aws-secrets-manager-config spring-cloud-starter-aws spring-cloud-starter-aws-jdbc spring-cloud-starter-aws-messaging spring-cloud-starter-aws-parameter-store-config + spring-cloud-starter-aws-appconfig-config spring-cloud-starter-aws-secrets-manager-config spring-cloud-aws-integration-test docs diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index e1e05c0a9..524aaf27e 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -99,6 +99,11 @@ spring-cloud-starter-aws-parameter-store-config ${project.version} + + org.springframework.cloud + spring-cloud-starter-aws-appconfig-config + ${project.version} + org.springframework.cloud spring-cloud-starter-aws-secrets-manager-config @@ -134,6 +139,11 @@ spring-cloud-aws-parameter-store-config ${project.version} + + org.springframework.cloud + spring-cloud-aws-appconfig-config + ${project.version} + org.springframework.cloud spring-cloud-aws-secrets-manager-config From 7eba07c73c1295ad7573e27e4c6aebac0ae8c158 Mon Sep 17 00:00:00 2001 From: jarp Date: Mon, 7 Sep 2020 14:25:24 -0500 Subject: [PATCH 38/47] feat(aws-appconfig): add aws appconfig component --- spring-cloud-aws-appconfig-config/pom.xml | 62 +++++++ .../aws/appconfig/AwsAppConfigProperties.java | 135 +++++++++++++++ .../appconfig/AwsAppConfigPropertySource.java | 159 ++++++++++++++++++ .../AwsAppConfigPropertySourceLocator.java | 91 ++++++++++ .../appconfig/AwsAppConfigPropertiesTest.java | 122 ++++++++++++++ ...AwsAppConfigPropertySourceLocatorTest.java | 134 +++++++++++++++ .../AwsAppConfigPropertySourceTest.java | 121 +++++++++++++ .../src/test/resources/config.json | 10 ++ .../src/test/resources/config.yaml | 6 + 9 files changed, 840 insertions(+) create mode 100644 spring-cloud-aws-appconfig-config/pom.xml create mode 100644 spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigProperties.java create mode 100644 spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java create mode 100644 spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java create mode 100644 spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertiesTest.java create mode 100644 spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java create mode 100644 spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java create mode 100644 spring-cloud-aws-appconfig-config/src/test/resources/config.json create mode 100644 spring-cloud-aws-appconfig-config/src/test/resources/config.yaml diff --git a/spring-cloud-aws-appconfig-config/pom.xml b/spring-cloud-aws-appconfig-config/pom.xml new file mode 100644 index 000000000..68f6d4809 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.springframework.cloud + spring-cloud-aws + 2.3.0.BUILD-SNAPSHOT + + + spring-cloud-aws-appconfig-config + + Spring Cloud AWS AppConfig Configuration + Spring Cloud AWS AppConfig Configuration + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-autoconfigure + + + + org.springframework.cloud + spring-cloud-context + + + + com.amazonaws + aws-java-sdk-appconfig + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + diff --git a/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigProperties.java b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigProperties.java new file mode 100644 index 000000000..81c1ac384 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigProperties.java @@ -0,0 +1,135 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.StringUtils; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +/** + * @author jarpz + */ +@ConfigurationProperties(AwsAppConfigProperties.CONFIG_PREFIX) +public class AwsAppConfigProperties implements Validator { + + /** + * Configuration prefix. + */ + public static final String CONFIG_PREFIX = "aws.appconfig"; + + private String accountId; + + private String application; + + private String environment; + + private String configurationProfile; + + private String configurationVersion; + + private String region; + + private boolean failFast; + + @Override + public boolean supports(Class clazz) { + return AwsAppConfigProperties.class.isAssignableFrom(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + AwsAppConfigProperties properties = (AwsAppConfigProperties) target; + + if (StringUtils.isEmpty(properties.accountId)) { + errors.rejectValue("accountId", "NotEmpty", + "account-id should not be empty or null."); + } + + if (StringUtils.isEmpty(properties.application)) { + errors.rejectValue("application", "NotEmpty", + "application should not be empty or null."); + } + + if (StringUtils.isEmpty(properties.environment)) { + errors.rejectValue("environment", "NotEmpty", + "environment should not be empty or null."); + } + + if (StringUtils.isEmpty(properties.configurationProfile)) { + errors.rejectValue("configurationProfile", "NotEmpty", + "configurationProfile should not be empty or null."); + } + } + + public String getAccountId() { + return accountId; + } + + public String getApplication() { + return application; + } + + public String getEnvironment() { + return environment; + } + + public String getConfigurationProfile() { + return configurationProfile; + } + + public String getConfigurationVersion() { + return configurationVersion; + } + + public String getRegion() { + return region; + } + + public boolean isFailFast() { + return failFast; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public void setApplication(String application) { + this.application = application; + } + + public void setEnvironment(String environment) { + this.environment = environment; + } + + public void setConfigurationProfile(String configurationProfile) { + this.configurationProfile = configurationProfile; + } + + public void setConfigurationVersion(String configurationVersion) { + this.configurationVersion = configurationVersion; + } + + public void setRegion(String region) { + this.region = region; + } + + public void setFailFast(boolean failFast) { + this.failFast = failFast; + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java new file mode 100644 index 000000000..d06188fd1 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java @@ -0,0 +1,159 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; + +import com.amazonaws.services.appconfig.AmazonAppConfig; +import com.amazonaws.services.appconfig.model.GetConfigurationRequest; +import com.amazonaws.services.appconfig.model.GetConfigurationResult; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.util.ReflectionUtils; + +/** + * @author jarpz + */ +public class AwsAppConfigPropertySource + extends EnumerablePropertySource { + + private static final String SUPPORTED_TYPE_JSON = "application/json"; + + private static final String SUPPORTED_TYPE_YAML = "application/x-yaml"; + + private Properties properties; + + private final AwsAppConfigProperties configProperties; + + public AwsAppConfigPropertySource(String name, AmazonAppConfig appConfigClient, + AwsAppConfigProperties configProperties) { + super(name, appConfigClient); + this.configProperties = configProperties; + } + + public void init() { + GetConfigurationRequest request = new GetConfigurationRequest() + .withClientId(configProperties.getAccountId()) + .withApplication(configProperties.getApplication()) + .withConfiguration(name) + .withClientConfigurationVersion( + configProperties.getConfigurationVersion()) + .withEnvironment(configProperties.getEnvironment()); + + getAppConfig(request); + } + + @Override + public String[] getPropertyNames() { + Set strings = properties.stringPropertyNames(); + return strings.toArray(new String[strings.size()]); + } + + @Override + public Object getProperty(String name) { + return properties.get(name); + } + + private void getAppConfig(GetConfigurationRequest request) { + GetConfigurationResult configuration = this.source.getConfiguration(request); + + logger.trace(String.format("loading file: %s/%s/%s/%s", + configProperties.getApplication(), + configProperties.getConfigurationProfile(), + configProperties.getEnvironment(), + configuration.getConfigurationVersion())); + + switch (configuration.getContentType()) { + case SUPPORTED_TYPE_YAML: + processYamlContent(configuration.getContent()); + break; + case SUPPORTED_TYPE_JSON: + processJsonContent(configuration.getContent()); + break; + default: + throw new IllegalStateException(String.format("Unsupported content type: %s", + configuration.getContentType())); + } + } + + private void processYamlContent(ByteBuffer byteBuffer) { + + YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); + + bean.setResources(new ByteArrayResource(byteBuffer.array())); + + properties = bean.getObject(); + } + + private void processJsonContent(ByteBuffer byteBuffer) { + + try { + Map map = new ObjectMapper().readValue(byteBuffer.array(), + new TypeReference>() { + }); + + Map result = new LinkedHashMap<>(); + this.flatten(null, result, map); + + properties = new Properties(); + properties.putAll(result); + } + catch (IOException ex) { + ReflectionUtils.rethrowRuntimeException(ex); + } + } + + /** + * flatten json structure. + */ + private void flatten(String prefix, Map result, + Map map) { + String namePrefix = Objects.nonNull(prefix) ? prefix + "." : ""; + + map.forEach((key, value) -> this.extract(namePrefix + key, result, value)); + } + + private void extract(String name, Map result, Object value) { + if (value instanceof Map) { + this.flatten(name, result, (Map) value); + } + else if (value instanceof Collection) { + int index = 0; + + for (Iterator it = ((Collection) value).iterator(); it.hasNext(); ++index) { + Object object = it.next(); + this.extract(name + "[" + index + "]", result, object); + } + } + else { + result.put(name, value); + } + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java new file mode 100644 index 000000000..1366afb7f --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java @@ -0,0 +1,91 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import java.util.Objects; + +import com.amazonaws.services.appconfig.AmazonAppConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.bootstrap.config.PropertySourceLocator; +import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertySource; +import org.springframework.util.ReflectionUtils; + +/** + * @author jarpz + */ +public class AwsAppConfigPropertySourceLocator implements PropertySourceLocator { + + private final AmazonAppConfig appConfigClient; + + private final AwsAppConfigProperties properties; + + private static final Log logger = LogFactory + .getLog(AwsAppConfigPropertySourceLocator.class); + + public AwsAppConfigPropertySourceLocator(AmazonAppConfig appConfigClient, + AwsAppConfigProperties properties) { + this.appConfigClient = appConfigClient; + this.properties = properties; + } + + @Override + public PropertySource locate(Environment environment) { + if (!(environment instanceof ConfigurableEnvironment)) { + return null; + } + + ConfigurableEnvironment env = (ConfigurableEnvironment) environment; + + String appName = this.properties.getConfigurationProfile(); + if (Objects.isNull(appName)) { + appName = env.getProperty("spring.application.name"); + } + + CompositePropertySource composite = new CompositePropertySource("aws-app-config"); + + try { + composite.addPropertySource(create(appName)); + } + catch (Exception ex) { + if (properties.isFailFast()) { + logger.error( + "Fail fast is set and there was an error reading configuration from AWS AppConfig: {}", + ex); + ReflectionUtils.rethrowRuntimeException(ex); + } + else { + logger.warn("Unable to load AWS AppConfig from " + appName, ex); + } + } + + return composite; + } + + private AwsAppConfigPropertySource create(String appName) { + AwsAppConfigPropertySource propertySource = new AwsAppConfigPropertySource( + appName, appConfigClient, properties); + propertySource.init(); + + return propertySource; + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertiesTest.java b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertiesTest.java new file mode 100644 index 000000000..5cfb03fc5 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertiesTest.java @@ -0,0 +1,122 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author jarpz + */ +public class AwsAppConfigPropertiesTest { + + @ParameterizedTest + @MethodSource("invalidProperties") + public void validationFails(AwsAppConfigProperties properties, String field, + String errorCode) { + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + + properties.validate(properties, errors); + + assertThat(errors.getFieldError(field)).isNotNull(); + assertThat(errors.getFieldError(field).getCode()).isEqualTo(errorCode); + } + + private static Stream invalidProperties() { + return Stream.of( + Arguments.of( + new AwsAppConfigPropertiesBuilder().withAccountId("").build(), + "accountId", "NotEmpty"), + Arguments.of( + new AwsAppConfigPropertiesBuilder().withApplication("").build(), + "application", "NotEmpty"), + Arguments.of(new AwsAppConfigPropertiesBuilder() + .withConfigurationProfile("").build(), "configurationProfile", + "NotEmpty"), + Arguments.of( + new AwsAppConfigPropertiesBuilder().withEnvironment("").build(), + "environment", "NotEmpty")); + } + + @Test + void validationSucceeds() { + AwsAppConfigProperties properties = new AwsAppConfigPropertiesBuilder() + .withAccountId("12345678").withApplication("my-project") + .withConfigurationProfile("my-app").withEnvironment("dev").build(); + + Errors errors = new BeanPropertyBindingResult(properties, "properties"); + properties.validate(properties, errors); + + assertThat(errors.getAllErrors()).isEmpty(); + } + + private static class AwsAppConfigPropertiesBuilder { + + private AwsAppConfigProperties properties = new AwsAppConfigProperties(); + + AwsAppConfigPropertiesBuilder withAccountId(String accountId) { + properties.setAccountId(accountId); + return this; + } + + AwsAppConfigPropertiesBuilder withApplication(String application) { + properties.setApplication(application); + return this; + } + + AwsAppConfigPropertiesBuilder withConfigurationProfile( + String configurationProfile) { + properties.setConfigurationProfile(configurationProfile); + return this; + } + + AwsAppConfigPropertiesBuilder withEnvironment(String environment) { + properties.setEnvironment(environment); + return this; + } + + AwsAppConfigPropertiesBuilder withConfigurationVersion(String version) { + properties.setConfigurationVersion(version); + return this; + } + + AwsAppConfigPropertiesBuilder withFailFast(boolean failFast) { + properties.setFailFast(failFast); + return this; + } + + AwsAppConfigPropertiesBuilder withRegion(String region) { + properties.setRegion(region); + return this; + } + + private AwsAppConfigProperties build() { + return properties; + } + + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java new file mode 100644 index 000000000..94e509433 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import java.nio.ByteBuffer; + +import com.amazonaws.services.appconfig.AmazonAppConfig; +import com.amazonaws.services.appconfig.model.GetConfigurationResult; +import org.apache.commons.codec.Resources; +import org.junit.jupiter.api.Test; + +import org.springframework.core.env.PropertySource; +import org.springframework.mock.env.MockEnvironment; + +import static com.amazonaws.util.IOUtils.toByteArray; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AwsAppConfigPropertySourceLocatorTest { + + private AmazonAppConfig appConfigClient = mock(AmazonAppConfig.class); + + private MockEnvironment env = new MockEnvironment(); + + private AwsAppConfigProperties properties = new AwsAppConfigProperties(); + + { + properties.setAccountId("123456789"); + properties.setApplication("my-project"); + properties.setConfigurationProfile("api-my"); + properties.setEnvironment("dev"); + } + + @Test + void whenLoadYamlAppConfigThenReturnPropertySource() throws Exception { + ByteBuffer content = ByteBuffer + .wrap(toByteArray(Resources.getInputStream("config.yaml"))); + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/x-yaml"); + result.setContent(content); + + when(appConfigClient.getConfiguration(any())).thenReturn(result); + + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( + appConfigClient, properties); + + env.setActiveProfiles("test"); + + PropertySource propertySource = locator.locate(env); + + assertThat(propertySource.getProperty("server.port")).isEqualTo(8081); + } + + @Test + void whenLoadJsonAppConfigThenReturnPropertySource() throws Exception { + ByteBuffer content = ByteBuffer + .wrap(toByteArray(Resources.getInputStream("config.json"))); + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/json"); + result.setContent(content); + + when(appConfigClient.getConfiguration(any())).thenReturn(result); + + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( + appConfigClient, properties); + + env.setActiveProfiles("test"); + + PropertySource propertySource = locator.locate(env); + + assertThat(propertySource.getProperty("server.port")).isEqualTo(8089); + } + + @Test + void whenLoadAnAppConfigAndThrowErrorThenRethrowErrorWhenFailFastTrue() { + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/json"); + + when(appConfigClient.getConfiguration(any())) + .thenThrow(new RuntimeException("connection error")); + + properties.setFailFast(true); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( + appConfigClient, properties); + + env.setActiveProfiles("test"); + + assertThatThrownBy(() -> locator.locate(env)).hasMessage("connection error"); + } + + @Test + void whenLoadAnAppConfigAndThrowErrorThenReturnEmptyWhenFailFastFalse() { + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/json"); + + when(appConfigClient.getConfiguration(any())) + .thenThrow(new RuntimeException("connection error")); + + properties.setFailFast(false); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( + appConfigClient, properties); + + env.setActiveProfiles("test"); + + assertThatCode(() -> locator.locate(env)).doesNotThrowAnyException(); + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java new file mode 100644 index 000000000..e6000c6b9 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java @@ -0,0 +1,121 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.appconfig; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import com.amazonaws.services.appconfig.AmazonAppConfig; +import com.amazonaws.services.appconfig.model.GetConfigurationRequest; +import com.amazonaws.services.appconfig.model.GetConfigurationResult; +import org.apache.commons.codec.Resources; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import static com.amazonaws.util.IOUtils.toByteArray; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AwsAppConfigPropertySourceTest { + + private AmazonAppConfig appConfigClient = mock(AmazonAppConfig.class); + + private AwsAppConfigProperties properties = new AwsAppConfigProperties(); + + { + properties.setAccountId("123456789"); + properties.setApplication("my-project"); + properties.setConfigurationProfile("api-my"); + properties.setEnvironment("dev"); + } + + @Test + void requestYamlAppConfigExpectSuccessProperties() throws IOException { + + ByteBuffer content = ByteBuffer + .wrap(toByteArray(Resources.getInputStream("config.yaml"))); + + ArgumentCaptor captor = ArgumentCaptor + .forClass(GetConfigurationRequest.class); + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/x-yaml"); + result.setContent(content); + + when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); + + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", + appConfigClient, properties); + + source.init(); + + assertThat(source.getProperty("spring.application.name")).isEqualTo("my-app"); + assertThat(source.getProperty("server.port")).isEqualTo(8081); + + assertThat(captor.getValue().getConfiguration()).isEqualTo("my-api"); + } + + @Test + public void requestJsonAppConfigExpectSuccessProperties() throws Exception { + ByteBuffer content = ByteBuffer + .wrap(toByteArray(Resources.getInputStream("config.json"))); + + ArgumentCaptor captor = ArgumentCaptor + .forClass(GetConfigurationRequest.class); + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("application/json"); + result.setContent(content); + + when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); + + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", + appConfigClient, properties); + + source.init(); + + assertThat(source.getProperty("spring.application.name")).isEqualTo("my-app"); + assertThat(source.getProperty("server.port")).isEqualTo(8089); + + assertThat(captor.getValue().getConfiguration()).isEqualTo("my-api"); + } + + @Test + public void requestUnsupportedAppConfigContentType() { + + ArgumentCaptor captor = ArgumentCaptor + .forClass(GetConfigurationRequest.class); + + GetConfigurationResult result = new GetConfigurationResult(); + result.setConfigurationVersion("1"); + result.setContentType("text/plain"); + + when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); + + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", + appConfigClient, properties); + + Assertions.assertThatThrownBy(source::init) + .isInstanceOf(IllegalStateException.class); + + } + +} diff --git a/spring-cloud-aws-appconfig-config/src/test/resources/config.json b/spring-cloud-aws-appconfig-config/src/test/resources/config.json new file mode 100644 index 000000000..429518af1 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/test/resources/config.json @@ -0,0 +1,10 @@ +{ + "spring": { + "application": { + "name": "my-app" + } + }, + "server": { + "port": 8089 + } +} diff --git a/spring-cloud-aws-appconfig-config/src/test/resources/config.yaml b/spring-cloud-aws-appconfig-config/src/test/resources/config.yaml new file mode 100644 index 000000000..42d0ac7d1 --- /dev/null +++ b/spring-cloud-aws-appconfig-config/src/test/resources/config.yaml @@ -0,0 +1,6 @@ +spring: + application.name: my-app + main: + webflux.base-path: /my-controller + +server.port: 8081 From 241d6d3c112beea3c6b9896b799bb1d007216b4a Mon Sep 17 00:00:00 2001 From: jarp Date: Mon, 7 Sep 2020 14:26:21 -0500 Subject: [PATCH 39/47] feat(aws-appconfig): add starter appconfig --- .../pom.xml | 52 +++++++++++++ .../AwsAppConfigBootstrapConfiguration.java | 65 ++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 + ...wsAppConfigBootstrapConfigurationTest.java | 75 +++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 spring-cloud-starter-aws-appconfig-config/pom.xml create mode 100644 spring-cloud-starter-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java create mode 100644 spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories create mode 100644 spring-cloud-starter-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java diff --git a/spring-cloud-starter-aws-appconfig-config/pom.xml b/spring-cloud-starter-aws-appconfig-config/pom.xml new file mode 100644 index 000000000..78a8a9734 --- /dev/null +++ b/spring-cloud-starter-aws-appconfig-config/pom.xml @@ -0,0 +1,52 @@ + + + + + 4.0.0 + + org.springframework.cloud + spring-cloud-aws + 2.3.0.BUILD-SNAPSHOT + + + spring-cloud-starter-aws-appconfig-config + Spring Cloud AWS AppConfig Configuration Starter + Spring Cloud AWS AppConfig Configuration Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + ${basedir}/../.. + + + + + org.springframework.cloud + spring-cloud-aws-appconfig-config + + + + org.springframework.cloud + spring-cloud-aws-autoconfigure + + + + diff --git a/spring-cloud-starter-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java b/spring-cloud-starter-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java new file mode 100644 index 000000000..7d5ca54c8 --- /dev/null +++ b/spring-cloud-starter-aws-appconfig-config/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.autoconfigure.appconfig; + +import com.amazonaws.services.appconfig.AmazonAppConfig; +import com.amazonaws.services.appconfig.AmazonAppConfigAsync; +import com.amazonaws.services.appconfig.AmazonAppConfigClientBuilder; +import com.amazonaws.util.StringUtils; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.aws.appconfig.AwsAppConfigProperties; +import org.springframework.cloud.aws.appconfig.AwsAppConfigPropertySourceLocator; +import org.springframework.cloud.aws.core.SpringCloudClientConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author jarpz + */ +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties({ AwsAppConfigProperties.class }) +@ConditionalOnClass({ AmazonAppConfigAsync.class, + AwsAppConfigPropertySourceLocator.class }) +@ConditionalOnProperty(prefix = "aws.appconfig", name = { "enabled" }, + matchIfMissing = true) +public class AwsAppConfigBootstrapConfiguration { + + @Bean + AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator( + AmazonAppConfig appConfigClient, AwsAppConfigProperties properties) { + return new AwsAppConfigPropertySourceLocator(appConfigClient, properties); + } + + @Bean + @ConditionalOnMissingBean + public AmazonAppConfig appConfigClient( + AwsAppConfigProperties awsAppConfigProperties) { + + AmazonAppConfigClientBuilder builder = AmazonAppConfigClientBuilder.standard() + .withClientConfiguration( + SpringCloudClientConfiguration.getClientConfiguration()); + + return StringUtils.isNullOrEmpty(awsAppConfigProperties.getRegion()) + ? builder.build() + : builder.withRegion(awsAppConfigProperties.getRegion()).build(); + } + +} diff --git a/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..02bc6bb8f --- /dev/null +++ b/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.cloud.bootstrap.BootstrapConfiguration=\ +org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration diff --git a/spring-cloud-starter-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java b/spring-cloud-starter-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java new file mode 100644 index 000000000..b4bf625d9 --- /dev/null +++ b/spring-cloud-starter-aws-appconfig-config/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.aws.autoconfigure.appconfig; + +import java.lang.reflect.Method; + +import com.amazonaws.AmazonWebServiceClient; +import com.amazonaws.services.appconfig.AmazonAppConfigClient; +import org.junit.jupiter.api.Test; + +import org.springframework.cloud.aws.appconfig.AwsAppConfigProperties; +import org.springframework.util.ReflectionUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AwsAppConfigBootstrapConfigurationTest { + + AwsAppConfigBootstrapConfiguration bootstrapConfig = new AwsAppConfigBootstrapConfiguration(); + + @Test + void testWithStaticRegion() { + String region = "us-east-2"; + AmazonAppConfigClient appConfigClient = createAppConfigAsync(region); + + Method signingRegionMethod = ReflectionUtils + .findMethod(AmazonWebServiceClient.class, "getSigningRegion"); + + signingRegionMethod.setAccessible(true); + + String signedRegion = (String) ReflectionUtils.invokeMethod(signingRegionMethod, + appConfigClient); + + assertThat(signedRegion).isEqualTo(region); + } + + @Test + void testUserAgent() { + String region = "us-east-2"; + AmazonAppConfigClient appConfigClient = createAppConfigAsync(region); + + assertThat(appConfigClient.getClientConfiguration().getUserAgentSuffix()) + .startsWith("spring-cloud-aws/"); + } + + private AmazonAppConfigClient createAppConfigAsync(String region) { + AwsAppConfigProperties awsAppConfigProperties = new AwsAppConfigProperties(); + awsAppConfigProperties.setRegion(region); + + Method appConfigAsync = ReflectionUtils.findMethod( + AwsAppConfigBootstrapConfiguration.class, "appConfigClient", + AwsAppConfigProperties.class); + + appConfigAsync.setAccessible(true); + + AmazonAppConfigClient appConfigClient = (AmazonAppConfigClient) ReflectionUtils + .invokeMethod(appConfigAsync, bootstrapConfig, awsAppConfigProperties); + + return appConfigClient; + } + +} From 33d2559fc6982ce57e1969ce9b6dab84c4a9336c Mon Sep 17 00:00:00 2001 From: jarp Date: Tue, 15 Sep 2020 16:28:50 -0500 Subject: [PATCH 40/47] feat(aws-appconfig): rename module removing config suffix --- spring-cloud-aws-autoconfigure/pom.xml | 5 +++ spring-cloud-aws-dependencies/pom.xml | 4 +- spring-cloud-starter-aws-appconfig/pom.xml | 52 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 spring-cloud-starter-aws-appconfig/pom.xml diff --git a/spring-cloud-aws-autoconfigure/pom.xml b/spring-cloud-aws-autoconfigure/pom.xml index d3c4fae3b..aae8f9b8a 100644 --- a/spring-cloud-aws-autoconfigure/pom.xml +++ b/spring-cloud-aws-autoconfigure/pom.xml @@ -48,6 +48,11 @@ spring-cloud-aws-parameter-store-config true + + org.springframework.cloud + spring-cloud-aws-appconfig + true + org.springframework.boot spring-boot-autoconfigure diff --git a/spring-cloud-aws-dependencies/pom.xml b/spring-cloud-aws-dependencies/pom.xml index 524aaf27e..16acb1503 100644 --- a/spring-cloud-aws-dependencies/pom.xml +++ b/spring-cloud-aws-dependencies/pom.xml @@ -101,7 +101,7 @@ org.springframework.cloud - spring-cloud-starter-aws-appconfig-config + spring-cloud-starter-aws-appconfig ${project.version} @@ -141,7 +141,7 @@ org.springframework.cloud - spring-cloud-aws-appconfig-config + spring-cloud-aws-appconfig ${project.version} diff --git a/spring-cloud-starter-aws-appconfig/pom.xml b/spring-cloud-starter-aws-appconfig/pom.xml new file mode 100644 index 000000000..0c03eb6a2 --- /dev/null +++ b/spring-cloud-starter-aws-appconfig/pom.xml @@ -0,0 +1,52 @@ + + + + + 4.0.0 + + org.springframework.cloud + spring-cloud-aws + 2.3.0.BUILD-SNAPSHOT + + + spring-cloud-starter-aws-appconfig + Spring Cloud AWS AppConfig Configuration Starter + Spring Cloud AWS AppConfig Configuration Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + ${basedir}/../.. + + + + + org.springframework.cloud + spring-cloud-aws-appconfig + + + + org.springframework.cloud + spring-cloud-aws-autoconfigure + + + + From d21e4dc1ab17f902839dae4067a86cdd2bcb26a0 Mon Sep 17 00:00:00 2001 From: jarp Date: Tue, 15 Sep 2020 16:29:54 -0500 Subject: [PATCH 41/47] feat(aws-appconfig): move classes & fix comments --- pom.xml | 4 +- .../pom.xml | 4 +- .../appconfig/AwsAppConfigPropertySource.java | 47 +++++++++-------- .../AwsAppConfigPropertySourceLocator.java | 39 ++++++++++---- ...AwsAppConfigPropertySourceLocatorTest.java | 23 ++------ .../AwsAppConfigPropertySourceTest.java | 20 ++----- .../src/test/resources/config.json | 0 .../src/test/resources/config.yaml | 0 .../AwsAppConfigBootstrapConfiguration.java | 11 ++-- .../appconfig/AwsAppConfigProperties.java | 13 ++--- .../main/resources/META-INF/spring.factories | 3 +- ...wsAppConfigBootstrapConfigurationTest.java | 5 +- .../appconfig/AwsAppConfigPropertiesTest.java | 7 +-- .../pom.xml | 52 ------------------- .../main/resources/META-INF/spring.factories | 2 - 15 files changed, 84 insertions(+), 146 deletions(-) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/pom.xml (94%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java (79%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java (70%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java (88%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java (89%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/test/resources/config.json (100%) rename {spring-cloud-aws-appconfig-config => spring-cloud-aws-appconfig}/src/test/resources/config.yaml (100%) rename {spring-cloud-starter-aws-appconfig-config => spring-cloud-aws-autoconfigure}/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java (84%) rename {spring-cloud-aws-appconfig-config/src/main/java/org/springframework/cloud/aws => spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure}/appconfig/AwsAppConfigProperties.java (88%) rename {spring-cloud-starter-aws-appconfig-config => spring-cloud-aws-autoconfigure}/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java (94%) rename {spring-cloud-aws-appconfig-config/src/test/java/org/springframework/cloud/aws => spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure}/appconfig/AwsAppConfigPropertiesTest.java (93%) delete mode 100644 spring-cloud-starter-aws-appconfig-config/pom.xml delete mode 100644 spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories diff --git a/pom.xml b/pom.xml index e7a726593..94dfe5296 100644 --- a/pom.xml +++ b/pom.xml @@ -59,13 +59,13 @@ spring-cloud-aws-messaging spring-cloud-aws-autoconfigure spring-cloud-aws-parameter-store-config - spring-cloud-aws-appconfig-config + spring-cloud-aws-appconfig spring-cloud-aws-secrets-manager-config spring-cloud-starter-aws spring-cloud-starter-aws-jdbc spring-cloud-starter-aws-messaging spring-cloud-starter-aws-parameter-store-config - spring-cloud-starter-aws-appconfig-config + spring-cloud-starter-aws-appconfig spring-cloud-starter-aws-secrets-manager-config spring-cloud-aws-integration-test docs diff --git a/spring-cloud-aws-appconfig-config/pom.xml b/spring-cloud-aws-appconfig/pom.xml similarity index 94% rename from spring-cloud-aws-appconfig-config/pom.xml rename to spring-cloud-aws-appconfig/pom.xml index 68f6d4809..abb4ca8b1 100644 --- a/spring-cloud-aws-appconfig-config/pom.xml +++ b/spring-cloud-aws-appconfig/pom.xml @@ -1,6 +1,6 @@ - - - 4.0.0 - - org.springframework.cloud - spring-cloud-aws - 2.3.0.BUILD-SNAPSHOT - - - spring-cloud-starter-aws-appconfig-config - Spring Cloud AWS AppConfig Configuration Starter - Spring Cloud AWS AppConfig Configuration Starter - https://projects.spring.io/spring-cloud - - Pivotal Software, Inc. - https://www.spring.io - - - ${basedir}/../.. - - - - - org.springframework.cloud - spring-cloud-aws-appconfig-config - - - - org.springframework.cloud - spring-cloud-aws-autoconfigure - - - - diff --git a/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 02bc6bb8f..000000000 --- a/spring-cloud-starter-aws-appconfig-config/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration From ebd950e9daf1077931d3a39859082a0856d7da06 Mon Sep 17 00:00:00 2001 From: jarp Date: Wed, 16 Sep 2020 11:45:31 -0500 Subject: [PATCH 42/47] feat(aws-appconfig): remove unused dependencies --- spring-cloud-aws-appconfig/pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spring-cloud-aws-appconfig/pom.xml b/spring-cloud-aws-appconfig/pom.xml index abb4ca8b1..79786a8b0 100644 --- a/spring-cloud-aws-appconfig/pom.xml +++ b/spring-cloud-aws-appconfig/pom.xml @@ -36,11 +36,6 @@ spring-context - - org.springframework.boot - spring-boot-autoconfigure - - org.springframework.cloud spring-cloud-context @@ -50,13 +45,5 @@ com.amazonaws aws-java-sdk-appconfig - - - org.springframework.boot - spring-boot-configuration-processor - true - - - From c373eecd7e6dd68e933d57ab14d420ff5cb0b860 Mon Sep 17 00:00:00 2001 From: jarp Date: Wed, 16 Sep 2020 19:39:03 -0500 Subject: [PATCH 43/47] test(aws-appconfig): change tests to use ApplicationContextRunner --- ...wsAppConfigBootstrapConfigurationTest.java | 57 ++++++++----------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java index 229578340..3945ff5b2 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java @@ -18,59 +18,48 @@ import java.lang.reflect.Method; -import com.amazonaws.AmazonWebServiceClient; +import com.amazonaws.services.appconfig.AmazonAppConfig; import com.amazonaws.services.appconfig.AmazonAppConfigClient; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; -public class AwsAppConfigBootstrapConfigurationTest { +class AwsAppConfigBootstrapConfigurationTest { - AwsAppConfigBootstrapConfiguration bootstrapConfig = new AwsAppConfigBootstrapConfiguration(); + private ApplicationContextRunner runner = new ApplicationContextRunner() + .withUserConfiguration(AwsAppConfigBootstrapConfiguration.class); + + private static String[] properties = new String[] { "aws.appconfig.region=us-east-2", + "aws.appconfig.account-id=1234567", "aws.appconfig.application=demo", + "aws.appconfig.environment=dev" }; @Test void testWithStaticRegion() { - String region = "us-east-2"; - AmazonAppConfigClient appConfigClient = createAppConfigAsync(region); - Method signingRegionMethod = ReflectionUtils - .findMethod(AmazonWebServiceClient.class, "getSigningRegion"); - + .findMethod(AmazonAppConfigClient.class, "getSigningRegion"); signingRegionMethod.setAccessible(true); - String signedRegion = (String) ReflectionUtils.invokeMethod(signingRegionMethod, - appConfigClient); + runner.withPropertyValues(properties).run(context -> { + AmazonAppConfig appConfig = context.getBean(AmazonAppConfig.class); - assertThat(signedRegion).isEqualTo(region); + assertThat(appConfig).isNotNull(); + + assertThat(ReflectionUtils.invokeMethod(signingRegionMethod, appConfig)) + .isEqualTo("us-east-2"); + }); } @Test void testUserAgent() { - String region = "us-east-2"; - AmazonAppConfigClient appConfigClient = createAppConfigAsync(region); - - Assertions - .assertThat(appConfigClient.getClientConfiguration().getUserAgentSuffix()) - .startsWith("spring-cloud-aws/"); - } - - private AmazonAppConfigClient createAppConfigAsync(String region) { - AwsAppConfigProperties awsAppConfigProperties = new AwsAppConfigProperties(); - awsAppConfigProperties.setRegion(region); - - Method appConfigAsync = ReflectionUtils.findMethod( - AwsAppConfigBootstrapConfiguration.class, "appConfigClient", - AwsAppConfigProperties.class); - - appConfigAsync.setAccessible(true); - - AmazonAppConfigClient appConfigClient = (AmazonAppConfigClient) ReflectionUtils - .invokeMethod(appConfigAsync, bootstrapConfig, awsAppConfigProperties); - - return appConfigClient; + runner.withPropertyValues(properties) + .run(context -> assertThat(context.getBean(AmazonAppConfig.class)) + .isNotNull().extracting(AmazonAppConfigClient.class::cast) + .extracting(appconfig -> appconfig.getClientConfiguration() + .getUserAgentSuffix()) + .asString().startsWith("spring-cloud-aws/")); } } From fd58ab1bb8d61cc61db4044773973e41aebca92d Mon Sep 17 00:00:00 2001 From: jarp Date: Tue, 22 Sep 2020 17:01:28 -0500 Subject: [PATCH 44/47] feat(aws-appconfig): change properties prefix to spring.cloud.aws.* + change spring.factories BootstrapConfiguration + improve tests --- .../AwsAppConfigBootstrapConfiguration.java | 41 ++++++---- .../appconfig/AwsAppConfigProperties.java | 7 +- ...itional-spring-configuration-metadata.json | 6 ++ .../main/resources/META-INF/spring.factories | 6 +- ...wsAppConfigBootstrapConfigurationTest.java | 21 +++--- .../appconfig/AwsAppConfigPropertiesTest.java | 75 +++++-------------- 6 files changed, 63 insertions(+), 93 deletions(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java index b1d7f97d6..870ab1097 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java @@ -16,17 +16,20 @@ package org.springframework.cloud.aws.autoconfigure.appconfig; -import com.amazonaws.services.appconfig.AmazonAppConfig; +import java.util.Objects; + import com.amazonaws.services.appconfig.AmazonAppConfigAsync; -import com.amazonaws.services.appconfig.AmazonAppConfigClientBuilder; -import com.amazonaws.util.StringUtils; +import com.amazonaws.services.appconfig.AmazonAppConfigClient; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.aws.appconfig.AwsAppConfigPropertySourceLocator; -import org.springframework.cloud.aws.core.SpringCloudClientConfiguration; +import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean; +import org.springframework.cloud.aws.core.region.RegionProvider; +import org.springframework.cloud.aws.core.region.StaticRegionProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -37,12 +40,25 @@ @EnableConfigurationProperties(AwsAppConfigProperties.class) @ConditionalOnClass({ AmazonAppConfigAsync.class, AwsAppConfigPropertySourceLocator.class }) -@ConditionalOnProperty(prefix = "aws.appconfig", name = "enabled", matchIfMissing = true) +@ConditionalOnProperty(prefix = "spring.cloud.aws.appconfig", name = "enabled", + matchIfMissing = true) public class AwsAppConfigBootstrapConfiguration { + private final AwsAppConfigProperties properties; + + private final RegionProvider regionProvider; + + public AwsAppConfigBootstrapConfiguration(AwsAppConfigProperties properties, + ObjectProvider regionProvider) { + this.properties = properties; + this.regionProvider = Objects.isNull(properties.getRegion()) + ? regionProvider.getIfAvailable() + : new StaticRegionProvider(properties.getRegion()); + } + @Bean AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator( - AmazonAppConfig appConfigClient, AwsAppConfigProperties properties) { + AmazonAppConfigClient appConfigClient) { return new AwsAppConfigPropertySourceLocator(appConfigClient, properties.getAccountId(), properties.getApplication(), properties.getConfigurationProfile(), properties.getEnvironment(), @@ -51,16 +67,9 @@ AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator( @Bean @ConditionalOnMissingBean - public AmazonAppConfig appConfigClient( - AwsAppConfigProperties awsAppConfigProperties) { - - AmazonAppConfigClientBuilder builder = AmazonAppConfigClientBuilder.standard() - .withClientConfiguration( - SpringCloudClientConfiguration.getClientConfiguration()); - - return StringUtils.isNullOrEmpty(awsAppConfigProperties.getRegion()) - ? builder.build() - : builder.withRegion(awsAppConfigProperties.getRegion()).build(); + public AmazonWebserviceClientFactoryBean appConfigClient() { + return new AmazonWebserviceClientFactoryBean<>(AmazonAppConfigClient.class, null, + regionProvider); } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java index 1de7dd0a0..02d2c49c3 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java @@ -24,14 +24,9 @@ /** * @author jarpz */ -@ConfigurationProperties(AwsAppConfigProperties.CONFIG_PREFIX) +@ConfigurationProperties(prefix = "spring.cloud.aws.appconfig") public class AwsAppConfigProperties implements Validator { - /** - * Configuration prefix. - */ - public static final String CONFIG_PREFIX = "aws.appconfig"; - private String accountId; private String application; diff --git a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 038e43ca0..9d918bf9a 100644 --- a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -47,6 +47,12 @@ "name": "cloud.aws.stack.enabled", "description": "Enables Stack integration.", "type": "java.lang.Boolean" + }, + { + "defaultValue": true, + "name": "spring.cloud.aws.appconfig.enabled", + "description": "Enables AppConfig integration.", + "type": "java.lang.Boolean" } ] } diff --git a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories index 0def68fb4..c0ea7f066 100644 --- a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories @@ -1,3 +1,6 @@ +org.springframework.cloud.bootstrap.BootstrapConfiguration=\ +org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration + org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration,\ org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration,\ @@ -9,5 +12,4 @@ org.springframework.cloud.aws.autoconfigure.cache.ElastiCacheAutoConfiguration,\ org.springframework.cloud.aws.autoconfigure.messaging.SqsAutoConfiguration,\ org.springframework.cloud.aws.autoconfigure.messaging.SnsAutoConfiguration,\ org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration,\ -org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration,\ -org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration +org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java index 3945ff5b2..83c6bdca2 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java @@ -16,39 +16,36 @@ package org.springframework.cloud.aws.autoconfigure.appconfig; -import java.lang.reflect.Method; - import com.amazonaws.services.appconfig.AmazonAppConfig; import com.amazonaws.services.appconfig.AmazonAppConfigClient; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.util.ReflectionUtils; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; class AwsAppConfigBootstrapConfigurationTest { - private ApplicationContextRunner runner = new ApplicationContextRunner() + private final ApplicationContextRunner runner = new ApplicationContextRunner() .withUserConfiguration(AwsAppConfigBootstrapConfiguration.class); - private static String[] properties = new String[] { "aws.appconfig.region=us-east-2", - "aws.appconfig.account-id=1234567", "aws.appconfig.application=demo", - "aws.appconfig.environment=dev" }; + private static final String[] properties = new String[] { + "spring.cloud.aws.appconfig.region=us-east-2", + "spring.cloud.aws.appconfig.account-id=1234567", + "spring.cloud.aws.appconfig.application=demo", + "spring.cloud.aws.appconfig.environment=dev" }; @Test void testWithStaticRegion() { - Method signingRegionMethod = ReflectionUtils - .findMethod(AmazonAppConfigClient.class, "getSigningRegion"); - signingRegionMethod.setAccessible(true); runner.withPropertyValues(properties).run(context -> { AmazonAppConfig appConfig = context.getBean(AmazonAppConfig.class); assertThat(appConfig).isNotNull(); - assertThat(ReflectionUtils.invokeMethod(signingRegionMethod, appConfig)) - .isEqualTo("us-east-2"); + Object region = ReflectionTestUtils.getField(appConfig, "signingRegion"); + assertThat("us-east-2").isEqualTo(region); }); } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java index f5fe0a2f3..a71cf8013 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java @@ -31,11 +31,11 @@ /** * @author jarpz */ -public class AwsAppConfigPropertiesTest { +class AwsAppConfigPropertiesTest { @ParameterizedTest @MethodSource("invalidProperties") - public void validationFails(AwsAppConfigProperties properties, String field, + void validationFails(AwsAppConfigProperties properties, String field, String errorCode) { Errors errors = new BeanPropertyBindingResult(properties, "properties"); @@ -47,22 +47,18 @@ public void validationFails(AwsAppConfigProperties properties, String field, private static Stream invalidProperties() { return Stream.of( - Arguments.of( - new AwsAppConfigPropertiesBuilder().withAccountId("").build(), - "accountId", "NotEmpty"), - Arguments.of( - new AwsAppConfigPropertiesBuilder().withApplication("").build(), - "application", "NotEmpty"), - Arguments.of( - new AwsAppConfigPropertiesBuilder().withEnvironment("").build(), - "environment", "NotEmpty")); + Arguments.of(buildProperties("", null, null, null), "accountId", + "NotEmpty"), + Arguments.of(buildProperties(null, "", null, null), "application", + "NotEmpty"), + Arguments.of(buildProperties(null, null, null, ""), "environment", + "NotEmpty")); } @Test void validationSucceeds() { - AwsAppConfigProperties properties = new AwsAppConfigPropertiesBuilder() - .withAccountId("12345678").withApplication("my-project") - .withConfigurationProfile("my-app").withEnvironment("dev").build(); + AwsAppConfigProperties properties = buildProperties("12345678", "my-project", + "my-app", "dev"); Errors errors = new BeanPropertyBindingResult(properties, "properties"); properties.validate(properties, errors); @@ -70,50 +66,15 @@ void validationSucceeds() { assertThat(errors.getAllErrors()).isEmpty(); } - private static class AwsAppConfigPropertiesBuilder { - - private AwsAppConfigProperties properties = new AwsAppConfigProperties(); - - AwsAppConfigPropertiesBuilder withAccountId(String accountId) { - properties.setAccountId(accountId); - return this; - } - - AwsAppConfigPropertiesBuilder withApplication(String application) { - properties.setApplication(application); - return this; - } - - AwsAppConfigPropertiesBuilder withConfigurationProfile( - String configurationProfile) { - properties.setConfigurationProfile(configurationProfile); - return this; - } - - AwsAppConfigPropertiesBuilder withEnvironment(String environment) { - properties.setEnvironment(environment); - return this; - } - - AwsAppConfigPropertiesBuilder withConfigurationVersion(String version) { - properties.setConfigurationVersion(version); - return this; - } - - AwsAppConfigPropertiesBuilder withFailFast(boolean failFast) { - properties.setFailFast(failFast); - return this; - } - - AwsAppConfigPropertiesBuilder withRegion(String region) { - properties.setRegion(region); - return this; - } - - private AwsAppConfigProperties build() { - return properties; - } + private static AwsAppConfigProperties buildProperties(String accountId, + String application, String configurationProfile, String environment) { + AwsAppConfigProperties properties = new AwsAppConfigProperties(); + properties.setAccountId(accountId); + properties.setApplication(application); + properties.setConfigurationProfile(configurationProfile); + properties.setEnvironment(environment); + return properties; } } From 2cbf279436ff490ddfd81a9f009af1b8dd51bdbe Mon Sep 17 00:00:00 2001 From: jarp Date: Fri, 25 Sep 2020 15:06:33 -0500 Subject: [PATCH 45/47] feat(aws-appconfig): use assert when appName is empty or null --- .../aws/appconfig/AwsAppConfigPropertySourceLocator.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java index 8dc48f694..e552b4782 100644 --- a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java +++ b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java @@ -28,7 +28,7 @@ import org.springframework.util.ReflectionUtils; import static java.util.Objects.isNull; -import static java.util.Objects.requireNonNull; +import static org.springframework.util.Assert.hasText; /** * @author jarpz @@ -74,10 +74,12 @@ public PropertySource locate(Environment environment) { String appName = configurationProfile; if (isNull(appName)) { - appName = requireNonNull(env.getProperty("spring.application.name"), - "configurationProfile should not be empty or null."); + appName = env.getProperty("spring.application.name"); } + hasText(appName, + "configurationProfile or spring.application.name should not be empty or null."); + CompositePropertySource composite = new CompositePropertySource("aws-app-config"); try { From 33d96f5e6e8a74385f6049e9b0ee63d491beaf90 Mon Sep 17 00:00:00 2001 From: Jonathan Rodriguez Date: Mon, 30 Nov 2020 14:36:14 -0500 Subject: [PATCH 46/47] feat(aws-appconfig): rename accountId as clientId + allow default random clientId + use first profile name as environment if it is null --- .../appconfig/AwsAppConfigPropertySource.java | 8 ++++---- .../AwsAppConfigPropertySourceLocator.java | 20 +++++++++++++------ .../AwsAppConfigBootstrapConfiguration.java | 14 +++++++++---- .../appconfig/AwsAppConfigProperties.java | 15 +++++--------- .../appconfig/AwsAppConfigPropertiesTest.java | 6 ++---- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java index e34b5cf15..cfddf4a5c 100644 --- a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java +++ b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java @@ -47,7 +47,7 @@ public class AwsAppConfigPropertySource private static final String SUPPORTED_TYPE_YAML = "application/x-yaml"; - private final String accountId; + private final String clientId; private final String application; @@ -57,11 +57,11 @@ public class AwsAppConfigPropertySource private Properties properties; - public AwsAppConfigPropertySource(String name, String accountId, String application, + public AwsAppConfigPropertySource(String name, String clientId, String application, String environment, String configurationVersion, AmazonAppConfig appConfigClient) { super(name, appConfigClient); - this.accountId = accountId; + this.clientId = clientId; this.application = application; this.configurationVersion = configurationVersion; this.environment = environment; @@ -69,7 +69,7 @@ public AwsAppConfigPropertySource(String name, String accountId, String applicat public void init() { GetConfigurationRequest request = new GetConfigurationRequest() - .withClientId(accountId).withApplication(application) + .withClientId(clientId).withApplication(application) .withConfiguration(name) .withClientConfigurationVersion(configurationVersion) .withEnvironment(environment); diff --git a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java index e552b4782..6c41bbbdc 100644 --- a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java +++ b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java @@ -16,6 +16,8 @@ package org.springframework.cloud.aws.appconfig; +import java.util.Arrays; + import com.amazonaws.services.appconfig.AmazonAppConfig; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,7 +39,7 @@ public class AwsAppConfigPropertySourceLocator implements PropertySourceLocator private final AmazonAppConfig appConfigClient; - private final String accountId; + private final String clientId; private final String application; @@ -53,10 +55,10 @@ public class AwsAppConfigPropertySourceLocator implements PropertySourceLocator .getLog(AwsAppConfigPropertySourceLocator.class); public AwsAppConfigPropertySourceLocator(AmazonAppConfig appConfigClient, - String accountId, String application, String configurationProfile, + String clientId, String application, String configurationProfile, String environment, String configurationVersion, boolean failFast) { this.appConfigClient = appConfigClient; - this.accountId = accountId; + this.clientId = clientId; this.application = application; this.configurationProfile = configurationProfile; this.environment = environment; @@ -76,14 +78,20 @@ public PropertySource locate(Environment environment) { if (isNull(appName)) { appName = env.getProperty("spring.application.name"); } + String profile = this.environment; + if (isNull(profile)) { + profile = Arrays.stream(env.getActiveProfiles()).findFirst() + .orElse("default"); + } hasText(appName, "configurationProfile or spring.application.name should not be empty or null."); + hasText(profile, "environment or profiles should not be empty or null "); CompositePropertySource composite = new CompositePropertySource("aws-app-config"); try { - composite.addPropertySource(create(appName)); + composite.addPropertySource(create(appName, profile)); } catch (Exception ex) { if (failFast) { @@ -100,9 +108,9 @@ public PropertySource locate(Environment environment) { return composite; } - private AwsAppConfigPropertySource create(String appName) { + private AwsAppConfigPropertySource create(String appName, String profile) { AwsAppConfigPropertySource propertySource = new AwsAppConfigPropertySource( - appName, accountId, application, environment, configurationVersion, + appName, clientId, application, profile, configurationVersion, appConfigClient); propertySource.init(); diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java index 870ab1097..7f9a32af0 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.cloud.aws.autoconfigure.appconfig; import java.util.Objects; +import java.util.UUID; import com.amazonaws.services.appconfig.AmazonAppConfigAsync; import com.amazonaws.services.appconfig.AmazonAppConfigClient; @@ -32,6 +33,7 @@ import org.springframework.cloud.aws.core.region.StaticRegionProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; /** * @author jarpz @@ -59,10 +61,14 @@ public AwsAppConfigBootstrapConfiguration(AwsAppConfigProperties properties, @Bean AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator( AmazonAppConfigClient appConfigClient) { - return new AwsAppConfigPropertySourceLocator(appConfigClient, - properties.getAccountId(), properties.getApplication(), - properties.getConfigurationProfile(), properties.getEnvironment(), - properties.getConfigurationVersion(), properties.isFailFast()); + + String clientId = StringUtils.isEmpty(properties.getClientId()) + ? UUID.randomUUID().toString() : properties.getClientId(); + + return new AwsAppConfigPropertySourceLocator(appConfigClient, clientId, + properties.getApplication(), properties.getConfigurationProfile(), + properties.getEnvironment(), properties.getConfigurationVersion(), + properties.isFailFast()); } @Bean diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java index 02d2c49c3..6a09fd2b6 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java @@ -27,7 +27,7 @@ @ConfigurationProperties(prefix = "spring.cloud.aws.appconfig") public class AwsAppConfigProperties implements Validator { - private String accountId; + private String clientId; private String application; @@ -50,11 +50,6 @@ public boolean supports(Class clazz) { public void validate(Object target, Errors errors) { AwsAppConfigProperties properties = (AwsAppConfigProperties) target; - if (StringUtils.isEmpty(properties.getAccountId())) { - errors.rejectValue("accountId", "NotEmpty", - "account-id should not be empty or null."); - } - if (StringUtils.isEmpty(properties.getApplication())) { errors.rejectValue("application", "NotEmpty", "application should not be empty or null."); @@ -66,8 +61,8 @@ public void validate(Object target, Errors errors) { } } - public String getAccountId() { - return accountId; + public String getClientId() { + return clientId; } public String getApplication() { @@ -94,8 +89,8 @@ public boolean isFailFast() { return failFast; } - public void setAccountId(String accountId) { - this.accountId = accountId; + public void setClientId(String clientId) { + this.clientId = clientId; } public void setApplication(String application) { diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java index a71cf8013..aa58e73f0 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java @@ -47,8 +47,6 @@ void validationFails(AwsAppConfigProperties properties, String field, private static Stream invalidProperties() { return Stream.of( - Arguments.of(buildProperties("", null, null, null), "accountId", - "NotEmpty"), Arguments.of(buildProperties(null, "", null, null), "application", "NotEmpty"), Arguments.of(buildProperties(null, null, null, ""), "environment", @@ -66,10 +64,10 @@ void validationSucceeds() { assertThat(errors.getAllErrors()).isEmpty(); } - private static AwsAppConfigProperties buildProperties(String accountId, + private static AwsAppConfigProperties buildProperties(String clientId, String application, String configurationProfile, String environment) { AwsAppConfigProperties properties = new AwsAppConfigProperties(); - properties.setAccountId(accountId); + properties.setClientId(clientId); properties.setApplication(application); properties.setConfigurationProfile(configurationProfile); properties.setEnvironment(environment); From e3cfc4d5b45d143a22e4640a6af7803a2f87f092 Mon Sep 17 00:00:00 2001 From: Jonathan Rodriguez Date: Fri, 5 Nov 2021 11:59:03 -0500 Subject: [PATCH 47/47] feat: Align code with master branch & fix code style --- spring-cloud-aws-appconfig/pom.xml | 2 +- .../appconfig/AwsAppConfigPropertySource.java | 28 +++++++---------- .../AwsAppConfigPropertySourceLocator.java | 22 +++++--------- ...AwsAppConfigPropertySourceLocatorTest.java | 28 ++++++++--------- .../AwsAppConfigPropertySourceTest.java | 30 ++++++++----------- .../AwsAppConfigBootstrapConfiguration.java | 24 ++++++--------- .../appconfig/AwsAppConfigProperties.java | 6 ++-- ...wsAppConfigBootstrapConfigurationTest.java | 15 ++++------ .../appconfig/AwsAppConfigPropertiesTest.java | 17 ++++------- spring-cloud-starter-aws-appconfig/pom.xml | 2 +- 10 files changed, 68 insertions(+), 106 deletions(-) diff --git a/spring-cloud-aws-appconfig/pom.xml b/spring-cloud-aws-appconfig/pom.xml index 79786a8b0..6f43836b3 100644 --- a/spring-cloud-aws-appconfig/pom.xml +++ b/spring-cloud-aws-appconfig/pom.xml @@ -21,7 +21,7 @@ org.springframework.cloud spring-cloud-aws - 2.3.0.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-aws-appconfig diff --git a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java index cfddf4a5c..052612664 100644 --- a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java +++ b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.java @@ -40,8 +40,7 @@ /** * @author jarpz */ -public class AwsAppConfigPropertySource - extends EnumerablePropertySource { +public class AwsAppConfigPropertySource extends EnumerablePropertySource { private static final String SUPPORTED_TYPE_JSON = "application/json"; @@ -57,9 +56,8 @@ public class AwsAppConfigPropertySource private Properties properties; - public AwsAppConfigPropertySource(String name, String clientId, String application, - String environment, String configurationVersion, - AmazonAppConfig appConfigClient) { + public AwsAppConfigPropertySource(String name, String clientId, String application, String environment, + String configurationVersion, AmazonAppConfig appConfigClient) { super(name, appConfigClient); this.clientId = clientId; this.application = application; @@ -68,11 +66,9 @@ public AwsAppConfigPropertySource(String name, String clientId, String applicati } public void init() { - GetConfigurationRequest request = new GetConfigurationRequest() - .withClientId(clientId).withApplication(application) - .withConfiguration(name) - .withClientConfigurationVersion(configurationVersion) - .withEnvironment(environment); + GetConfigurationRequest request = new GetConfigurationRequest().withClientId(clientId) + .withApplication(application).withConfiguration(name) + .withClientConfigurationVersion(configurationVersion).withEnvironment(environment); getAppConfig(request); } @@ -80,7 +76,7 @@ public void init() { @Override public String[] getPropertyNames() { Set strings = properties.stringPropertyNames(); - return strings.toArray(new String[strings.size()]); + return strings.toArray(new String[0]); } @Override @@ -91,8 +87,8 @@ public Object getProperty(String name) { private void getAppConfig(GetConfigurationRequest request) { GetConfigurationResult result = this.source.getConfiguration(request); - logger.trace(String.format("loading file: %s/%s/%s/%s", application, name, - environment, result.getConfigurationVersion())); + logger.trace(String.format("loading file: %s/%s/%s/%s", application, name, environment, + result.getConfigurationVersion())); switch (result.getContentType()) { case SUPPORTED_TYPE_YAML: @@ -102,8 +98,7 @@ private void getAppConfig(GetConfigurationRequest request) { processJsonContent(result.getContent()); break; default: - throw new IllegalStateException(String.format("Unsupported content type: %s", - result.getContentType())); + throw new IllegalStateException(String.format("Unsupported content type: %s", result.getContentType())); } } @@ -135,8 +130,7 @@ private void processJsonContent(ByteBuffer byteBuffer) { /** * flatten json structure. */ - private void flatten(String prefix, Map result, - Map map) { + private void flatten(String prefix, Map result, Map map) { String namePrefix = Objects.nonNull(prefix) ? prefix + "." : ""; map.forEach((key, value) -> this.extract(namePrefix + key, result, value)); diff --git a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java index 6c41bbbdc..9eebf3cce 100644 --- a/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java +++ b/spring-cloud-aws-appconfig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.java @@ -51,12 +51,10 @@ public class AwsAppConfigPropertySourceLocator implements PropertySourceLocator private final boolean failFast; - private static final Log logger = LogFactory - .getLog(AwsAppConfigPropertySourceLocator.class); + private static final Log logger = LogFactory.getLog(AwsAppConfigPropertySourceLocator.class); - public AwsAppConfigPropertySourceLocator(AmazonAppConfig appConfigClient, - String clientId, String application, String configurationProfile, - String environment, String configurationVersion, boolean failFast) { + public AwsAppConfigPropertySourceLocator(AmazonAppConfig appConfigClient, String clientId, String application, + String configurationProfile, String environment, String configurationVersion, boolean failFast) { this.appConfigClient = appConfigClient; this.clientId = clientId; this.application = application; @@ -80,12 +78,10 @@ public PropertySource locate(Environment environment) { } String profile = this.environment; if (isNull(profile)) { - profile = Arrays.stream(env.getActiveProfiles()).findFirst() - .orElse("default"); + profile = Arrays.stream(env.getActiveProfiles()).findFirst().orElse("default"); } - hasText(appName, - "configurationProfile or spring.application.name should not be empty or null."); + hasText(appName, "configurationProfile or spring.application.name should not be empty or null."); hasText(profile, "environment or profiles should not be empty or null "); CompositePropertySource composite = new CompositePropertySource("aws-app-config"); @@ -95,8 +91,7 @@ public PropertySource locate(Environment environment) { } catch (Exception ex) { if (failFast) { - logger.error( - "Fail fast is set and there was an error reading configuration from AWS AppConfig: {}", + logger.error("Fail fast is set and there was an error reading configuration from AWS AppConfig: {}", ex); ReflectionUtils.rethrowRuntimeException(ex); } @@ -109,9 +104,8 @@ public PropertySource locate(Environment environment) { } private AwsAppConfigPropertySource create(String appName, String profile) { - AwsAppConfigPropertySource propertySource = new AwsAppConfigPropertySource( - appName, clientId, application, profile, configurationVersion, - appConfigClient); + AwsAppConfigPropertySource propertySource = new AwsAppConfigPropertySource(appName, clientId, application, + profile, configurationVersion, appConfigClient); propertySource.init(); return propertySource; diff --git a/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java b/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java index 10391be73..142bc79cd 100644 --- a/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java +++ b/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocatorTest.java @@ -42,8 +42,7 @@ public class AwsAppConfigPropertySourceLocatorTest { @Test void whenLoadYamlAppConfigThenReturnPropertySource() throws Exception { - ByteBuffer content = ByteBuffer - .wrap(toByteArray(Resources.getInputStream("config.yaml"))); + ByteBuffer content = ByteBuffer.wrap(toByteArray(Resources.getInputStream("config.yaml"))); GetConfigurationResult result = new GetConfigurationResult(); result.setConfigurationVersion("1"); @@ -52,8 +51,8 @@ void whenLoadYamlAppConfigThenReturnPropertySource() throws Exception { when(appConfigClient.getConfiguration(any())).thenReturn(result); - AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( - appConfigClient, "123456789", "my-project", "api-my", "dev", null, false); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator(appConfigClient, "123456789", + "my-project", "api-my", "dev", null, false); env.setActiveProfiles("test"); @@ -64,8 +63,7 @@ void whenLoadYamlAppConfigThenReturnPropertySource() throws Exception { @Test void whenLoadJsonAppConfigThenReturnPropertySource() throws Exception { - ByteBuffer content = ByteBuffer - .wrap(toByteArray(Resources.getInputStream("config.json"))); + ByteBuffer content = ByteBuffer.wrap(toByteArray(Resources.getInputStream("config.json"))); GetConfigurationResult result = new GetConfigurationResult(); result.setConfigurationVersion("1"); @@ -74,8 +72,8 @@ void whenLoadJsonAppConfigThenReturnPropertySource() throws Exception { when(appConfigClient.getConfiguration(any())).thenReturn(result); - AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( - appConfigClient, "123456789", "my-project", "api-my", "dev", null, false); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator(appConfigClient, "123456789", + "my-project", "api-my", "dev", null, false); env.setActiveProfiles("test"); @@ -90,11 +88,10 @@ void whenLoadAnAppConfigAndThrowErrorThenRethrowErrorWhenFailFastTrue() { result.setConfigurationVersion("1"); result.setContentType("application/json"); - when(appConfigClient.getConfiguration(any())) - .thenThrow(new RuntimeException("connection error")); + when(appConfigClient.getConfiguration(any())).thenThrow(new RuntimeException("connection error")); - AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( - appConfigClient, "123456789", "my-project", "api-my", "dev", null, true); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator(appConfigClient, "123456789", + "my-project", "api-my", "dev", null, true); env.setActiveProfiles("test"); @@ -107,11 +104,10 @@ void whenLoadAnAppConfigAndThrowErrorThenReturnEmptyWhenFailFastFalse() { result.setConfigurationVersion("1"); result.setContentType("application/json"); - when(appConfigClient.getConfiguration(any())) - .thenThrow(new RuntimeException("connection error")); + when(appConfigClient.getConfiguration(any())).thenThrow(new RuntimeException("connection error")); - AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator( - appConfigClient, "123456789", "my-project", "api-my", "dev", null, false); + AwsAppConfigPropertySourceLocator locator = new AwsAppConfigPropertySourceLocator(appConfigClient, "123456789", + "my-project", "api-my", "dev", null, false); env.setActiveProfiles("test"); diff --git a/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java b/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java index 68a5e5145..ebe6eeb90 100644 --- a/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java +++ b/spring-cloud-aws-appconfig/src/test/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceTest.java @@ -38,11 +38,9 @@ public class AwsAppConfigPropertySourceTest { @Test void requestYamlAppConfigExpectSuccessProperties() throws IOException { - ByteBuffer content = ByteBuffer - .wrap(toByteArray(Resources.getInputStream("config.yaml"))); + ByteBuffer content = ByteBuffer.wrap(toByteArray(Resources.getInputStream("config.yaml"))); - ArgumentCaptor captor = ArgumentCaptor - .forClass(GetConfigurationRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(GetConfigurationRequest.class); GetConfigurationResult result = new GetConfigurationResult(); result.setConfigurationVersion("1"); @@ -51,8 +49,8 @@ void requestYamlAppConfigExpectSuccessProperties() throws IOException { when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); - AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", - "123456789", "my-project", "dev", null, appConfigClient); + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", "123456789", "my-project", "dev", + null, appConfigClient); source.init(); @@ -64,11 +62,9 @@ void requestYamlAppConfigExpectSuccessProperties() throws IOException { @Test public void requestJsonAppConfigExpectSuccessProperties() throws Exception { - ByteBuffer content = ByteBuffer - .wrap(toByteArray(Resources.getInputStream("config.json"))); + ByteBuffer content = ByteBuffer.wrap(toByteArray(Resources.getInputStream("config.json"))); - ArgumentCaptor captor = ArgumentCaptor - .forClass(GetConfigurationRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(GetConfigurationRequest.class); GetConfigurationResult result = new GetConfigurationResult(); result.setConfigurationVersion("1"); @@ -77,8 +73,8 @@ public void requestJsonAppConfigExpectSuccessProperties() throws Exception { when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); - AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", - "123456789", "my-project", "dev", null, appConfigClient); + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", "123456789", "my-project", "dev", + null, appConfigClient); source.init(); @@ -90,8 +86,7 @@ public void requestJsonAppConfigExpectSuccessProperties() throws Exception { @Test public void requestUnsupportedAppConfigContentType() { - ArgumentCaptor captor = ArgumentCaptor - .forClass(GetConfigurationRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(GetConfigurationRequest.class); GetConfigurationResult result = new GetConfigurationResult(); result.setConfigurationVersion("1"); @@ -99,11 +94,10 @@ public void requestUnsupportedAppConfigContentType() { when(appConfigClient.getConfiguration(captor.capture())).thenReturn(result); - AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", - "123456789", "my-project", "dev", null, appConfigClient); + AwsAppConfigPropertySource source = new AwsAppConfigPropertySource("my-api", "123456789", "my-project", "dev", + null, appConfigClient); - Assertions.assertThatThrownBy(source::init) - .isInstanceOf(IllegalStateException.class); + Assertions.assertThatThrownBy(source::init).isInstanceOf(IllegalStateException.class); } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java index 7f9a32af0..d5edd6a13 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfiguration.java @@ -40,10 +40,8 @@ */ @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(AwsAppConfigProperties.class) -@ConditionalOnClass({ AmazonAppConfigAsync.class, - AwsAppConfigPropertySourceLocator.class }) -@ConditionalOnProperty(prefix = "spring.cloud.aws.appconfig", name = "enabled", - matchIfMissing = true) +@ConditionalOnClass({ AmazonAppConfigAsync.class, AwsAppConfigPropertySourceLocator.class }) +@ConditionalOnProperty(prefix = "spring.cloud.aws.appconfig", name = "enabled", matchIfMissing = true) public class AwsAppConfigBootstrapConfiguration { private final AwsAppConfigProperties properties; @@ -53,29 +51,25 @@ public class AwsAppConfigBootstrapConfiguration { public AwsAppConfigBootstrapConfiguration(AwsAppConfigProperties properties, ObjectProvider regionProvider) { this.properties = properties; - this.regionProvider = Objects.isNull(properties.getRegion()) - ? regionProvider.getIfAvailable() + this.regionProvider = Objects.isNull(properties.getRegion()) ? regionProvider.getIfAvailable() : new StaticRegionProvider(properties.getRegion()); } @Bean - AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator( - AmazonAppConfigClient appConfigClient) { + AwsAppConfigPropertySourceLocator awsAppConfigPropertySourceLocator(AmazonAppConfigClient appConfigClient) { - String clientId = StringUtils.isEmpty(properties.getClientId()) - ? UUID.randomUUID().toString() : properties.getClientId(); + String clientId = StringUtils.isEmpty(properties.getClientId()) ? UUID.randomUUID().toString() + : properties.getClientId(); - return new AwsAppConfigPropertySourceLocator(appConfigClient, clientId, - properties.getApplication(), properties.getConfigurationProfile(), - properties.getEnvironment(), properties.getConfigurationVersion(), + return new AwsAppConfigPropertySourceLocator(appConfigClient, clientId, properties.getApplication(), + properties.getConfigurationProfile(), properties.getEnvironment(), properties.getConfigurationVersion(), properties.isFailFast()); } @Bean @ConditionalOnMissingBean public AmazonWebserviceClientFactoryBean appConfigClient() { - return new AmazonWebserviceClientFactoryBean<>(AmazonAppConfigClient.class, null, - regionProvider); + return new AmazonWebserviceClientFactoryBean<>(AmazonAppConfigClient.class, null, regionProvider); } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java index 6a09fd2b6..237193be0 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigProperties.java @@ -51,13 +51,11 @@ public void validate(Object target, Errors errors) { AwsAppConfigProperties properties = (AwsAppConfigProperties) target; if (StringUtils.isEmpty(properties.getApplication())) { - errors.rejectValue("application", "NotEmpty", - "application should not be empty or null."); + errors.rejectValue("application", "NotEmpty", "application should not be empty or null."); } if (StringUtils.isEmpty(properties.getEnvironment())) { - errors.rejectValue("environment", "NotEmpty", - "environment should not be empty or null."); + errors.rejectValue("environment", "NotEmpty", "environment should not be empty or null."); } } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java index 83c6bdca2..5dd63958e 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigBootstrapConfigurationTest.java @@ -30,10 +30,8 @@ class AwsAppConfigBootstrapConfigurationTest { private final ApplicationContextRunner runner = new ApplicationContextRunner() .withUserConfiguration(AwsAppConfigBootstrapConfiguration.class); - private static final String[] properties = new String[] { - "spring.cloud.aws.appconfig.region=us-east-2", - "spring.cloud.aws.appconfig.account-id=1234567", - "spring.cloud.aws.appconfig.application=demo", + private static final String[] properties = new String[] { "spring.cloud.aws.appconfig.region=us-east-2", + "spring.cloud.aws.appconfig.account-id=1234567", "spring.cloud.aws.appconfig.application=demo", "spring.cloud.aws.appconfig.environment=dev" }; @Test @@ -52,11 +50,10 @@ void testWithStaticRegion() { @Test void testUserAgent() { runner.withPropertyValues(properties) - .run(context -> assertThat(context.getBean(AmazonAppConfig.class)) - .isNotNull().extracting(AmazonAppConfigClient.class::cast) - .extracting(appconfig -> appconfig.getClientConfiguration() - .getUserAgentSuffix()) - .asString().startsWith("spring-cloud-aws/")); + .run(context -> assertThat(context.getBean(AmazonAppConfig.class)).isNotNull() + .extracting(AmazonAppConfigClient.class::cast) + .extracting(appconfig -> appconfig.getClientConfiguration().getUserAgentSuffix()).asString() + .startsWith("spring-cloud-aws/")); } } diff --git a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java index aa58e73f0..d02c42a4e 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/org/springframework/cloud/aws/autoconfigure/appconfig/AwsAppConfigPropertiesTest.java @@ -35,8 +35,7 @@ class AwsAppConfigPropertiesTest { @ParameterizedTest @MethodSource("invalidProperties") - void validationFails(AwsAppConfigProperties properties, String field, - String errorCode) { + void validationFails(AwsAppConfigProperties properties, String field, String errorCode) { Errors errors = new BeanPropertyBindingResult(properties, "properties"); properties.validate(properties, errors); @@ -46,17 +45,13 @@ void validationFails(AwsAppConfigProperties properties, String field, } private static Stream invalidProperties() { - return Stream.of( - Arguments.of(buildProperties(null, "", null, null), "application", - "NotEmpty"), - Arguments.of(buildProperties(null, null, null, ""), "environment", - "NotEmpty")); + return Stream.of(Arguments.of(buildProperties(null, "", null, null), "application", "NotEmpty"), + Arguments.of(buildProperties(null, null, null, ""), "environment", "NotEmpty")); } @Test void validationSucceeds() { - AwsAppConfigProperties properties = buildProperties("12345678", "my-project", - "my-app", "dev"); + AwsAppConfigProperties properties = buildProperties("12345678", "my-project", "my-app", "dev"); Errors errors = new BeanPropertyBindingResult(properties, "properties"); properties.validate(properties, errors); @@ -64,8 +59,8 @@ void validationSucceeds() { assertThat(errors.getAllErrors()).isEmpty(); } - private static AwsAppConfigProperties buildProperties(String clientId, - String application, String configurationProfile, String environment) { + private static AwsAppConfigProperties buildProperties(String clientId, String application, + String configurationProfile, String environment) { AwsAppConfigProperties properties = new AwsAppConfigProperties(); properties.setClientId(clientId); properties.setApplication(application); diff --git a/spring-cloud-starter-aws-appconfig/pom.xml b/spring-cloud-starter-aws-appconfig/pom.xml index 0c03eb6a2..6559dca6b 100644 --- a/spring-cloud-starter-aws-appconfig/pom.xml +++ b/spring-cloud-starter-aws-appconfig/pom.xml @@ -22,7 +22,7 @@ org.springframework.cloud spring-cloud-aws - 2.3.0.BUILD-SNAPSHOT + 3.0.0-SNAPSHOT spring-cloud-starter-aws-appconfig