Skip to content

Commit

Permalink
feat : upgrade to spring cloud 2024.0.0.0 and localstack to 4.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli authored Dec 16, 2024
1 parent df73958 commit fa39570
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion aws-kinesis-project/producer/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'
services:

localstack:
image: localstack/localstack:3.8.1
image: localstack/localstack:4.0.3
ports:
- "4566:4566"
environment:
Expand Down
4 changes: 2 additions & 2 deletions aws-kinesis-project/producer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>21</java.version>
<spring-cloud.version>2023.0.4</spring-cloud.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>
<springdoc-openapi.version>2.7.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
Expand Down Expand Up @@ -223,7 +223,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.0</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
package com.learning.aws.spring;

import static org.testcontainers.containers.localstack.LocalStackContainer.Service.KINESIS;

import com.learning.aws.spring.common.ContainerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.utility.DockerImageName;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;

@TestConfiguration(proxyBeanMethods = false)
public class TestKinesisProducerApplication {

@Bean
LocalStackContainer localStackContainer(DynamicPropertyRegistry dynamicPropertyRegistry) {
LocalStackContainer localStackContainer =
new LocalStackContainer(
DockerImageName.parse("localstack/localstack").withTag("3.7.2"));
dynamicPropertyRegistry.add("spring.cloud.aws.endpoint", localStackContainer::getEndpoint);
dynamicPropertyRegistry.add(
"spring.cloud.aws.region.static", localStackContainer::getRegion);
dynamicPropertyRegistry.add(
"spring.cloud.aws.access-key", localStackContainer::getAccessKey);
dynamicPropertyRegistry.add(
"spring.cloud.aws.secret-key", localStackContainer::getSecretKey);
return localStackContainer;
}

@Bean
KinesisAsyncClient amazonKinesis(LocalStackContainer localStackContainer) {
return KinesisAsyncClient.builder()
.endpointOverride(localStackContainer.getEndpointOverride(KINESIS))
.region(Region.of(localStackContainer.getRegion()))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
localStackContainer.getAccessKey(),
localStackContainer.getSecretKey())))
.build();
}

public static void main(String[] args) {
SpringApplication.from(KinesisProducerApplication::main)
.with(TestKinesisProducerApplication.class)
.with(ContainerConfig.class)
.run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.aws.spring.TestKinesisProducerApplication;
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, classes = TestKinesisProducerApplication.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ContainerConfig.class)
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.learning.aws.spring.common;

import static org.testcontainers.containers.localstack.LocalStackContainer.Service.KINESIS;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.utility.DockerImageName;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;

@TestConfiguration(proxyBeanMethods = false)
public class ContainerConfig {

@Bean
LocalStackContainer localStackContainer() {
return new LocalStackContainer(
DockerImageName.parse("localstack/localstack").withTag("4.0.3"));
}

@Bean
DynamicPropertyRegistrar dynamicPropertyRegistrar(LocalStackContainer localStackContainer) {
return dynamicPropertyRegistry -> {
dynamicPropertyRegistry.add(
"spring.cloud.aws.endpoint", localStackContainer::getEndpoint);
dynamicPropertyRegistry.add(
"spring.cloud.aws.region.static", localStackContainer::getRegion);
dynamicPropertyRegistry.add(
"spring.cloud.aws.access-key", localStackContainer::getAccessKey);
dynamicPropertyRegistry.add(
"spring.cloud.aws.secret-key", localStackContainer::getSecretKey);
};
}

@Bean
KinesisAsyncClient amazonKinesis(LocalStackContainer localStackContainer) {
return KinesisAsyncClient.builder()
.endpointOverride(localStackContainer.getEndpointOverride(KINESIS))
.region(Region.of(localStackContainer.getRegion()))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
localStackContainer.getAccessKey(),
localStackContainer.getSecretKey())))
.build();
}
}

0 comments on commit fa39570

Please sign in to comment.