Skip to content

Commit

Permalink
feat : upgrade software to latest versions (#818)
Browse files Browse the repository at this point in the history
* feat : upgrade software to latest versions

* attempt to use OOTB service connection for S3

* fix : issue with assiging dynamic properties

* run all repo tests with testcontainers
  • Loading branch information
rajadilipkolli authored Dec 27, 2024
1 parent 0083751 commit 0e77433
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic",
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable",
"java.debug.settings.onBuildFailureProceed": true
}
2 changes: 1 addition & 1 deletion aws-s3-project/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- "5432:5432"

localstack:
image: localstack/localstack:3.8.1
image: localstack/localstack:4.0.3
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
Expand Down
2 changes: 1 addition & 1 deletion aws-s3-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -11,7 +12,7 @@
public class WebMvcConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
public void addCorsMappings(@NonNull CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedMethods("*")
.allowedHeaders("*")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
package com.learning.awspring;

import com.learning.awspring.common.LocalStackContainerConfig;
import com.learning.awspring.common.SQLContainerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.devtools.restart.RestartScope;
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.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

@TestConfiguration(proxyBeanMethods = false)
public class TestS3Application {

@Bean
@ServiceConnection
@RestartScope
PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.0-alpine"))
.withReuse(true);
}

@Bean
LocalStackContainer localstackContainer(DynamicPropertyRegistry registry) {
LocalStackContainer localStackContainer =
new LocalStackContainer(
DockerImageName.parse("localstack/localstack").withTag("3.7.2"))
.withCopyFileToContainer(
MountableFile.forHostPath(".localstack/"),
"/etc/localstack/init/ready.d/")
.waitingFor(
Wait.forLogMessage(".*LocalStack initialized successfully\n", 1));
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;
}

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

import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.awspring.TestS3Application;
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 = TestS3Application.class)
@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {SQLContainerConfig.class, LocalStackContainerConfig.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

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

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.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

@TestConfiguration(proxyBeanMethods = false)
public class LocalStackContainerConfig {

@Bean
LocalStackContainer localstackContainer() {
return new LocalStackContainer(
DockerImageName.parse("localstack/localstack").withTag("4.0.3"))
.withCopyFileToContainer(
MountableFile.forHostPath(".localstack/"), "/etc/localstack/init/ready.d/")
.waitingFor(Wait.forLogMessage(".*LocalStack initialized successfully\n", 1));
}

@Bean
DynamicPropertyRegistrar dynamicPropertyRegistrar(LocalStackContainer localStackContainer) {
return registry -> {
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);
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.learning.awspring.common;

import org.springframework.boot.devtools.restart.RestartScope;
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.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class SQLContainerConfig {

@Bean
@ServiceConnection
@RestartScope
PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.2-alpine"))
.withReuse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.learning.awspring.common.SQLContainerConfig;
import com.learning.awspring.entities.FileInfo;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.context.annotation.Import;

@DataJpaTest
@Import(SQLContainerConfig.class)
class FileInfoRepositoryTest {

@Autowired private TestEntityManager entityManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.learning.awspring.common.SQLContainerConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;

@DataJpaTest(
properties = {
"spring.jpa.hibernate.ddl-auto=validate",
"spring.test.database.replace=none",
"spring.datasource.url=jdbc:tc:postgresql:16.2-alpine:///db"
})
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@AutoConfigureTestDatabase
@Import(SQLContainerConfig.class)
class SchemaValidationTest {

@Autowired private DataSource dataSource;
Expand Down

0 comments on commit 0e77433

Please sign in to comment.