Merge branch '3.1.x'

Closes gh-36486
pull/36565/head
Scott Frederick 1 year ago
commit 2452958f7b

@ -29,6 +29,7 @@ dependencies {
testImplementation("org.mockito:mockito-core")
testImplementation("org.springframework:spring-core-test")
testImplementation("org.springframework:spring-test")
testImplementation("org.testcontainers:testcontainers")
testRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc")
testRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class ActiveMQDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
ActiveMQDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("activemq-compose.yaml");
super("activemq-compose.yaml", DockerImageNames.activeMq());
}
@Test

@ -23,6 +23,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class CassandraDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
CassandraDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("cassandra-compose.yaml");
super("cassandra-compose.yaml", DockerImageNames.cassandra());
}
@Test

@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnect
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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("elasticsearch-compose.yaml");
super("elasticsearch-compose.yaml", DockerImageNames.elasticsearch8());
}
@Test

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class JdbcAdaptingFlywayConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
JdbcAdaptingFlywayConnectionDetailsFactoryIntegrationTests() {
super("flyway-compose.yaml");
super("flyway-compose.yaml", DockerImageNames.postgresql());
}
@Test

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class JdbcAdaptingLiquibaseConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
JdbcAdaptingLiquibaseConnectionDetailsFactoryIntegrationTests() {
super("liquibase-compose.yaml");
super("liquibase-compose.yaml", DockerImageNames.postgresql());
}
@Test

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class MariaDbJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MariaDbJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-compose.yaml");
super("mariadb-compose.yaml", DockerImageNames.mariadb());
}
@Test

@ -21,6 +21,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class MariaDbR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MariaDbR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-compose.yaml");
super("mariadb-compose.yaml", DockerImageNames.mariadb());
}
@Test

@ -21,6 +21,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class MongoDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MongoDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mongo-compose.yaml");
super("mongo-compose.yaml", DockerImageNames.mongo());
}
@Test

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class MySqlJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MySqlJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-compose.yaml");
super("mysql-compose.yaml", DockerImageNames.mysql());
}
@Test

@ -21,6 +21,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class MySqlR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MySqlR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-compose.yaml");
super("mysql-compose.yaml", DockerImageNames.mysql());
}
@Test

@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.ClassUtils;
@ -43,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("oracle-compose.yaml");
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}
@Test

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.r2dbc.core.DatabaseClient;
import static org.assertj.core.api.Assertions.assertThat;
@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class OracleR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
OracleR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("oracle-compose.yaml");
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}
@Test

@ -20,6 +20,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("postgres-compose.yaml");
super("postgres-compose.yaml", DockerImageNames.postgresql());
}
@Test

@ -21,6 +21,7 @@ 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.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("postgres-compose.yaml");
super("postgres-compose.yaml", DockerImageNames.postgresql());
}
@Test

@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails;
import org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails.Address;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class RabbitDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
RabbitDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("rabbit-compose.yaml");
super("rabbit-compose.yaml", DockerImageNames.rabbit());
}
@Test

@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Standalone;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class RedisDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
RedisDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("redis-compose.yaml");
super("redis-compose.yaml", DockerImageNames.redis());
}
@Test

@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.ClassUtils;
@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class SqlServerJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
SqlServerJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mssqlserver-compose.yaml");
super("mssqlserver-compose.yaml", DockerImageNames.sqlserver());
}
@Test

@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.r2dbc.core.DatabaseClient;
import static org.assertj.core.api.Assertions.assertThat;
@ -42,7 +43,7 @@ class SqlServerR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
SqlServerR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mssqlserver-compose.yaml");
super("mssqlserver-compose.yaml", DockerImageNames.sqlserver());
}
@Test

