-
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 instead of System…
….properties reference : eddumelendez/testcontainers-localstack@8b76647
- Loading branch information
1 parent
116af53
commit bf373dd
Showing
7 changed files
with
42 additions
and
37 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
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
13 changes: 12 additions & 1 deletion
13
aws-parameterstore-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 |
---|---|---|
@@ -1,10 +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).run(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
23 changes: 14 additions & 9 deletions
23
...erstore-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,27 +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(".*Initialized\\.\n", 1)); | ||
|
||
static { | ||
localStackContainer.start(); | ||
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-parameterstore:/spring/config/"); | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
aws-parameterstore-project/src/test/java/com/example/awsspring/common/MyDBContainer.java
This file was deleted.
Oops, something went wrong.