Skip to content

Commit

Permalink
feat : using aws Serviceconnection for testcontainers in dev mode (#665)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rajadilipkolli authored Apr 2, 2024
1 parent 86bb1dd commit 45475ab
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 218 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/sonarbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 7 additions & 7 deletions aws-cloudwatch-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.5.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
Expand Down Expand Up @@ -110,18 +110,18 @@
<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>postgresql</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -239,7 +239,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,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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;

Expand Down

This file was deleted.

This file was deleted.

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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ApplicationIntegrationTest extends AbstractIntegrationTest {

@Test
void contextLoads() {
assertThat(LOCAL_STACK_CONTAINER.isRunning()).isTrue();

UUID id = UUID.randomUUID();
String email = "[email protected]";
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
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;
import org.springframework.test.context.ActiveProfiles;
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;

Expand Down

This file was deleted.

21 changes: 6 additions & 15 deletions aws-secretmanager-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,8 +19,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

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

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.43.0</spotless.version>
Expand Down Expand Up @@ -88,10 +88,6 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-secrets-manager</artifactId>
Expand All @@ -103,8 +99,8 @@
<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>
Expand All @@ -117,11 +113,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 @@ -239,7 +230,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.18.1</version>
<version>1.19.2</version>
<style>AOSP</style>
</googleJavaFormat>
<formatAnnotations />
Expand Down Expand Up @@ -371,4 +362,4 @@
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
</project>
Loading

0 comments on commit 45475ab

Please sign in to comment.