Update spring-boot-testcontainers to use docker-test plugin

See gh-41228
This commit is contained in:
Andy Wilkinson
2024-06-25 10:51:33 +01:00
parent d78c7b541a
commit 3f1f801461
32 changed files with 197 additions and 124 deletions

View File

@@ -4,6 +4,7 @@ plugins {
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.conventions"
id "org.springframework.boot.deployed"
id "org.springframework.boot.docker-test"
id "org.springframework.boot.optional-dependencies"
}
@@ -13,6 +14,43 @@ dependencies {
api(project(":spring-boot-project:spring-boot-autoconfigure"))
api("org.testcontainers:testcontainers")
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
dockerTestImplementation("ch.qos.logback:logback-classic")
dockerTestImplementation("co.elastic.clients:elasticsearch-java") {
exclude group: "commons-logging", module: "commons-logging"
}
dockerTestImplementation("com.couchbase.client:java-client")
dockerTestImplementation("com.datastax.oss:java-driver-core")
dockerTestImplementation("io.micrometer:micrometer-registry-otlp")
dockerTestImplementation("io.rest-assured:rest-assured") {
exclude group: "commons-logging", module: "commons-logging"
}
dockerTestImplementation("org.apache.activemq:activemq-client-jakarta")
dockerTestImplementation("org.assertj:assertj-core")
dockerTestImplementation("org.awaitility:awaitility")
dockerTestImplementation("org.flywaydb:flyway-core")
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
dockerTestImplementation("org.junit.platform:junit-platform-launcher")
dockerTestImplementation("org.liquibase:liquibase-core") {
exclude(group: "javax.xml.bind", module: "jaxb-api")
}
dockerTestImplementation("org.mockito:mockito-core")
dockerTestImplementation("org.springframework:spring-core-test")
dockerTestImplementation("org.springframework:spring-jdbc")
dockerTestImplementation("org.springframework:spring-jms")
dockerTestImplementation("org.springframework:spring-r2dbc")
dockerTestImplementation("org.springframework.amqp:spring-rabbit")
dockerTestImplementation("org.springframework.data:spring-data-redis")
dockerTestImplementation("org.springframework.kafka:spring-kafka")
dockerTestImplementation("org.springframework.pulsar:spring-pulsar")
dockerTestImplementation("org.testcontainers:junit-jupiter")
dockerTestRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
dockerTestRuntimeOnly("com.zaxxer:HikariCP")
dockerTestRuntimeOnly("io.lettuce:lettuce-core")
dockerTestRuntimeOnly("org.postgresql:postgresql")
optional(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
optional("org.springframework:spring-test")
optional("org.springframework.data:spring-data-mongodb")
@@ -20,7 +58,6 @@ dependencies {
optional("org.testcontainers:cassandra")
optional("org.testcontainers:couchbase")
optional("org.testcontainers:elasticsearch")
optional("org.testcontainers:influxdb")
optional("org.testcontainers:jdbc")
optional("org.testcontainers:kafka")
optional("org.testcontainers:mariadb")
@@ -36,43 +73,9 @@ dependencies {
optional("org.testcontainers:redpanda")
optional("org.testcontainers:r2dbc")
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation(project(":spring-boot-project:spring-boot-test"))
testImplementation("ch.qos.logback:logback-classic")
testImplementation("co.elastic.clients:elasticsearch-java") {
exclude group: "commons-logging", module: "commons-logging"
}
testImplementation("com.couchbase.client:java-client")
testImplementation("com.datastax.oss:java-driver-core")
testImplementation("io.micrometer:micrometer-registry-otlp")
testImplementation("io.rest-assured:rest-assured") {
exclude group: "commons-logging", module: "commons-logging"
}
testImplementation("org.apache.activemq:activemq-client-jakarta")
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation("org.assertj:assertj-core")
testImplementation("org.awaitility:awaitility")
testImplementation("org.flywaydb:flyway-core")
testImplementation("org.influxdb:influxdb-java")
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.platform:junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-launcher")
testImplementation("org.liquibase:liquibase-core") {
exclude(group: "javax.xml.bind", module: "jaxb-api")
}
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.springframework:spring-core-test")
testImplementation("org.springframework:spring-jdbc")
testImplementation("org.springframework:spring-jms")
testImplementation("org.springframework:spring-r2dbc")
testImplementation("org.springframework.amqp:spring-rabbit")
testImplementation("org.springframework.data:spring-data-redis")
testImplementation("org.springframework.kafka:spring-kafka")
testImplementation("org.springframework.pulsar:spring-pulsar")
testImplementation("org.testcontainers:junit-jupiter")
testRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
testRuntimeOnly("com.zaxxer:HikariCP")
testRuntimeOnly("io.lettuce:lettuce-core")
testRuntimeOnly("org.postgresql:postgresql")
}

View File

@@ -36,6 +36,9 @@ import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Tests for {@link ImportTestcontainers} when properties are being injected into a
* {@link LoadTimeWeaverAware} bean.
*
* @author Phillip Webb
*/
@ExtendWith(SpringExtension.class)

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testcontainers.service.connection.r2dbc;
import java.time.Duration;
import io.r2dbc.spi.ConnectionFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.oracle.OracleContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.context.annotation.Configuration;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link OracleFreeR2dbcContainerConnectionDetailsFactory}.
*
* @author Andy Wilkinson
*/
@SpringJUnitConfig
@Testcontainers(disabledWithoutDocker = true)
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleFreeR2dbcContainerConnectionDetailsFactoryIntegrationTests {
@Container
@ServiceConnection
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
@Autowired
ConnectionFactory connectionFactory;
@Test
void connectionCanBeMadeToOracleContainer() {
Object result = DatabaseClient.create(this.connectionFactory)
.sql(DatabaseDriver.ORACLE.getValidationQuery())
.map((row, metadata) -> row.get(0))
.first()
.block(Duration.ofSeconds(30));
assertThat(result).isEqualTo("Hello");
}
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
static class TestConfiguration {
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testcontainers.service.connection.r2dbc;
import java.time.Duration;
import io.r2dbc.spi.ConnectionFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.context.annotation.Configuration;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link OracleXeR2dbcContainerConnectionDetailsFactory}.
*
* @author Andy Wilkinson
*/
@SpringJUnitConfig
@Testcontainers(disabledWithoutDocker = true)
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleXeR2dbcContainerConnectionDetailsFactoryIntegrationTests {
@Container
@ServiceConnection
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
@Autowired
ConnectionFactory connectionFactory;
@Test
void connectionCanBeMadeToOracleContainer() {
Object result = DatabaseClient.create(this.connectionFactory)
.sql(DatabaseDriver.ORACLE.getValidationQuery())
.map((row, metadata) -> row.get(0))
.first()
.block(Duration.ofSeconds(30));
assertThat(result).isEqualTo("Hello");
}
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
static class TestConfiguration {
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
</configuration>

View File

@@ -0,0 +1 @@
spring.test.context.cache.maxSize=1

View File

@@ -16,29 +16,12 @@
package org.springframework.boot.testcontainers.service.connection.r2dbc;
import java.time.Duration;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.oracle.OracleContainer;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactoryHints;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.context.annotation.Configuration;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,39 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@SpringJUnitConfig
@Testcontainers(disabledWithoutDocker = true)
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleFreeR2dbcContainerConnectionDetailsFactoryTests {
@Container
@ServiceConnection
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
@Autowired
ConnectionFactory connectionFactory;
@Test
void connectionCanBeMadeToOracleContainer() {
Object result = DatabaseClient.create(this.connectionFactory)
.sql(DatabaseDriver.ORACLE.getValidationQuery())
.map((row, metadata) -> row.get(0))
.first()
.block(Duration.ofSeconds(30));
assertThat(result).isEqualTo("Hello");
}
@Test
void shouldRegisterHints() {
RuntimeHints hints = ContainerConnectionDetailsFactoryHints.getRegisteredHints(getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onType(ConnectionFactoryOptions.class)).accepts(hints);
}
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
static class TestConfiguration {
}
}

View File

@@ -16,29 +16,12 @@
package org.springframework.boot.testcontainers.service.connection.r2dbc;
import java.time.Duration;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactoryHints;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.context.annotation.Configuration;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,39 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@SpringJUnitConfig
@Testcontainers(disabledWithoutDocker = true)
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleXeR2dbcContainerConnectionDetailsFactoryTests {
@Container
@ServiceConnection
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
@Autowired
ConnectionFactory connectionFactory;
@Test
void connectionCanBeMadeToOracleContainer() {
Object result = DatabaseClient.create(this.connectionFactory)
.sql(DatabaseDriver.ORACLE.getValidationQuery())
.map((row, metadata) -> row.get(0))
.first()
.block(Duration.ofSeconds(30));
assertThat(result).isEqualTo("Hello");
}
@Test
void shouldRegisterHints() {
RuntimeHints hints = ContainerConnectionDetailsFactoryHints.getRegisteredHints(getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onType(ConnectionFactoryOptions.class)).accepts(hints);
}
@Configuration(proxyBeanMethods = false)
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
static class TestConfiguration {
}
}