Skip to content

Commit

Permalink
Rework Docker Compose integration tests
Browse files Browse the repository at this point in the history
This commit introduces a new annotation, `@DockerComposeTest`,
that allows a test class to have multiple tests, each of which
uses a different Docker Compose YAML file.

Closes gh-41154
  • Loading branch information
wilkinsona authored and philwebb committed Jun 20, 2024
1 parent 491f34d commit 43cd241
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.boot.docker.compose.service.connection.activemq;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -29,15 +27,10 @@
*
* @author Stephane Nicoll
*/
class ActiveMQDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

ActiveMQDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("activemq-compose.yaml", TestImage.ACTIVE_MQ);
}
class ActiveMQDockerComposeConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
ActiveMQConnectionDetails connectionDetails = run(ActiveMQConnectionDetails.class);
@DockerComposeTest(composeFile = "activemq-compose.yaml", image = TestImage.ACTIVE_MQ)
void runCreatesConnectionDetails(ActiveMQConnectionDetails connectionDetails) {
assertThat(connectionDetails.getBrokerUrl()).isNotNull().startsWith("tcp://");
assertThat(connectionDetails.getUser()).isEqualTo("root");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

import java.util.List;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.cassandra.CassandraConnectionDetails;
import org.springframework.boot.autoconfigure.cassandra.CassandraConnectionDetails.Node;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -32,15 +30,10 @@
*
* @author Scott Frederick
*/
class CassandraDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

CassandraDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("cassandra-compose.yaml", TestImage.CASSANDRA);
}
class CassandraDockerComposeConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
CassandraConnectionDetails connectionDetails = run(CassandraConnectionDetails.class);
@DockerComposeTest(composeFile = "cassandra-compose.yaml", image = TestImage.CASSANDRA)
void runCreatesConnectionDetails(CassandraConnectionDetails connectionDetails) {
List<Node> contactPoints = connectionDetails.getContactPoints();
assertThat(contactPoints).hasSize(1);
Node node = contactPoints.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package org.springframework.boot.docker.compose.service.connection.elasticsearch;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails.Node;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails.Node.Protocol;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,15 +31,10 @@
* @author Andy Wilkinson
* @author Phillip Webb
*/
class ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("elasticsearch-compose.yaml", TestImage.ELASTICSEARCH_8);
}
class ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
ElasticsearchConnectionDetails connectionDetails = run(ElasticsearchConnectionDetails.class);
@DockerComposeTest(composeFile = "elasticsearch-compose.yaml", image = TestImage.ELASTICSEARCH_8)
void runCreatesConnectionDetails(ElasticsearchConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUsername()).isEqualTo("elastic");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getPathPrefix()).isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.boot.docker.compose.service.connection.flyway;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.flyway.FlywayConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -29,15 +27,10 @@
*
* @author Andy Wilkinson
*/
class JdbcAdaptingFlywayConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

