Skip to content

Commit

Permalink
Dependency updates and Testcontainers configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernKW committed Jun 11, 2024
1 parent 3199869 commit c07af8a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
runtimeOnly 'org.postgresql:postgresql'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.testcontainers:localstack'
testImplementation 'org.testcontainers:junit-jupiter'
Expand Down
2 changes: 0 additions & 2 deletions application/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ services:
- 4566:4566
environment:
- SERVICES=sqs,ses,dynamodb
- DEFAULT_REGION=eu-central-1
- USE_SINGLE_REGION=true
volumes:
- ./src/test/resources/localstack/local-aws-infrastructure.sh:/docker-entrypoint-initaws.d/init.sh
keycloak:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.stratospheric.todoapp;

import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
Expand All @@ -8,25 +9,30 @@
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

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

@ActiveProfiles("dev")
@Testcontainers
public abstract class AbstractDevIntegrationTest {

@Container
@ServiceConnection
static PostgreSQLContainer<?> database = new PostgreSQLContainer<>("postgres:12.9")
.withDatabaseName("stratospheric")
.withUsername("stratospheric")
.withPassword("stratospheric");

static LocalStackContainer localStack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:0.14.3"))
@Container
static LocalStackContainer localStack = new LocalStackContainer(DockerImageName.parse("localstack/localstack"))
.withClasspathResourceMapping("/localstack", "/docker-entrypoint-initaws.d", BindMode.READ_ONLY)
.withEnv("USE_SINGLE_REGION", "true")
.withEnv("DEFAULT_REGION", "eu-central-1")
.withServices(SQS, SES, DYNAMODB)
.waitingFor(Wait.forLogMessage(".*Initialized\\.\n", 1));
.waitingFor(Wait.forLogMessage(".*Ready.*\n", 1));

@Container
static GenericContainer keycloak = new GenericContainer(DockerImageName.parse("quay.io/keycloak/keycloak:18.0.0-legacy"))
.withExposedPorts(8080)
.withClasspathResourceMapping("/keycloak", "/tmp", BindMode.READ_ONLY)
Expand All @@ -36,12 +42,12 @@ public abstract class AbstractDevIntegrationTest {
.withEnv("KEYCLOAK_PASSWORD", "keycloak")
.waitingFor(Wait.forHttp("/auth").forStatusCode(200));

@Container
static GenericContainer<?> activeMq = new GenericContainer<>(DockerImageName.parse("stratospheric/activemq-docker-image"))
.withExposedPorts(5672, 61613, 61614, 61616);

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", () -> database.getJdbcUrl());
registry.add("spring.security.oauth2.client.provider.cognito.issuerUri", () -> "http://localhost:" + keycloak.getMappedPort(8080) + "/auth/realms/stratospheric");
registry.add("spring.cloud.aws.endpoint", () -> localStack.getEndpointOverride(SQS).toString());
registry.add("spring.activemq.broker-url", () -> "localhost:" + activeMq.getMappedPort(61613));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class TodoControllerIntegrationTest extends AbstractDevIntegrationTest {

@Test
void shouldAllowCrudOperationOnTodo() throws Exception {

OidcUser todoOwner = createOidcUser("duke@stratospheric.dev", "duke");

Long createdTodoId = shouldCreateTodo(todoOwner);
Expand All @@ -54,7 +53,6 @@ void shouldAllowCrudOperationOnTodo() throws Exception {

@Test
void shouldAllowCollaboratingOnSharedTodo() throws Exception {

OidcUser collaborator = createOidcUser("collaborator@stratospheric.dev", "collaborator");

Long sharedTodoId = givenSharedTodo();
Expand Down
4 changes: 1 addition & 3 deletions chapters/chapter-12/application/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ services:
- POSTGRES_PASSWORD=stratospheric
- POSTGRES_DB=stratospheric
localstack:
image: localstack/localstack:0.14.4
image: localstack/localstack
ports:
- 4566:4566
environment:
- SERVICES=sqs,ses,dynamodb
- DEFAULT_REGION=eu-central-1
- USE_SINGLE_REGION=true
volumes:
- ./src/test/resources/localstack/local-aws-infrastructure.sh:/docker-entrypoint-initaws.d/init.sh
keycloak:
Expand Down
9 changes: 5 additions & 4 deletions getting-started-with-spring-boot-on-aws/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ repositories {
}

ext {
set('awsSpringVersion', '3.0.1')
set('testcontainersVersion', '1.18.0')
set('awsLambdaJavaEventsVersion', '3.11.2')
set('awsJavaSdkCoreVersion', '1.12.481')
set('awsSpringVersion', '3.1.1')
set('testcontainersVersion', '1.19.8')
set('awsLambdaJavaEventsVersion', '3.11.5')
set('awsJavaSdkCoreVersion', '1.12.739')
}

dependencies {
Expand All @@ -28,6 +28,7 @@ dependencies {
// AWS Java SDK v1/v2 agnostic library for type-safe access to the S3 event object
implementation "com.amazonaws:aws-lambda-java-events:${awsLambdaJavaEventsVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:localstack'
testImplementation 'org.testcontainers:junit-jupiter'
// Required to compile due to coupling between the LocalStack Testcontainers module and the AWS Java SDK v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ApplicationTest {

@Container
static LocalStackContainer localStack =
new LocalStackContainer(DockerImageName.parse("localstack/localstack:0.14.0"))
new LocalStackContainer(DockerImageName.parse("localstack/localstack"))
.withServices(SQS, S3, SSM);

@BeforeAll
Expand Down

0 comments on commit c07af8a

Please sign in to comment.