From dceb85812c7951cf5ab69bae40ec136d5bd7ed04 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 23 Nov 2022 02:52:03 +0000 Subject: [PATCH] Bumping versions --- ...terStoreEnvironmentRepositoryUnitTest.java | 84 ++- ...ameterStoreEnvironmentRepositoryTests.java | 236 +++------ .../AwsS3EnvironmentRepositoryTests.java | 82 ++- ...retsManagerEnvironmentRepositoryTests.java | 500 ++++++++---------- 4 files changed, 363 insertions(+), 539 deletions(-) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java index 25048425..a10df257 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java @@ -50,7 +50,8 @@ import static org.mockito.Mockito.when; import static org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentProperties.DEFAULT_PATH_SEPARATOR; /** - * Unit test is must for testing paginated logic, since doing it with integration test is not that easy. + * Unit test is must for testing paginated logic, since doing it with integration test is + * not that easy. * * @author Iulian Antohe */ @@ -62,15 +63,20 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { put("spring.cache.redis.time-to-live", "0"); } }; + private static final Map SHARED_DEFAULT_PROPERTIES = new HashMap() { { put("logging.level.root", "error"); put("spring.cache.redis.time-to-live", "1000"); } }; + private final SsmClient ssmClient = mock(SsmClient.class, "aws-ssm-client-mock"); + private final ConfigServerProperties configServerProperties = new ConfigServerProperties(); + private final AwsParameterStoreEnvironmentProperties environmentProperties = new AwsParameterStoreEnvironmentProperties(); + private final AwsParameterStoreEnvironmentRepository repository = new AwsParameterStoreEnvironmentRepository( ssmClient, configServerProperties, environmentProperties); @@ -84,12 +90,10 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { environmentProperties.setMaxResults(1); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -100,29 +104,24 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } - private void setupAwsSsmClientMocks(Environment environment, - boolean withSlashesForPropertyName, boolean paginatedResponse) { + private void setupAwsSsmClientMocks(Environment environment, boolean withSlashesForPropertyName, + boolean paginatedResponse) { for (PropertySource ps : environment.getPropertySources()) { - String path = StringUtils.delete(ps.getName(), - environmentProperties.getOrigin()); + String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin()); - GetParametersByPathRequest request = GetParametersByPathRequest.builder() - .path(path).recursive(environmentProperties.isRecursive()) + GetParametersByPathRequest request = GetParametersByPathRequest.builder().path(path) + .recursive(environmentProperties.isRecursive()) .withDecryption(environmentProperties.isDecryptValues()) .maxResults(environmentProperties.getMaxResults()).build(); - Set parameters = getParameters(ps, path, - withSlashesForPropertyName); + Set parameters = getParameters(ps, path, withSlashesForPropertyName); - GetParametersByPathResponse response = GetParametersByPathResponse.builder() - .parameters(parameters).build(); + GetParametersByPathResponse response = GetParametersByPathResponse.builder().parameters(parameters).build(); - if (paginatedResponse - && environmentProperties.getMaxResults() < parameters.size()) { + if (paginatedResponse && environmentProperties.getMaxResults() < parameters.size()) { List> chunks = splitParametersIntoChunks(parameters); String nextToken = null; @@ -133,32 +132,26 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { if (i == 0) { nextToken = generateNextToken(); - GetParametersByPathResponse responseClone = response.toBuilder() - .parameters(chunk).nextToken(nextToken).build(); + GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk) + .nextToken(nextToken).build(); - when(ssmClient.getParametersByPath(eq(request))) - .thenReturn(responseClone); + when(ssmClient.getParametersByPath(eq(request))).thenReturn(responseClone); } else if (i == chunks.size() - 1) { - GetParametersByPathRequest requestClone = request.toBuilder() - .nextToken(nextToken).build(); - GetParametersByPathResponse responseClone = response.toBuilder() - .parameters(chunk).build(); + GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build(); + GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk).build(); - when(ssmClient.getParametersByPath(eq(requestClone))) - .thenReturn(responseClone); + when(ssmClient.getParametersByPath(eq(requestClone))).thenReturn(responseClone); } else { String newNextToken = generateNextToken(); - GetParametersByPathRequest requestClone = request.toBuilder() - .nextToken(nextToken).build(); + GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build(); - GetParametersByPathResponse responseClone = response.toBuilder() - .parameters(chunk).nextToken(newNextToken).build(); + GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk) + .nextToken(newNextToken).build(); - when(ssmClient.getParametersByPath(eq(requestClone))) - .thenReturn(responseClone); + when(ssmClient.getParametersByPath(eq(requestClone))).thenReturn(responseClone); nextToken = newNextToken; } @@ -172,25 +165,19 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { private Set getParameters(PropertySource propertySource, String path, boolean withSlashesForPropertyName) { - Function, Parameter> mapper = p -> Parameter.builder() - .name(path + (withSlashesForPropertyName - ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) - : p.getKey())) - .type(ParameterType.STRING).value((String) p.getValue()).version(1L) - .build(); + Function, Parameter> mapper = p -> Parameter + .builder().name(path + (withSlashesForPropertyName + ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) : p.getKey())) + .type(ParameterType.STRING).value((String) p.getValue()).version(1L).build(); - return propertySource.getSource().entrySet().stream().map(mapper) - .collect(Collectors.toSet()); + return propertySource.getSource().entrySet().stream().map(mapper).collect(Collectors.toSet()); } private List> splitParametersIntoChunks(Set parameters) { AtomicInteger counter = new AtomicInteger(); Collector>> collector = Collectors - .groupingBy( - p -> counter.getAndIncrement() - / environmentProperties.getMaxResults(), - Collectors.toSet()); + .groupingBy(p -> counter.getAndIncrement() / environmentProperties.getMaxResults(), Collectors.toSet()); return new ArrayList<>(parameters.stream().collect(collector).values()); } @@ -198,8 +185,7 @@ public class AWSParameterStoreEnvironmentRepositoryUnitTest { private String generateNextToken() { String random = randomAlphabetic(RandomUtils.nextInt(3, 33)); - return Base64.getEncoder() - .encodeToString(random.getBytes(StandardCharsets.UTF_8)); + return Base64.getEncoder().encodeToString(random.getBytes(StandardCharsets.UTF_8)); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java index 7618bd6e..9c759d25 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java @@ -66,13 +66,11 @@ public class AwsParameterStoreEnvironmentRepositoryTests { DockerImageName.parse("localstack/localstack:0.14.2")).withServices(SSM); private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider - .create(AwsBasicCredentials.create(localstack.getAccessKey(), - localstack.getSecretKey())); + .create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())); - private final SsmClient ssmClient = SsmClient.builder() - .region(Region.of(localstack.getRegion())) - .credentialsProvider(staticCredentialsProvider) - .endpointOverride(localstack.getEndpointOverride(SSM)).build(); + private final SsmClient ssmClient = SsmClient.builder().region(Region.of(localstack.getRegion())) + .credentialsProvider(staticCredentialsProvider).endpointOverride(localstack.getEndpointOverride(SSM)) + .build(); private final ConfigServerProperties configServerProperties = new ConfigServerProperties(); @@ -85,8 +83,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { @AfterEach public void cleanUp() { - toBeRemoved.forEach(value -> ssmClient - .deleteParameter(DeleteParameterRequest.builder().name(value).build())); + toBeRemoved.forEach(value -> ssmClient.deleteParameter(DeleteParameterRequest.builder().name(value).build())); toBeRemoved.clear(); } @@ -100,12 +97,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -116,8 +111,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -129,12 +123,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -145,8 +137,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -169,8 +160,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -182,12 +172,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -198,8 +186,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -211,12 +198,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -227,8 +212,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -239,12 +223,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -255,8 +237,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -278,8 +259,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -290,12 +270,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -306,8 +284,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -319,12 +296,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -335,8 +310,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -347,12 +321,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -363,8 +335,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -386,8 +357,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -398,12 +368,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -414,8 +382,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -427,25 +394,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); putParameters(expected); @@ -453,8 +418,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -465,25 +429,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); putParameters(expected); @@ -491,8 +453,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -507,8 +468,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(appSpecificParamsPs, sharedParamsPs)); @@ -519,8 +479,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -531,25 +490,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/"; - PropertySource appSpecificProdParamsPs = new PropertySource( - appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); + PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName, + APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificParamsPs, sharedParamsPs)); putParameters(expected); @@ -557,8 +514,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -569,34 +525,30 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/"; - PropertySource appSpecificProdParamsPs = new PropertySource( - appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); + PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName, + APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, - appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, - sharedParamsPs)); + expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificDefaultParamsPs, + sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); putParameters(expected); @@ -604,8 +556,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -628,17 +579,14 @@ public class AwsParameterStoreEnvironmentRepositoryTests { PropertySource overridesPs = new PropertySource("overrides", overrides); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll( - Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs)); + expected.addAll(Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs)); putParameters(expected); @@ -646,8 +594,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -658,12 +605,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -674,8 +619,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -691,8 +635,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -720,16 +663,13 @@ public class AwsParameterStoreEnvironmentRepositoryTests { putParameters(environment, false); } - private void putParameters(Environment environment, - boolean withSlashesForPropertyName) { + private void putParameters(Environment environment, boolean withSlashesForPropertyName) { for (PropertySource ps : environment.getPropertySources()) { - String path = StringUtils.delete(ps.getName(), - environmentProperties.getOrigin()); - Set parameters = getParameters(ps, path, - withSlashesForPropertyName); + String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin()); + Set parameters = getParameters(ps, path, withSlashesForPropertyName); parameters.forEach(value -> { - ssmClient.putParameter(PutParameterRequest.builder().name(value.name()) - .dataType("text").value(value.value()).build()); + ssmClient.putParameter( + PutParameterRequest.builder().name(value.name()).dataType("text").value(value.value()).build()); toBeRemoved.add(value.name()); }); } @@ -737,15 +677,12 @@ public class AwsParameterStoreEnvironmentRepositoryTests { private Set getParameters(PropertySource propertySource, String path, boolean withSlashesForPropertyName) { - Function, Parameter> mapper = p -> Parameter.builder() - .name(path + (withSlashesForPropertyName - ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) - : p.getKey())) - .type(ParameterType.STRING).value((String) p.getValue()).version(1L) - .build(); + Function, Parameter> mapper = p -> Parameter + .builder().name(path + (withSlashesForPropertyName + ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) : p.getKey())) + .type(ParameterType.STRING).value((String) p.getValue()).version(1L).build(); - return propertySource.getSource().entrySet().stream().map(mapper) - .collect(Collectors.toSet()); + return propertySource.getSource().entrySet().stream().map(mapper).collect(Collectors.toSet()); } @Test @@ -803,4 +740,5 @@ public class AwsParameterStoreEnvironmentRepositoryTests { put("spring.cache.redis.time-to-live", "300000"); } }; + } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java index a9b8c321..e6be5bad 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java @@ -63,34 +63,27 @@ public class AwsS3EnvironmentRepositoryTests { private final ConfigServerProperties server = new ConfigServerProperties(); private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider - .create(AwsBasicCredentials.create(localstack.getAccessKey(), - localstack.getSecretKey())); + .create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())); - private final S3Client s3Client = S3Client.builder() - .region(Region.of(localstack.getRegion())) - .credentialsProvider(staticCredentialsProvider) - .endpointOverride(localstack.getEndpointOverride(S3)).build(); + private final S3Client s3Client = S3Client.builder().region(Region.of(localstack.getRegion())) + .credentialsProvider(staticCredentialsProvider).endpointOverride(localstack.getEndpointOverride(S3)) + .build(); - private final EnvironmentRepository envRepo = new AwsS3EnvironmentRepository(s3Client, - "bucket1", server); + private final EnvironmentRepository envRepo = new AwsS3EnvironmentRepository(s3Client, "bucket1", server); private final List toBeRemoved = new ArrayList<>(); - final String yamlContent = "cloudfoundry:\n" + " enabled: true\n" + " accounts:\n" - + " - name: acc1\n" + " user: 'user1'\n" - + " password: 'password1'\n" + " api: api.sys.acc1.cf-app.com\n" - + " environment: test1\n" + " - name: acc2\n" - + " user: 'user2'\n" + " password: 'password2'\n" - + " api: api.sys.acc2.cf-app.com\n" + " environment: test2\n"; + final String yamlContent = "cloudfoundry:\n" + " enabled: true\n" + " accounts:\n" + " - name: acc1\n" + + " user: 'user1'\n" + " password: 'password1'\n" + " api: api.sys.acc1.cf-app.com\n" + + " environment: test1\n" + " - name: acc2\n" + " user: 'user2'\n" + + " password: 'password2'\n" + " api: api.sys.acc2.cf-app.com\n" + " environment: test2\n"; - final String jsonContent = "{\n" + " \"cloudfoundry\": {\n" + " \"enabled\": true,\n" - + " \"accounts\": [{\n" + " \"name\": \"acc1\",\n" - + " \"user\": \"user1\",\n" + " \"password\": \"password1\",\n" - + " \"api\": \"api.sys.acc1.cf-app.com\",\n" - + " \"environment\": \"test1\"\n" + " }, {\n" + " \"name\": \"acc2\",\n" - + " \"user\": \"user2\",\n" + " \"password\": \"password2\",\n" - + " \"api\": \"api.sys.acc2.cf-app.com\",\n" - + " \"environment\": \"test2\"\n" + " }]\n" + " }\n" + "}"; + final String jsonContent = "{\n" + " \"cloudfoundry\": {\n" + " \"enabled\": true,\n" + " \"accounts\": [{\n" + + " \"name\": \"acc1\",\n" + " \"user\": \"user1\",\n" + " \"password\": \"password1\",\n" + + " \"api\": \"api.sys.acc1.cf-app.com\",\n" + " \"environment\": \"test1\"\n" + " }, {\n" + + " \"name\": \"acc2\",\n" + " \"user\": \"user2\",\n" + " \"password\": \"password2\",\n" + + " \"api\": \"api.sys.acc2.cf-app.com\",\n" + " \"environment\": \"test2\"\n" + " }]\n" + " }\n" + + "}"; final Properties expectedProperties = new Properties(); @@ -111,22 +104,22 @@ public class AwsS3EnvironmentRepositoryTests { @BeforeAll public static void createBucket() { StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider - .create(AwsBasicCredentials.create(localstack.getAccessKey(), - localstack.getSecretKey())); + .create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())); S3Client s3Client = S3Client.builder().region(Region.of(localstack.getRegion())) - .credentialsProvider(staticCredentialsProvider) - .endpointOverride(localstack.getEndpointOverride(S3)).build(); + .credentialsProvider(staticCredentialsProvider).endpointOverride(localstack.getEndpointOverride(S3)) + .build(); s3Client.createBucket(CreateBucketRequest.builder().bucket("bucket1").build()); - s3Client.putBucketVersioning(PutBucketVersioningRequest.builder() - .bucket("bucket1").versioningConfiguration(VersioningConfiguration - .builder().status(BucketVersioningStatus.ENABLED).build()) - .build()); + s3Client.putBucketVersioning( + PutBucketVersioningRequest.builder().bucket("bucket1") + .versioningConfiguration( + VersioningConfiguration.builder().status(BucketVersioningStatus.ENABLED).build()) + .build()); } @AfterEach public void cleanUp() { - toBeRemoved.forEach(value -> s3Client.deleteObject( - DeleteObjectRequest.builder().bucket("bucket1").key(value).build())); + toBeRemoved.forEach( + value -> s3Client.deleteObject(DeleteObjectRequest.builder().bucket("bucket1").key(value).build())); toBeRemoved.clear(); } @@ -138,15 +131,11 @@ public class AwsS3EnvironmentRepositoryTests { @Test public void findPropertiesObject() throws UnsupportedEncodingException { - String propertyContent = "cloudfoundry.enabled=true\n" - + "cloudfoundry.accounts[0].name=acc1\n" - + "cloudfoundry.accounts[0].user=user1\n" - + "cloudfoundry.accounts[0].password=password1\n" + String propertyContent = "cloudfoundry.enabled=true\n" + "cloudfoundry.accounts[0].name=acc1\n" + + "cloudfoundry.accounts[0].user=user1\n" + "cloudfoundry.accounts[0].password=password1\n" + "cloudfoundry.accounts[0].api=api.sys.acc1.cf-app.com\n" - + "cloudfoundry.accounts[0].environment=test1\n" - + "cloudfoundry.accounts[1].name=acc2\n" - + "cloudfoundry.accounts[1].user=user2\n" - + "cloudfoundry.accounts[1].password=password2\n" + + "cloudfoundry.accounts[0].environment=test1\n" + "cloudfoundry.accounts[1].name=acc2\n" + + "cloudfoundry.accounts[1].user=user2\n" + "cloudfoundry.accounts[1].password=password2\n" + "cloudfoundry.accounts[1].api=api.sys.acc2.cf-app.com\n" + "cloudfoundry.accounts[1].environment=test2\n"; String versionId = putFiles("foo-bar.properties", propertyContent); @@ -242,8 +231,7 @@ public class AwsS3EnvironmentRepositoryTests { } @Test - public void findWithMultipleApplicationAllFound() - throws UnsupportedEncodingException { + public void findWithMultipleApplicationAllFound() throws UnsupportedEncodingException { putFiles("foo-profile1.yml", jsonContent); String versionId = putFiles("bar-profile1.yml", jsonContent); @@ -254,8 +242,7 @@ public class AwsS3EnvironmentRepositoryTests { @Test public void factoryCustomizable() { - AwsS3EnvironmentRepositoryFactory factory = new AwsS3EnvironmentRepositoryFactory( - new ConfigServerProperties()); + AwsS3EnvironmentRepositoryFactory factory = new AwsS3EnvironmentRepositoryFactory(new ConfigServerProperties()); AwsS3EnvironmentProperties properties = new AwsS3EnvironmentProperties(); properties.setRegion("us-east-1"); properties.setEndpoint("https://myawsendpoint/"); @@ -265,14 +252,13 @@ public class AwsS3EnvironmentRepositoryTests { private String putFiles(String fileName, String propertyContent) { toBeRemoved.add(fileName); - return s3Client.putObject( - PutObjectRequest.builder().bucket("bucket1").key(fileName).build(), + return s3Client.putObject(PutObjectRequest.builder().bucket("bucket1").key(fileName).build(), RequestBody.fromString((propertyContent))).versionId(); } - private void assertExpectedEnvironment(Environment env, String applicationName, - String label, String versionId, int propertySourceCount, String... profiles) { + private void assertExpectedEnvironment(Environment env, String applicationName, String label, String versionId, + int propertySourceCount, String... profiles) { assertThat(env.getName()).isEqualTo(applicationName); assertThat(env.getProfiles()).isEqualTo(profiles); assertThat(env.getLabel()).isEqualTo(label); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java index e1991544..637e988c 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java @@ -61,19 +61,15 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { @Container private static final LocalStackContainer localstack = new LocalStackContainer( - DockerImageName.parse("localstack/localstack:0.14.2")) - .withServices(SECRETSMANAGER); + DockerImageName.parse("localstack/localstack:0.14.2")).withServices(SECRETSMANAGER); - private static final Log log = LogFactory - .getLog(AwsSecretsManagerEnvironmentRepository.class); + private static final Log log = LogFactory.getLog(AwsSecretsManagerEnvironmentRepository.class); private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider - .create(AwsBasicCredentials.create(localstack.getAccessKey(), - localstack.getSecretKey())); + .create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())); private final SecretsManagerClient smClient = SecretsManagerClient.builder() - .region(Region.of(localstack.getRegion())) - .credentialsProvider(staticCredentialsProvider) + .region(Region.of(localstack.getRegion())).credentialsProvider(staticCredentialsProvider) .endpointOverride(localstack.getEndpointOverride(SECRETSMANAGER)).build(); private final ConfigServerProperties configServerProperties = new ConfigServerProperties(); @@ -83,15 +79,14 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { private final AwsSecretsManagerEnvironmentRepository repository = new AwsSecretsManagerEnvironmentRepository( smClient, configServerProperties, environmentProperties); - private final ObjectMapper objectMapper = new ObjectMapper() - .configure(SerializationFeature.INDENT_OUTPUT, true); + private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true); private final List toBeRemoved = new ArrayList<>(); @AfterEach public void cleanUp() { - toBeRemoved.forEach(value -> smClient.deleteSecret(DeleteSecretRequest.builder() - .secretId(value).forceDeleteWithoutRecovery(true).build())); + toBeRemoved.forEach(value -> smClient + .deleteSecret(DeleteSecretRequest.builder().secretId(value).forceDeleteWithoutRecovery(true).build())); toBeRemoved.clear(); } @@ -104,24 +99,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(defaultApplication, profiles, null, - null, null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(defaultApplication, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -132,24 +124,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(defaultApplication, profiles, null, - null, null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(defaultApplication, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -160,24 +149,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(defaultApplication, profiles, null, - null, null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(defaultApplication, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -188,28 +174,26 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(defaultApplication, profiles, null, - null, null); - environment.addAll(Arrays.asList(applicationProdProperties, - applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(defaultApplication, profiles, null, null, null); + environment + .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -220,24 +204,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -247,24 +228,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -274,24 +252,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -301,28 +276,26 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(applicationProdProperties, - applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment + .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -333,24 +306,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -360,24 +330,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -387,24 +354,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll( - Arrays.asList(applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -414,28 +378,26 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(applicationProdProperties, - applicationDefaultProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment + .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -446,32 +408,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/"; - PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, - getFooDefaultProperties()); + PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooDefaultProperties, - applicationDefaultProperties, fooProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties, + applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -481,32 +439,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/"; - PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, - getFooDefaultProperties()); + PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooDefaultProperties, - applicationDefaultProperties, fooProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties, + applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -516,32 +470,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/"; - PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, - getFooDefaultProperties()); + PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooDefaultProperties, - applicationDefaultProperties, fooProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties, + applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -551,23 +501,20 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); + Environment environment = new Environment(application, profiles, null, null, null); environment.addAll(Arrays.asList(fooProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -577,28 +524,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(applicationDefaultProperties, fooProperties, - applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(applicationDefaultProperties, fooProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -608,41 +551,35 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/"; - PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, - getFooProdProperties()); + PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties()); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/"; - PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, - getFooDefaultProperties()); + PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties()); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, - fooDefaultProperties, applicationDefaultProperties, fooProperties, - applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooDefaultProperties, + applicationDefaultProperties, fooProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -652,32 +589,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/"; - PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, - getFooProdProperties()); + PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties()); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, - fooProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll( + Arrays.asList(fooProdProperties, applicationProdProperties, fooProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -687,49 +620,43 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/"; - PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, - getFooProdProperties()); + PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties()); String fooEastPropertiesName = "aws:secrets:/secret/foo-east/"; - PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, - getFooEastProperties()); + PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, getFooEastProperties()); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/"; - PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, - getFooDefaultProperties()); + PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties()); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); String applicationEastPropertiesName = "aws:secrets:/secret/application-east/"; - PropertySource applicationEastProperties = new PropertySource( - applicationEastPropertiesName, getApplicationEastProperties()); + PropertySource applicationEastProperties = new PropertySource(applicationEastPropertiesName, + getApplicationEastProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, - fooEastProperties, applicationEastProperties, fooDefaultProperties, - applicationDefaultProperties, fooProperties, applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooEastProperties, + applicationEastProperties, fooDefaultProperties, applicationDefaultProperties, fooProperties, + applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -739,41 +666,35 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/"; - PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, - getFooProdProperties()); + PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties()); String fooEastPropertiesName = "aws:secrets:/secret/foo-east/"; - PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, - getFooEastProperties()); + PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, getFooEastProperties()); String fooPropertiesName = "aws:secrets:/secret/foo/"; - PropertySource fooProperties = new PropertySource(fooPropertiesName, - getFooProperties()); + PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties()); String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/"; - PropertySource applicationProdProperties = new PropertySource( - applicationProdPropertiesName, getApplicationProdProperties()); + PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName, + getApplicationProdProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); String applicationEastPropertiesName = "aws:secrets:/secret/application-east/"; - PropertySource applicationEastProperties = new PropertySource( - applicationEastPropertiesName, getApplicationEastProperties()); + PropertySource applicationEastProperties = new PropertySource(applicationEastPropertiesName, + getApplicationEastProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, - fooEastProperties, applicationEastProperties, fooProperties, - applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooEastProperties, + applicationEastProperties, fooProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -793,24 +714,21 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { PropertySource overrideProperties = new PropertySource("overrides", overrides); String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/"; - PropertySource applicationDefaultProperties = new PropertySource( - applicationDefaultPropertiesName, getApplicationDefaultProperties()); + PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName, + getApplicationDefaultProperties()); String applicationPropertiesName = "aws:secrets:/secret/application/"; - PropertySource applicationProperties = new PropertySource( - applicationPropertiesName, getApplicationProperties()); + PropertySource applicationProperties = new PropertySource(applicationPropertiesName, + getApplicationProperties()); - Environment environment = new Environment(application, profiles, null, null, - null); - environment.addAll(Arrays.asList(overrideProperties, applicationDefaultProperties, - applicationProperties)); + Environment environment = new Environment(application, profiles, null, null, null); + environment.addAll(Arrays.asList(overrideProperties, applicationDefaultProperties, applicationProperties)); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -819,14 +737,12 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { String profile = configServerProperties.getDefaultProfile(); String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); - Environment environment = new Environment(application, profiles, null, null, - null); + Environment environment = new Environment(application, profiles, null, null, null); putSecrets(environment); Environment resultEnv = repository.findOne(application, profile, null); - assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(environment); + assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @Test @@ -852,11 +768,9 @@ public class AwsSecretsManagerEnvironmentRepositoryTests { private void putSecrets(Environment environment) { for (PropertySource ps : environment.getPropertySources()) { - String path = StringUtils.delete(ps.getName(), - environmentProperties.getOrigin()); + String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin()); String secrets = getSecrets(ps); - smClient.createSecret(CreateSecretRequest.builder().name(path) - .secretString(secrets).build()); + smClient.createSecret(CreateSecretRequest.builder().name(path).secretString(secrets).build()); toBeRemoved.add(path); } }