Skip to content

Commit 3f1f801

Browse files
committed
Update spring-boot-testcontainers to use docker-test plugin
See gh-41228
1 parent d78c7b5 commit 3f1f801

File tree

32 files changed

+197
-124
lines changed

32 files changed

+197
-124
lines changed

spring-boot-project/spring-boot-testcontainers/build.gradle

+39-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id "org.springframework.boot.configuration-properties"
55
id "org.springframework.boot.conventions"
66
id "org.springframework.boot.deployed"
7+
id "org.springframework.boot.docker-test"
78
id "org.springframework.boot.optional-dependencies"
89
}
910

@@ -13,14 +14,50 @@ dependencies {
1314
api(project(":spring-boot-project:spring-boot-autoconfigure"))
1415
api("org.testcontainers:testcontainers")
1516

17+
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
18+
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
19+
dockerTestImplementation("ch.qos.logback:logback-classic")
20+
dockerTestImplementation("co.elastic.clients:elasticsearch-java") {
21+
exclude group: "commons-logging", module: "commons-logging"
22+
}
23+
dockerTestImplementation("com.couchbase.client:java-client")
24+
dockerTestImplementation("com.datastax.oss:java-driver-core")
25+
dockerTestImplementation("io.micrometer:micrometer-registry-otlp")
26+
dockerTestImplementation("io.rest-assured:rest-assured") {
27+
exclude group: "commons-logging", module: "commons-logging"
28+
}
29+
dockerTestImplementation("org.apache.activemq:activemq-client-jakarta")
30+
dockerTestImplementation("org.assertj:assertj-core")
31+
dockerTestImplementation("org.awaitility:awaitility")
32+
dockerTestImplementation("org.flywaydb:flyway-core")
33+
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
34+
dockerTestImplementation("org.junit.platform:junit-platform-launcher")
35+
dockerTestImplementation("org.liquibase:liquibase-core") {
36+
exclude(group: "javax.xml.bind", module: "jaxb-api")
37+
}
38+
dockerTestImplementation("org.mockito:mockito-core")
39+
dockerTestImplementation("org.springframework:spring-core-test")
40+
dockerTestImplementation("org.springframework:spring-jdbc")
41+
dockerTestImplementation("org.springframework:spring-jms")
42+
dockerTestImplementation("org.springframework:spring-r2dbc")
43+
dockerTestImplementation("org.springframework.amqp:spring-rabbit")
44+
dockerTestImplementation("org.springframework.data:spring-data-redis")
45+
dockerTestImplementation("org.springframework.kafka:spring-kafka")
46+
dockerTestImplementation("org.springframework.pulsar:spring-pulsar")
47+
dockerTestImplementation("org.testcontainers:junit-jupiter")
48+
49+
dockerTestRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
50+
dockerTestRuntimeOnly("com.zaxxer:HikariCP")
51+
dockerTestRuntimeOnly("io.lettuce:lettuce-core")
52+
dockerTestRuntimeOnly("org.postgresql:postgresql")
53+
1654
optional(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
1755
optional("org.springframework:spring-test")
1856
optional("org.springframework.data:spring-data-mongodb")
1957
optional("org.springframework.data:spring-data-neo4j")
2058
optional("org.testcontainers:cassandra")
2159
optional("org.testcontainers:couchbase")
2260
optional("org.testcontainers:elasticsearch")
23-
optional("org.testcontainers:influxdb")
2461
optional("org.testcontainers:jdbc")
2562
optional("org.testcontainers:kafka")
2663
optional("org.testcontainers:mariadb")
@@ -36,43 +73,9 @@ dependencies {
3673
optional("org.testcontainers:redpanda")
3774
optional("org.testcontainers:r2dbc")
3875

39-
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
4076
testImplementation(project(":spring-boot-project:spring-boot-test"))
41-
testImplementation("ch.qos.logback:logback-classic")
42-
testImplementation("co.elastic.clients:elasticsearch-java") {
43-
exclude group: "commons-logging", module: "commons-logging"
44-
}
45-
testImplementation("com.couchbase.client:java-client")
46-
testImplementation("com.datastax.oss:java-driver-core")
47-
testImplementation("io.micrometer:micrometer-registry-otlp")
48-
testImplementation("io.rest-assured:rest-assured") {
49-
exclude group: "commons-logging", module: "commons-logging"
50-
}
51-
testImplementation("org.apache.activemq:activemq-client-jakarta")
77+
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
5278
testImplementation("org.assertj:assertj-core")
53-
testImplementation("org.awaitility:awaitility")
54-
testImplementation("org.flywaydb:flyway-core")
55-
testImplementation("org.influxdb:influxdb-java")
5679
testImplementation("org.junit.jupiter:junit-jupiter")
57-
testImplementation("org.junit.platform:junit-platform-engine")
58-
testImplementation("org.junit.platform:junit-platform-launcher")
59-
testImplementation("org.liquibase:liquibase-core") {
60-
exclude(group: "javax.xml.bind", module: "jaxb-api")
61-
}
6280
testImplementation("org.mockito:mockito-core")
63-
testImplementation("org.mockito:mockito-junit-jupiter")
64-
testImplementation("org.springframework:spring-core-test")
65-
testImplementation("org.springframework:spring-jdbc")
66-
testImplementation("org.springframework:spring-jms")
67-
testImplementation("org.springframework:spring-r2dbc")
68-
testImplementation("org.springframework.amqp:spring-rabbit")
69-
testImplementation("org.springframework.data:spring-data-redis")
70-
testImplementation("org.springframework.kafka:spring-kafka")
71-
testImplementation("org.springframework.pulsar:spring-pulsar")
72-
testImplementation("org.testcontainers:junit-jupiter")
73-
74-
testRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
75-
testRuntimeOnly("com.zaxxer:HikariCP")
76-
testRuntimeOnly("io.lettuce:lettuce-core")
77-
testRuntimeOnly("org.postgresql:postgresql")
7881
}
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import org.springframework.test.context.junit.jupiter.SpringExtension;
3737

3838
/**
39+
* Tests for {@link ImportTestcontainers} when properties are being injected into a
40+
* {@link LoadTimeWeaverAware} bean.
41+
*
3942
* @author Phillip Webb
4043
*/
4144
@ExtendWith(SpringExtension.class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testcontainers.service.connection.r2dbc;
18+
19+
import java.time.Duration;
20+
21+
import io.r2dbc.spi.ConnectionFactory;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.condition.OS;
24+
import org.testcontainers.junit.jupiter.Container;
25+
import org.testcontainers.junit.jupiter.Testcontainers;
26+
import org.testcontainers.oracle.OracleContainer;
27+
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
30+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
31+
import org.springframework.boot.jdbc.DatabaseDriver;
32+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
33+
import org.springframework.boot.testsupport.container.TestImage;
34+
import org.springframework.boot.testsupport.junit.DisabledOnOs;
35+
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.r2dbc.core.DatabaseClient;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
38+
39+
import static org.assertj.core.api.Assertions.assertThat;
40+
41+
/**
42+
* Tests for {@link OracleFreeR2dbcContainerConnectionDetailsFactory}.
43+
*
44+
* @author Andy Wilkinson
45+
*/
46+
@SpringJUnitConfig
47+
@Testcontainers(disabledWithoutDocker = true)
48+
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
49+
disabledReason = "The Oracle image has no ARM support")
50+
class OracleFreeR2dbcContainerConnectionDetailsFactoryIntegrationTests {
51+
52+
@Container
53+
@ServiceConnection
54+
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
55+
56+
@Autowired
57+
ConnectionFactory connectionFactory;
58+
59+
@Test
60+
void connectionCanBeMadeToOracleContainer() {
61+
Object result = DatabaseClient.create(this.connectionFactory)
62+
.sql(DatabaseDriver.ORACLE.getValidationQuery())
63+
.map((row, metadata) -> row.get(0))
64+
.first()
65+
.block(Duration.ofSeconds(30));
66+
assertThat(result).isEqualTo("Hello");
67+
}
68+
69+
@Configuration(proxyBeanMethods = false)
70+
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
71+
static class TestConfiguration {
72+
73+
}
74+
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testcontainers.service.connection.r2dbc;
18+
19+
import java.time.Duration;
20+
21+
import io.r2dbc.spi.ConnectionFactory;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.condition.OS;
24+
import org.testcontainers.containers.OracleContainer;
25+
import org.testcontainers.junit.jupiter.Container;
26+
import org.testcontainers.junit.jupiter.Testcontainers;
27+
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
30+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
31+
import org.springframework.boot.jdbc.DatabaseDriver;
32+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
33+
import org.springframework.boot.testsupport.container.TestImage;
34+
import org.springframework.boot.testsupport.junit.DisabledOnOs;
35+
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.r2dbc.core.DatabaseClient;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
38+
39+
import static org.assertj.core.api.Assertions.assertThat;
40+
41+
/**
42+
* Tests for {@link OracleXeR2dbcContainerConnectionDetailsFactory}.
43+
*
44+
* @author Andy Wilkinson
45+
*/
46+
@SpringJUnitConfig
47+
@Testcontainers(disabledWithoutDocker = true)
48+
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
49+
disabledReason = "The Oracle image has no ARM support")
50+
class OracleXeR2dbcContainerConnectionDetailsFactoryIntegrationTests {
51+
52+
@Container
53+
@ServiceConnection
54+
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
55+
56+
@Autowired
57+
ConnectionFactory connectionFactory;
58+
59+
@Test
60+
void connectionCanBeMadeToOracleContainer() {
61+
Object result = DatabaseClient.create(this.connectionFactory)
62+
.sql(DatabaseDriver.ORACLE.getValidationQuery())
63+
.map((row, metadata) -> row.get(0))
64+
.first()
65+
.block(Duration.ofSeconds(30));
66+
assertThat(result).isEqualTo("Hello");
67+
}
68+
69+
@Configuration(proxyBeanMethods = false)
70+
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
71+
static class TestConfiguration {
72+
73+
}
74+
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml"/>
4+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.test.context.cache.maxSize=1

spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/r2dbc/OracleFreeR2dbcContainerConnectionDetailsFactoryTests.java

-44
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,12 @@
1616

1717
package org.springframework.boot.testcontainers.service.connection.r2dbc;
1818

19-
import java.time.Duration;
20-
21-
import io.r2dbc.spi.ConnectionFactory;
2219
import io.r2dbc.spi.ConnectionFactoryOptions;
2320
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.condition.OS;
25-
import org.testcontainers.junit.jupiter.Container;
26-
import org.testcontainers.junit.jupiter.Testcontainers;
27-
import org.testcontainers.oracle.OracleContainer;
2821

2922
import org.springframework.aot.hint.RuntimeHints;
3023
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
31-
import org.springframework.beans.factory.annotation.Autowired;
32-
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
33-
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
34-
import org.springframework.boot.jdbc.DatabaseDriver;
3524
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactoryHints;
36-
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
37-
import org.springframework.boot.testsupport.container.TestImage;
38-
import org.springframework.boot.testsupport.junit.DisabledOnOs;
39-
import org.springframework.context.annotation.Configuration;
40-
import org.springframework.r2dbc.core.DatabaseClient;
41-
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4225

4326
import static org.assertj.core.api.Assertions.assertThat;
4427

@@ -47,39 +30,12 @@
4730
*
4831
* @author Andy Wilkinson
4932
*/
50-
@SpringJUnitConfig
51-
@Testcontainers(disabledWithoutDocker = true)
52-
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
53-
disabledReason = "The Oracle image has no ARM support")
5433
class OracleFreeR2dbcContainerConnectionDetailsFactoryTests {
5534

56-
@Container
57-
@ServiceConnection
58-
static final OracleContainer oracle = TestImage.container(OracleContainer.class);
59-
60-
@Autowired
61-
ConnectionFactory connectionFactory;
62-
63-
@Test
64-
void connectionCanBeMadeToOracleContainer() {
65-
Object result = DatabaseClient.create(this.connectionFactory)
66-
.sql(DatabaseDriver.ORACLE.getValidationQuery())
67-
.map((row, metadata) -> row.get(0))
68-
.first()
69-
.block(Duration.ofSeconds(30));
70-
assertThat(result).isEqualTo("Hello");
71-
}
72-
7335
@Test
7436
void shouldRegisterHints() {
7537
RuntimeHints hints = ContainerConnectionDetailsFactoryHints.getRegisteredHints(getClass().getClassLoader());
7638
assertThat(RuntimeHintsPredicates.reflection().onType(ConnectionFactoryOptions.class)).accepts(hints);
7739
}
7840

79-
@Configuration(proxyBeanMethods = false)
80-
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
81-
static class TestConfiguration {
82-
83-
}
84-
8541
}

0 commit comments

Comments
 (0)