-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : using ConfigDataApplicationContextInitializer
- Loading branch information
1 parent
bf373dd
commit 30f2e9e
Showing
7 changed files
with
52 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
aws-secretmanager-project/src/test/java/com/example/awsspring/TestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.awsspring; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class TestApplication { | ||
|
||
@Bean | ||
@ServiceConnection | ||
PostgreSQLContainer<?> sqlContainer() { | ||
return new PostgreSQLContainer<>("postgres:16.0-alpine"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(Application::main).with(TestApplication.class).run(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 14 additions & 10 deletions
24
...manager-project/src/test/java/com/example/awsspring/common/LocalStackContainerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
package com.example.awsspring.common; | ||
|
||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
@Testcontainers | ||
public class LocalStackContainerConfig { | ||
|
||
@Container | ||
private static final LocalStackContainer localStackContainer = | ||
new LocalStackContainer(DockerImageName.parse("localstack/localstack").withTag("2.3.2")) | ||
.withCopyFileToContainer( | ||
MountableFile.forHostPath("localstack/"), | ||
"/etc/localstack/init/ready.d/") | ||
.waitingFor(Wait.forLogMessage(".*LocalStack initialized successfully\n", 1)); | ||
|
||
static { | ||
localStackContainer.start(); | ||
// Workaround to set value early | ||
System.setProperty( | ||
"spring.cloud.aws.endpoint", localStackContainer.getEndpoint().toString()); | ||
System.setProperty( | ||
"spring.cloud.aws.credentials.access-key", localStackContainer.getAccessKey()); | ||
System.setProperty( | ||
"spring.cloud.aws.credentials.secret-key", localStackContainer.getSecretKey()); | ||
System.setProperty("spring.cloud.aws.region.static", localStackContainer.getRegion()); | ||
@DynamicPropertySource | ||
static void properties(DynamicPropertyRegistry registry) { | ||
registry.add( | ||
"spring.cloud.aws.endpoint", () -> localStackContainer.getEndpoint().toString()); | ||
registry.add("spring.cloud.aws.credentials.access-key", localStackContainer::getAccessKey); | ||
registry.add("spring.cloud.aws.credentials.secret-key", localStackContainer::getSecretKey); | ||
registry.add("spring.cloud.aws.region.static", localStackContainer::getRegion); | ||
registry.add("spring.config.import", () -> "aws-secretsmanager:/spring/secret"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters