From 45475abe0f71590e9f413e2558591db424d0fb12 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Tue, 2 Apr 2024 16:58:22 +0530 Subject: [PATCH] feat : using aws Serviceconnection for testcontainers in dev mode (#665) * feat : using aws Serviceconnection for testcontainers in dev mode * using aws-testcontainers for sqs * adds testcontainers to sns and ses projects * prepare for upgrade * adds aws containers and polish --- .github/workflows/sonarbuild.yml | 3 +- aws-cloudwatch-project/pom.xml | 14 +++---- .../example/awsspring/TestApplication.java | 30 +++++++++++++++ .../common/AbstractIntegrationTest.java | 8 ++-- .../common/DBContainerInitializer.java | 28 -------------- .../awsspring/common/LocalStackConfig.java | 33 ---------------- aws-dynamodb-project/pom.xml | 10 ----- .../awsspring/ApplicationIntegrationTest.java | 1 - .../learning/awsspring/TestApplication.java | 37 ++++++++++++++++++ .../common/AbstractIntegrationTest.java | 5 ++- .../awsspring/common/LocalStackConfig.java | 38 ------------------- aws-secretmanager-project/pom.xml | 21 +++------- .../example/awsspring/TestApplication.java | 31 +++++++++++++++ aws-ses-project/pom.xml | 12 +++--- .../example/awsspring/TestSESApplication.java | 31 +++++++++++++++ .../common/AbstractIntegrationTest.java | 5 ++- .../awsspring/common/LocalStackConfig.java | 34 ----------------- aws-sns-project/pom.xml | 34 ++++++++++++----- .../awssns/common/ContainersConfig.java | 9 ++--- aws-sqs-project/pom.xml | 15 +++----- .../awspring/config/TestcontainersConfig.java | 16 +++----- .../SchemaValidationTest.java | 2 +- 22 files changed, 199 insertions(+), 218 deletions(-) create mode 100644 aws-cloudwatch-project/src/test/java/com/example/awsspring/TestApplication.java delete mode 100644 aws-cloudwatch-project/src/test/java/com/example/awsspring/common/DBContainerInitializer.java delete mode 100644 aws-cloudwatch-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java create mode 100644 aws-dynamodb-project/src/test/java/com/learning/awsspring/TestApplication.java delete mode 100644 aws-dynamodb-project/src/test/java/com/learning/awsspring/common/LocalStackConfig.java create mode 100644 aws-secretmanager-project/src/test/java/com/example/awsspring/TestApplication.java create mode 100644 aws-ses-project/src/test/java/com/example/awsspring/TestSESApplication.java delete mode 100644 aws-ses-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java rename aws-sqs-project/src/test/java/com/learning/awspring/{ => repositories}/SchemaValidationTest.java (94%) diff --git a/.github/workflows/sonarbuild.yml b/.github/workflows/sonarbuild.yml index 2f892c15..73ab86ec 100644 --- a/.github/workflows/sonarbuild.yml +++ b/.github/workflows/sonarbuild.yml @@ -25,7 +25,8 @@ jobs: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - - name: Build and analyze + - if: ${{ github.ref == 'refs/heads/main' }} + name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/aws-cloudwatch-project/pom.xml b/aws-cloudwatch-project/pom.xml index 807cf0c8..789ec0e9 100644 --- a/aws-cloudwatch-project/pom.xml +++ b/aws-cloudwatch-project/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.4 + 3.3.0-M3 com.example.awsspring @@ -19,7 +19,7 @@ UTF-8 21 - 3.1.1 + 3.2.0-M1 2.5.0 ${project.build.directory}/test-results @@ -110,18 +110,18 @@ test - org.testcontainers - junit-jupiter + io.awspring.cloud + spring-cloud-aws-testcontainers test org.testcontainers - postgresql + junit-jupiter test org.testcontainers - localstack + postgresql test @@ -239,7 +239,7 @@ - 1.18.1 + 1.19.2 diff --git a/aws-cloudwatch-project/src/test/java/com/example/awsspring/TestApplication.java b/aws-cloudwatch-project/src/test/java/com/example/awsspring/TestApplication.java new file mode 100644 index 00000000..c89596b4 --- /dev/null +++ b/aws-cloudwatch-project/src/test/java/com/example/awsspring/TestApplication.java @@ -0,0 +1,30 @@ +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; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +public class TestApplication { + + @Bean + @ServiceConnection + LocalStackContainer localstackContainer() { + return new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("3.3.0")); + } + + @Bean + @ServiceConnection + PostgreSQLContainer postgreSQLContainer() { + return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("16.2-alpine")); + } + + public static void main(String[] args) { + SpringApplication.from(Application::main).with(TestApplication.class).run(args); + } +} diff --git a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java b/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java index 48fe49de..85169cc9 100644 --- a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java +++ b/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java @@ -3,13 +3,13 @@ import static com.example.awsspring.utils.AppConstants.PROFILE_TEST; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +import com.example.awsspring.TestApplication; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({PROFILE_TEST}) @@ -20,11 +20,11 @@ "management.metrics.export.cloudwatch.step=5s", "management.metrics.enable.all=false", "management.metrics.enable.http=true" - }) + }, + classes = TestApplication.class) @AutoConfigureObservability -@ContextConfiguration(initializers = {DBContainerInitializer.class}) @AutoConfigureMockMvc -public abstract class AbstractIntegrationTest extends LocalStackConfig { +public abstract class AbstractIntegrationTest { @Autowired protected MockMvc mockMvc; diff --git a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/DBContainerInitializer.java b/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/DBContainerInitializer.java deleted file mode 100644 index d59a7ec0..00000000 --- a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/DBContainerInitializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.awsspring.common; - -import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.testcontainers.containers.PostgreSQLContainer; - -public class DBContainerInitializer - implements ApplicationContextInitializer { - - private static final PostgreSQLContainer sqlContainer = - new PostgreSQLContainer<>("postgres:15.3-alpine") - .withDatabaseName("integration-tests-db") - .withUsername("username") - .withPassword("password"); - - static { - sqlContainer.start(); - } - - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - TestPropertyValues.of( - "spring.datasource.url=" + sqlContainer.getJdbcUrl(), - "spring.datasource.username=" + sqlContainer.getUsername(), - "spring.datasource.password=" + sqlContainer.getPassword()) - .applyTo(configurableApplicationContext.getEnvironment()); - } -} diff --git a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java b/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java deleted file mode 100644 index 1b369bdf..00000000 --- a/aws-cloudwatch-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.awsspring.common; - -import static org.testcontainers.containers.localstack.LocalStackContainer.Service.CLOUDWATCH; - -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.testcontainers.containers.localstack.LocalStackContainer; -import org.testcontainers.utility.DockerImageName; - -public class LocalStackConfig { - - static LocalStackContainer localStackContainer; - - static { - localStackContainer = - new LocalStackContainer( - DockerImageName.parse("localstack/localstack").withTag("3.3.0")) - .withServices(CLOUDWATCH) - .withExposedPorts(4566); - localStackContainer.start(); - } - - @DynamicPropertySource - static void registerProperties(DynamicPropertyRegistry registry) { - registry.add( - "spring.cloud.aws.cloudwatch.endpoint", - () -> localStackContainer.getEndpointOverride(CLOUDWATCH).toString()); - registry.add("spring.cloud.aws.cloudwatch.region", localStackContainer::getRegion); - registry.add("spring.cloud.aws.credentials.secret-key", localStackContainer::getSecretKey); - registry.add("spring.cloud.aws.credentials.access-key", localStackContainer::getAccessKey); - registry.add("spring.cloud.aws.region.static", localStackContainer::getRegion); - } -} diff --git a/aws-dynamodb-project/pom.xml b/aws-dynamodb-project/pom.xml index 11329231..a432021a 100644 --- a/aws-dynamodb-project/pom.xml +++ b/aws-dynamodb-project/pom.xml @@ -94,11 +94,6 @@ spring-boot-starter-test test - - org.springframework.boot - spring-boot-testcontainers - test - io.awspring.cloud spring-cloud-aws-testcontainers @@ -109,11 +104,6 @@ junit-jupiter test - - org.testcontainers - localstack - test - diff --git a/aws-dynamodb-project/src/test/java/com/learning/awsspring/ApplicationIntegrationTest.java b/aws-dynamodb-project/src/test/java/com/learning/awsspring/ApplicationIntegrationTest.java index f2a0d859..c516fee4 100644 --- a/aws-dynamodb-project/src/test/java/com/learning/awsspring/ApplicationIntegrationTest.java +++ b/aws-dynamodb-project/src/test/java/com/learning/awsspring/ApplicationIntegrationTest.java @@ -22,7 +22,6 @@ class ApplicationIntegrationTest extends AbstractIntegrationTest { @Test void contextLoads() { - assertThat(LOCAL_STACK_CONTAINER.isRunning()).isTrue(); UUID id = UUID.randomUUID(); String email = "junit@email.com"; diff --git a/aws-dynamodb-project/src/test/java/com/learning/awsspring/TestApplication.java b/aws-dynamodb-project/src/test/java/com/learning/awsspring/TestApplication.java new file mode 100644 index 00000000..ba7175b6 --- /dev/null +++ b/aws-dynamodb-project/src/test/java/com/learning/awsspring/TestApplication.java @@ -0,0 +1,37 @@ +package com.learning.awsspring; + +import lombok.extern.slf4j.Slf4j; +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.localstack.LocalStackContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; +import org.testcontainers.utility.MountableFile; + +@Slf4j +@TestConfiguration(proxyBeanMethods = false) +public class TestApplication { + + @Bean + @ServiceConnection + LocalStackContainer localstackContainer() { + LocalStackContainer localstackContainer = + new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("3.3.0")) + .withCopyFileToContainer( + MountableFile.forHostPath(".localstack/"), + "/etc/localstack/init/ready.d/") + .waitingFor(Wait.forLogMessage(".*Initialized\\.\n", 1)); + localstackContainer.start(); + Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log); + localstackContainer.followOutput(logConsumer); + return localstackContainer; + } + + public static void main(String[] args) { + SpringApplication.from(Application::main).with(TestApplication.class).run(args); + } +} diff --git a/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/AbstractIntegrationTest.java b/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/AbstractIntegrationTest.java index cc2a5b02..3044e12c 100644 --- a/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/AbstractIntegrationTest.java +++ b/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/AbstractIntegrationTest.java @@ -4,6 +4,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import com.fasterxml.jackson.databind.ObjectMapper; +import com.learning.awsspring.TestApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -11,9 +12,9 @@ import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({PROFILE_TEST}) -@SpringBootTest(webEnvironment = RANDOM_PORT) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestApplication.class) @AutoConfigureMockMvc -public abstract class AbstractIntegrationTest extends LocalStackConfig { +public abstract class AbstractIntegrationTest { @Autowired protected MockMvc mockMvc; diff --git a/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/LocalStackConfig.java b/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/LocalStackConfig.java deleted file mode 100644 index d17aa6f0..00000000 --- a/aws-dynamodb-project/src/test/java/com/learning/awsspring/common/LocalStackConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.learning.awsspring.common; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.testcontainers.containers.localstack.LocalStackContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.DockerImageName; -import org.testcontainers.utility.MountableFile; - -@Slf4j -public class LocalStackConfig { - protected static final LocalStackContainer LOCAL_STACK_CONTAINER = - new LocalStackContainer(DockerImageName.parse("localstack/localstack").withTag("3.3.0")) - .withCopyFileToContainer( - MountableFile.forHostPath(".localstack/"), - "/etc/localstack/init/ready.d/") - .waitingFor(Wait.forLogMessage(".*Initialized\\.\n", 1)); - - static { - LOCAL_STACK_CONTAINER.start(); - Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log); - LOCAL_STACK_CONTAINER.followOutput(logConsumer); - } - - @DynamicPropertySource - static void setApplicationProperties(DynamicPropertyRegistry dynamicPropertyRegistry) { - dynamicPropertyRegistry.add( - "spring.cloud.aws.credentials.access-key", LOCAL_STACK_CONTAINER::getAccessKey); - dynamicPropertyRegistry.add( - "spring.cloud.aws.credentials.secret-key", LOCAL_STACK_CONTAINER::getSecretKey); - dynamicPropertyRegistry.add( - "spring.cloud.aws.region.static", LOCAL_STACK_CONTAINER::getRegion); - dynamicPropertyRegistry.add( - "spring.cloud.aws.endpoint", LOCAL_STACK_CONTAINER::getEndpoint); - } -} diff --git a/aws-secretmanager-project/pom.xml b/aws-secretmanager-project/pom.xml index 8071976c..93b87f7e 100644 --- a/aws-secretmanager-project/pom.xml +++ b/aws-secretmanager-project/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.4 + 3.3.0-M3 com.example.awsspring @@ -19,8 +19,8 @@ UTF-8 21 + 3.2.0-M1 2.5.0 - 3.1.1 ${project.build.directory}/test-results 2.43.0 @@ -88,10 +88,6 @@ springdoc-openapi-starter-webmvc-ui ${springdoc-openapi.version} - - org.apache.commons - commons-lang3 - io.awspring.cloud spring-cloud-aws-starter-secrets-manager @@ -103,8 +99,8 @@ test - org.springframework.boot - spring-boot-testcontainers + io.awspring.cloud + spring-cloud-aws-testcontainers test @@ -117,11 +113,6 @@ postgresql test - - org.testcontainers - localstack - test - @@ -239,7 +230,7 @@ - 1.18.1 + 1.19.2 @@ -371,4 +362,4 @@ - \ No newline at end of file + diff --git a/aws-secretmanager-project/src/test/java/com/example/awsspring/TestApplication.java b/aws-secretmanager-project/src/test/java/com/example/awsspring/TestApplication.java new file mode 100644 index 00000000..45abe4f1 --- /dev/null +++ b/aws-secretmanager-project/src/test/java/com/example/awsspring/TestApplication.java @@ -0,0 +1,31 @@ +package com.example.awsspring; + +import com.example.awsspring.common.DBTestContainer; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.context.ImportTestcontainers; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; +import org.testcontainers.utility.MountableFile; + +@TestConfiguration(proxyBeanMethods = false) +@ImportTestcontainers(DBTestContainer.class) +public class TestApplication { + + @Bean + @ServiceConnection + LocalStackContainer localStackContainer() { + return new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("3.3.0")) + .withCopyFileToContainer( + MountableFile.forHostPath("localstack/"), "/etc/localstack/init/ready.d/") + .waitingFor(Wait.forLogMessage(".*LocalStack initialized successfully\n", 1)); + } + + public static void main(String[] args) { + SpringApplication.from(Application::main).with(TestApplication.class).run(args); + } +} diff --git a/aws-ses-project/pom.xml b/aws-ses-project/pom.xml index 367c9768..a5b68b6a 100644 --- a/aws-ses-project/pom.xml +++ b/aws-ses-project/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.4 + 3.3.0-M3 com.example.awsspring @@ -19,7 +19,7 @@ UTF-8 21 - 3.1.1 + 3.2.0-M1 2.5.0 ${project.build.directory}/test-results @@ -98,13 +98,13 @@ test - org.testcontainers - junit-jupiter + io.awspring.cloud + spring-cloud-aws-testcontainers test org.testcontainers - localstack + junit-jupiter test @@ -222,7 +222,7 @@ - 1.18.1 + 1.19.2 diff --git a/aws-ses-project/src/test/java/com/example/awsspring/TestSESApplication.java b/aws-ses-project/src/test/java/com/example/awsspring/TestSESApplication.java new file mode 100644 index 00000000..cee6b50c --- /dev/null +++ b/aws-ses-project/src/test/java/com/example/awsspring/TestSESApplication.java @@ -0,0 +1,31 @@ +package com.example.awsspring; + +import lombok.extern.slf4j.Slf4j; +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.localstack.LocalStackContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.utility.DockerImageName; + +@Slf4j +@TestConfiguration(proxyBeanMethods = false) +public class TestSESApplication { + + @Bean + @ServiceConnection + LocalStackContainer localStackContainer() { + LocalStackContainer localStackContainer = + new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("3.3.0")); + localStackContainer.start(); + Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log); + localStackContainer.followOutput(logConsumer); + return localStackContainer; + } + + public static void main(String[] args) { + SpringApplication.from(SESApplication::main).with(TestSESApplication.class).run(args); + } +} diff --git a/aws-ses-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java b/aws-ses-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java index b9e80eea..3c23e08b 100644 --- a/aws-ses-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java +++ b/aws-ses-project/src/test/java/com/example/awsspring/common/AbstractIntegrationTest.java @@ -3,6 +3,7 @@ import static com.example.awsspring.utils.AppConstants.PROFILE_TEST; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +import com.example.awsspring.TestSESApplication; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -11,9 +12,9 @@ import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({PROFILE_TEST}) -@SpringBootTest(webEnvironment = RANDOM_PORT) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestSESApplication.class) @AutoConfigureMockMvc -public abstract class AbstractIntegrationTest extends LocalStackConfig { +public abstract class AbstractIntegrationTest { @Autowired protected MockMvc mockMvc; diff --git a/aws-ses-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java b/aws-ses-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java deleted file mode 100644 index bb8e916a..00000000 --- a/aws-ses-project/src/test/java/com/example/awsspring/common/LocalStackConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.example.awsspring.common; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.testcontainers.containers.localstack.LocalStackContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.utility.DockerImageName; - -@Slf4j -public class LocalStackConfig { - - static final LocalStackContainer localStackContainer = - new LocalStackContainer( - DockerImageName.parse("localstack/localstack").withTag("3.3.0")); - - static { - localStackContainer.start(); - Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log); - localStackContainer.followOutput(logConsumer); - } - - @DynamicPropertySource - static void setDynamicProperties(DynamicPropertyRegistry dynamicPropertyRegistry) { - dynamicPropertyRegistry.add( - "spring.cloud.aws.credentials.access-key", localStackContainer::getAccessKey); - dynamicPropertyRegistry.add( - "spring.cloud.aws.credentials.secret-key", localStackContainer::getSecretKey); - dynamicPropertyRegistry.add( - "spring.cloud.aws.region.static", localStackContainer::getRegion); - dynamicPropertyRegistry.add( - "spring.cloud.aws.endpoint", () -> localStackContainer.getEndpoint().toString()); - } -} diff --git a/aws-sns-project/pom.xml b/aws-sns-project/pom.xml index 1a4b16dc..556bb818 100644 --- a/aws-sns-project/pom.xml +++ b/aws-sns-project/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.4 + 3.3.0-M3 com.learning.awssns @@ -21,7 +21,7 @@ UTF-8 21 - 3.1.1 + 3.2.0-M1 2.5.0 ${project.build.directory}/test-results @@ -84,8 +84,8 @@ test - org.springframework.boot - spring-boot-testcontainers + io.awspring.cloud + spring-cloud-aws-testcontainers test @@ -93,11 +93,6 @@ junit-jupiter test - - org.testcontainers - localstack - test - @@ -326,4 +321,25 @@ + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/aws-sns-project/src/test/java/com/learning/awssns/common/ContainersConfig.java b/aws-sns-project/src/test/java/com/learning/awssns/common/ContainersConfig.java index 3be0e43b..d67f1da8 100644 --- a/aws-sns-project/src/test/java/com/learning/awssns/common/ContainersConfig.java +++ b/aws-sns-project/src/test/java/com/learning/awssns/common/ContainersConfig.java @@ -1,6 +1,7 @@ package com.learning.awssns.common; import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; import org.springframework.test.context.DynamicPropertyRegistry; import org.testcontainers.containers.localstack.LocalStackContainer; @@ -10,13 +11,9 @@ public class ContainersConfig { @Bean + @ServiceConnection LocalStackContainer localstackContainer(DynamicPropertyRegistry registry) { - LocalStackContainer localStackContainer = new LocalStackContainer( + return new LocalStackContainer( DockerImageName.parse("localstack/localstack").withTag("3.3.0")); - 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.cloud.aws.endpoint", localStackContainer::getEndpoint); - return localStackContainer; } } diff --git a/aws-sqs-project/pom.xml b/aws-sqs-project/pom.xml index f680243a..f555587d 100644 --- a/aws-sqs-project/pom.xml +++ b/aws-sqs-project/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.4 + 3.3.0-M3 com.learning.awspring @@ -21,7 +21,7 @@ 21 2.16.0 - 3.1.1 + 3.2.0-M1 1.5.5.Final 2.43.0 2.5.0 @@ -117,8 +117,8 @@ test - org.springframework.boot - spring-boot-testcontainers + io.awspring.cloud + spring-cloud-aws-testcontainers test @@ -131,11 +131,6 @@ postgresql test - - org.testcontainers - localstack - test - @@ -336,7 +331,7 @@ - 1.18.1 + 1.19.2 diff --git a/aws-sqs-project/src/test/java/com/learning/awspring/config/TestcontainersConfig.java b/aws-sqs-project/src/test/java/com/learning/awspring/config/TestcontainersConfig.java index bdc464d5..af810af0 100644 --- a/aws-sqs-project/src/test/java/com/learning/awspring/config/TestcontainersConfig.java +++ b/aws-sqs-project/src/test/java/com/learning/awspring/config/TestcontainersConfig.java @@ -3,7 +3,6 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; -import org.springframework.test.context.DynamicPropertyRegistry; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.localstack.LocalStackContainer; import org.testcontainers.utility.DockerImageName; @@ -18,15 +17,10 @@ public PostgreSQLContainer postgreSQLContainer() { } @Bean - LocalStackContainer localstackContainer(DynamicPropertyRegistry registry) { - LocalStackContainer localStackContainer = - new LocalStackContainer( - DockerImageName.parse("localstack/localstack").withTag("3.3.0")) - .withReuse(true); - 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.cloud.aws.endpoint", localStackContainer::getEndpoint); - return localStackContainer; + @ServiceConnection + LocalStackContainer localstackContainer() { + return new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("3.3.0")) + .withReuse(true); } } diff --git a/aws-sqs-project/src/test/java/com/learning/awspring/SchemaValidationTest.java b/aws-sqs-project/src/test/java/com/learning/awspring/repositories/SchemaValidationTest.java similarity index 94% rename from aws-sqs-project/src/test/java/com/learning/awspring/SchemaValidationTest.java rename to aws-sqs-project/src/test/java/com/learning/awspring/repositories/SchemaValidationTest.java index 059b8a7b..ff4f6253 100644 --- a/aws-sqs-project/src/test/java/com/learning/awspring/SchemaValidationTest.java +++ b/aws-sqs-project/src/test/java/com/learning/awspring/repositories/SchemaValidationTest.java @@ -1,4 +1,4 @@ -package com.learning.awspring; +package com.learning.awspring.repositories; import static org.assertj.core.api.Assertions.assertThat;