Skip to content

Commit

Permalink
chore: keep docker compose dependency with test scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmformenti committed May 18, 2024
1 parent 68dfddd commit 21963ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>

<!-- Databases - Uses H2 by default -->
<dependency>
Expand Down Expand Up @@ -122,6 +118,11 @@
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ A similar setup is provided for MySQL and PostgreSQL if a persistent database co
You only need to pass the Spring Boot profile at the time of running the application:

```bash
./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql
./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.MysqlTestApplication
```

or

```bash
./mvnw spring-boot:run -Dspring-boot.run.profiles=postgres
./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.PostgresIntegrationTests
```

## Test Applications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

package org.springframework.samples.petclinic;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.testcontainers.containers.MySQLContainer;

/**
* PetClinic Spring Boot Application.
Expand All @@ -32,15 +28,10 @@
@Configuration
public class MysqlTestApplication {

@ServiceConnection
@Profile("mysql")
@Bean
static MySQLContainer<?> container() {
return new MySQLContainer<>("mysql:8.2");
}

public static void main(String[] args) {
SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql");
new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("mysql") //
.run(args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package org.springframework.samples.petclinic;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -47,6 +40,13 @@
import org.springframework.web.client.RestTemplate;
import org.testcontainers.DockerClientFactory;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", //
"spring.docker.compose.profiles.active=postgres" })
@ActiveProfiles("postgres")
Expand All @@ -70,9 +70,6 @@ static void available() {
public static void main(String[] args) {
new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("postgres") //
.properties( //
"spring.docker.compose.profiles.active=postgres" //
) //
.listeners(new PropertiesLogger()) //
.run(args);
}
Expand Down

0 comments on commit 21963ae

Please sign in to comment.