JdbcAdaptingFlywayConnectionDetailsFactoryIntegrationTests() {
super("flyway-compose.yaml", TestImage.POSTGRESQL);
}
class JdbcAdaptingFlywayConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
FlywayConnectionDetails connectionDetails = run(FlywayConnectionDetails.class);
@DockerComposeTest(composeFile = "flyway-compose.yaml", image = TestImage.POSTGRESQL)
void runCreatesConnectionDetails(FlywayConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:postgresql://").endsWith("/mydatabase");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.boot.docker.compose.service.connection.liquibase;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.liquibase.LiquibaseConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -29,15 +27,10 @@
*
* @author Andy Wilkinson
*/
class JdbcAdaptingLiquibaseConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

JdbcAdaptingLiquibaseConnectionDetailsFactoryIntegrationTests() {
super("liquibase-compose.yaml", TestImage.POSTGRESQL);
}
class JdbcAdaptingLiquibaseConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
LiquibaseConnectionDetails connectionDetails = run(LiquibaseConnectionDetails.class);
@DockerComposeTest(composeFile = "liquibase-compose.yaml", image = TestImage.POSTGRESQL)
void runCreatesConnectionDetails(LiquibaseConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:postgresql://").endsWith("/mydatabase");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.boot.docker.compose.service.connection.mariadb;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -31,15 +29,10 @@
* @author Andy Wilkinson
* @author Phillip Webb
*/
class MariaDbJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

MariaDbJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-compose.yaml", TestImage.MARIADB);
}
class MariaDbJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
@DockerComposeTest(composeFile = "mariadb-compose.yaml", image = TestImage.MARIADB)
void runCreatesConnectionDetails(JdbcConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:mariadb://").endsWith("/mydatabase");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package org.springframework.boot.docker.compose.service.connection.mariadb;

import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -32,15 +31,10 @@
* @author Andy Wilkinson
* @author Phillip Webb
*/
class MariaDbR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
class MariaDbR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {

MariaDbR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-compose.yaml", TestImage.MARIADB);
}

@Test
void runCreatesConnectionDetails() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
@DockerComposeTest(composeFile = "mariadb-compose.yaml", image = TestImage.MARIADB)
void runCreatesConnectionDetails(R2dbcConnectionDetails connectionDetails) {
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("database=mydatabase", "driver=mariadb",
"password=REDACTED", "user=myuser");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package org.springframework.boot.docker.compose.service.connection.mongo;

import com.mongodb.ConnectionString;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.mongo.MongoConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,15 +32,10 @@
* @author Phillip Webb
* @author Scott Frederick
*/
class MongoDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
class MongoDockerComposeConnectionDetailsFactoryIntegrationTests {

MongoDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mongo-compose.yaml", TestImage.MONGODB);
}

@Test
void runCreatesConnectionDetails() {
MongoConnectionDetails connectionDetails = run(MongoConnectionDetails.class);
@DockerComposeTest(composeFile = "mongo-compose.yaml", image = TestImage.MONGODB)
void runCreatesConnectionDetails(MongoConnectionDetails connectionDetails) {
ConnectionString connectionString = connectionDetails.getConnectionString();
assertThat(connectionString.getCredential().getUserName()).isEqualTo("root");
assertThat(connectionString.getCredential().getPassword()).isEqualTo("secret".toCharArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.boot.docker.compose.service.connection.mysql;

import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -31,15 +29,10 @@
* @author Andy Wilkinson
* @author Phillip Webb
*/
class MySqlJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

MySqlJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-compose.yaml", TestImage.MYSQL);
}
class MySqlJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {

@Test
void runCreatesConnectionDetails() {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
@DockerComposeTest(composeFile = "mysql-compose.yaml", image = TestImage.MYSQL)
void runCreatesConnectionDetails(JdbcConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:mysql://").endsWith("/mydatabase");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package org.springframework.boot.docker.compose.service.connection.mysql;

import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -32,15 +31,10 @@
* @author Andy Wilkinson
* @author Phillip Webb
*/
class MySqlR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
class MySqlR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {

MySqlR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-compose.yaml", TestImage.MYSQL);
}

@Test
void runCreatesConnectionDetails() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
@DockerComposeTest(composeFile = "mysql-compose.yaml", image = TestImage.MYSQL)
void runCreatesConnectionDetails(R2dbcConnectionDetails connectionDetails) {
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("database=mydatabase", "driver=mysql",
"password=REDACTED", "user=myuser");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package org.springframework.boot.docker.compose.service.connection.neo4j;

import org.junit.jupiter.api.Test;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;

import org.springframework.boot.autoconfigure.neo4j.Neo4jConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,15 +32,10 @@
*
* @author Andy Wilkinson
*/
class Neo4jDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
class Neo4jDockerComposeConnectionDetailsFactoryIntegrationTests {

Neo4jDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("neo4j-compose.yaml", TestImage.NEO4J);
}

@Test
void runCreatesConnectionDetailsThatCanAccessNeo4j() {
Neo4jConnectionDetails connectionDetails = run(Neo4jConnectionDetails.class);
@DockerComposeTest(composeFile = "neo4j-compose.yaml", image = TestImage.NEO4J)
void runCreatesConnectionDetailsThatCanAccessNeo4j(Neo4jConnectionDetails connectionDetails) {
assertThat(connectionDetails.getAuthToken()).isEqualTo(AuthTokens.basic("neo4j", "secret"));
try (Driver driver = GraphDatabase.driver(connectionDetails.getUri(), connectionDetails.getAuthToken())) {
assertThatNoException().isThrownBy(driver::verifyConnectivity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import java.time.Duration;

import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;

import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
Expand All @@ -41,17 +40,12 @@
*/
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleFreeJdbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
class OracleFreeJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {

OracleFreeJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("oracle-compose.yaml", TestImage.ORACLE_FREE);
}

@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
@DockerComposeTest(composeFile = "oracle-compose.yaml", image = TestImage.ORACLE_FREE)
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase(JdbcConnectionDetails connectionDetails)
throws Exception {
assertThat(connectionDetails.getUsername()).isEqualTo("app_user");
assertThat(connectionDetails.getPassword()).isEqualTo("app_user_secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/freepdb1");
Expand Down
Loading

0 comments on commit 43cd241

Please sign in to comment.