|
19 | 19 | import static org.junit.jupiter.api.Assertions.fail; |
20 | 20 | import static org.mockito.ArgumentMatchers.any; |
21 | 21 | import static org.mockito.Mockito.mock; |
22 | | -import static org.mockito.Mockito.verify; |
23 | 22 | import static org.mockito.Mockito.when; |
24 | 23 | import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM; |
25 | 24 | import static org.testcontainers.shaded.org.awaitility.Awaitility.await; |
|
47 | 46 | import org.testcontainers.utility.DockerImageName; |
48 | 47 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
49 | 48 | import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; |
| 49 | +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
50 | 50 | import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; |
51 | 51 | import software.amazon.awssdk.http.SdkHttpClient; |
52 | 52 | import software.amazon.awssdk.http.apache.ApacheHttpClient; |
@@ -163,20 +163,18 @@ void ssmClientCanBeOverwrittenInBootstrapConfig() { |
163 | 163 |
|
164 | 164 | @Test |
165 | 165 | void credentialsProviderCanBeOverwrittenInBootstrapConfig() { |
166 | | - AwsCredentialsProvider mockCredentialsProvider = mock(AwsCredentialsProvider.class); |
167 | | - when(mockCredentialsProvider.resolveCredentials()) |
168 | | - .thenReturn(AwsBasicCredentials.create("mock-key", "mock-secret")); |
| 166 | + AwsCredentialsProvider bootstrapCredentialsProvider = StaticCredentialsProvider |
| 167 | + .create(AwsBasicCredentials.create("mock-key", "mock-secret")); |
169 | 168 | SpringApplication application = new SpringApplication(App.class); |
170 | 169 | application.setWebApplicationType(WebApplicationType.NONE); |
171 | 170 | application.addBootstrapRegistryInitializer(registry -> { |
172 | | - registry.register(AwsCredentialsProvider.class, ctx -> mockCredentialsProvider); |
| 171 | + registry.register(AwsCredentialsProvider.class, ctx -> bootstrapCredentialsProvider); |
173 | 172 | }); |
174 | 173 |
|
175 | 174 | try (ConfigurableApplicationContext context = runApplication(application, |
176 | 175 | "aws-parameterstore:/config/spring")) { |
177 | | - // perhaps there is a better way to verify that correct credentials provider |
178 | | - // is used by SSM client without using reflection? |
179 | | - verify(mockCredentialsProvider).resolveCredentials(); |
| 176 | + ConfiguredAwsClient ssmClient = new ConfiguredAwsClient(context.getBean(SsmClient.class)); |
| 177 | + assertThat(ssmClient.getAwsCredentialsProvider()).isEqualTo(bootstrapCredentialsProvider); |
180 | 178 | } |
181 | 179 | } |
182 | 180 |
|
@@ -248,17 +246,17 @@ void arrayParameterNames() { |
248 | 246 | putParameter(localstack, "/config/myservice/key_1_.nested_1_.nestedValue", "key_nestedValue4", REGION); |
249 | 247 |
|
250 | 248 | try (ConfigurableApplicationContext context = runApplication(application, |
251 | | - "aws-parameterstore:/config/myservice/")) { |
| 249 | + "aws-parameterstore:/config/myservice/")) { |
252 | 250 | assertThat(context.getEnvironment().getProperty("key[0].value")).isEqualTo("value1"); |
253 | 251 | assertThat(context.getEnvironment().getProperty("key[0].nested[0].nestedValue")) |
254 | | - .isEqualTo("key_nestedValue1"); |
| 252 | + .isEqualTo("key_nestedValue1"); |
255 | 253 | assertThat(context.getEnvironment().getProperty("key[0].nested[1].nestedValue")) |
256 | | - .isEqualTo("key_nestedValue2"); |
| 254 | + .isEqualTo("key_nestedValue2"); |
257 | 255 | assertThat(context.getEnvironment().getProperty("key[1].value")).isEqualTo("value2"); |
258 | 256 | assertThat(context.getEnvironment().getProperty("key[1].nested[0].nestedValue")) |
259 | | - .isEqualTo("key_nestedValue3"); |
| 257 | + .isEqualTo("key_nestedValue3"); |
260 | 258 | assertThat(context.getEnvironment().getProperty("key[1].nested[1].nestedValue")) |
261 | | - .isEqualTo("key_nestedValue4"); |
| 259 | + .isEqualTo("key_nestedValue4"); |
262 | 260 | } |
263 | 261 | } |
264 | 262 |
|
|
0 commit comments