Skip to content

Commit

Permalink
adds testcontainers to sns and ses projects
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Apr 2, 2024
1 parent d469eaa commit 4eb30bd
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 78 deletions.
10 changes: 0 additions & 10 deletions aws-dynamodb-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-testcontainers</artifactId>
Expand All @@ -109,11 +104,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
12 changes: 6 additions & 6 deletions aws-ses-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<version>3.3.0-M3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.awsspring</groupId>
Expand All @@ -19,7 +19,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>21</java.version>
<spring-cloud-aws.version>3.1.1</spring-cloud-aws.version>
<spring-cloud-aws.version>3.2.0-M1</spring-cloud-aws.version>
<springdoc-openapi.version>2.4.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
Expand Down Expand Up @@ -98,13 +98,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -222,7 +222,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.18.1</version>
<version>1.19.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

This file was deleted.

34 changes: 25 additions & 9 deletions aws-sns-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<version>3.3.0-M3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.learning.awssns</groupId>
Expand All @@ -21,7 +21,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>21</java.version>
<spring-cloud-aws.version>3.1.1</spring-cloud-aws.version>
<spring-cloud-aws.version>3.2.0-M1</spring-cloud-aws.version>
<springdoc-openapi.version>2.4.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
Expand Down Expand Up @@ -84,20 +84,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down Expand Up @@ -326,4 +321,25 @@
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
12 changes: 1 addition & 11 deletions aws-sqs-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-testcontainers</artifactId>
Expand All @@ -136,11 +131,6 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down Expand Up @@ -341,7 +331,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.18.1</version>
<version>1.19.2</version>
<style>AOSP</style>
</googleJavaFormat>
<formatAnnotations />
Expand Down

0 comments on commit 4eb30bd

Please sign in to comment.