@ -16,10 +16,17 @@
package org.springframework.boot.docker.compose.service.connection.test;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.io.TempDir;
import org.testcontainers.utility.DockerImageName;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationShutdownHandlers;
@ -28,28 +35,38 @@ import org.springframework.boot.testsupport.process.DisabledIfProcessUnavailable
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.function.ThrowingSupplier;
import static org.junit.Assert.fail;
/**
* Abstract base class for integration tests.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Scott Frederick
*/
@DisabledIfProcessUnavailable({ "docker", "version" })
@DisabledIfProcessUnavailable({ "docker", "compose" })
public abstract class AbstractDockerComposeIntegrationTests {
@TempDir
private static Path tempDir;
private final Resource composeResource;
private final DockerImageName dockerImageName;
@AfterAll
static void shutDown() {
SpringApplicationShutdownHandlers shutdownHandlers = SpringApplication.getShutdownHandlers();
((Runnable) shutdownHandlers).run();
}
protected AbstractDockerComposeIntegrationTests(String composeResource) {
protected AbstractDockerComposeIntegrationTests(String composeResource, DockerImageName dockerImageName) {
this.composeResource = new ClassPathResource(composeResource, getClass());
this.dockerImageName = dockerImageName;
}
protected final <T extends ConnectionDetails> T run(Class<T> type) {
@ -57,12 +74,26 @@ public abstract class AbstractDockerComposeIntegrationTests {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("spring.docker.compose.skip.in-tests", "false");
properties.put("spring.docker.compose.file",
ThrowingSupplier.of(this.composeResource::getFile).get().getAbsolutePath());
transformedComposeFile(ThrowingSupplier.of(this.composeResource::getFile).get(), this.dockerImageName));
properties.put("spring.docker.compose.stop.command", "down");
application.setDefaultProperties(properties);
return application.run().getBean(type);
}
private File transformedComposeFile(File composeFile, DockerImageName imageName) {
File tempComposeFile = Path.of(tempDir.toString(), composeFile.getName()).toFile();
try {
String composeFileContent = FileCopyUtils.copyToString(new FileReader(composeFile));
composeFileContent = composeFileContent.replace("{imageName}", imageName.asCanonicalNameString());
FileCopyUtils.copy(composeFileContent, new FileWriter(tempComposeFile));
}
catch (IOException ex) {
fail("Error transforming Docker compose file '" + composeFile + "' to '" + tempComposeFile + "': "
+ ex.getMessage());
}
return tempComposeFile;
}
@Configuration(proxyBeanMethods = false)
static class Config {

@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import static org.assertj.core.api.Assertions.assertThat;
@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class ZipkinDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
ZipkinDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("zipkin-compose.yaml");
super("zipkin-compose.yaml", DockerImageNames.zipkin());
}
@Test

@ -1,6 +1,6 @@
services:
activemq:
image: 'symptoma/activemq:5.18.0'
image: '{imageName}'
ports:
- '61616'
environment:

@ -1,6 +1,6 @@
services:
elasticsearch:
image: 'elasticsearch:8.6.1'
image: '{imageName}'
environment:
- 'ELASTIC_PASSWORD=secret'
- 'ES_JAVA_OPTS=-Xmx512m'

@ -1,6 +1,6 @@
services:
database:
image: 'gvenzl/oracle-xe:18.4.0-slim'
image: '{imageName}'
ports:
- '1521'
environment:

@ -1,6 +1,6 @@
services:
rabbitmq:
image: 'rabbitmq:3.11'
image: '{imageName}'
environment:
- 'RABBITMQ_DEFAULT_USER=myuser'
- 'RABBITMQ_DEFAULT_PASS=secret'

@ -1,6 +1,6 @@
services:
database:
image: 'mcr.microsoft.com/mssql/server'
image: '{imageName}'
ports:
- '1433'
environment:

@ -36,10 +36,16 @@ public final class DockerImageNames {
private static final String ELASTICSEARCH_VERSION = "7.17.5";
private static final String ELASTICSEARCH_8_VERSION = "8.6.1";
private static final String KAFKA_VERSION = "7.4.0";
private static final String MARIADB_VERSION = "10.10";
private static final String MONGO_VERSION = "5.0.17";
private static final String MYSQL_VERSION = "8.0";
private static final String NEO4J_VERSION = "4.4.11";
private static final String ORACLE_XE_VERSION = "18.4.0-slim";
@ -84,13 +90,21 @@ public final class DockerImageNames {
}
/**
* Return a {@link DockerImageName} suitable for running Elasticsearch.
* Return a {@link DockerImageName} suitable for running Elasticsearch 7.
* @return a docker image name for running elasticsearch
*/
public static DockerImageName elasticsearch() {
return DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch").withTag(ELASTICSEARCH_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Elasticsearch 8.
* @return a docker image name for running elasticsearch
*/
public static DockerImageName elasticsearch8() {
return DockerImageName.parse("elasticsearch").withTag(ELASTICSEARCH_8_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Kafka.
* @return a docker image name for running Kafka
@ -99,6 +113,14 @@ public final class DockerImageNames {
return DockerImageName.parse("confluentinc/cp-kafka").withTag(KAFKA_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running MariaDB.
* @return a docker image name for running Mariadb
*/
public static DockerImageName mariadb() {
return DockerImageName.parse("mariadb").withTag(MARIADB_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Mongo.
* @return a docker image name for running mongo
@ -107,6 +129,14 @@ public final class DockerImageNames {
return DockerImageName.parse("mongo").withTag(MONGO_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running MySQL.
* @return a docker image name for running MySQL
*/
public static DockerImageName mysql() {
return DockerImageName.parse("mysql").withTag(MYSQL_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Neo4j.
* @return a docker image name for running neo4j
@ -157,6 +187,14 @@ public final class DockerImageNames {
.asCompatibleSubstituteFor("docker.redpanda.com/redpandadata/redpanda");
}
/**
* Return a {@link DockerImageName} suitable for running Microsoft SQLServer.
* @return a docker image name for running SQLServer
*/
public static DockerImageName sqlserver() {
return DockerImageName.parse("mcr.microsoft.com/mssql/server");
}
/**
* Return a {@link DockerImageName} suitable for running a Docker registry.
* @return a docker image name for running a registry

Loading…
Cancel
Save