diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java index a7d4b270e5..f1706973c0 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java @@ -34,7 +34,7 @@ import org.springframework.util.ObjectUtils; * {@link ConnectionDetails} from a {@link ContainerConnectionSource}. * * @param the connection details type - * @param the generic container type + * @param the container type * @author Moritz Halbritter * @author Andy Wilkinson * @author Phillip Webb @@ -110,23 +110,30 @@ public abstract class ContainerConnectionDetailsFactory the container type */ - protected static class ContainerConnectionDetails implements ConnectionDetails, OriginProvider { + protected static class ContainerConnectionDetails> + implements ConnectionDetails, OriginProvider { - private final Origin origin; + private final ContainerConnectionSource source; /** * Create a new {@link ContainerConnectionDetails} instance. * @param source the source {@link ContainerConnectionSource} */ - protected ContainerConnectionDetails(ContainerConnectionSource source) { + protected ContainerConnectionDetails(ContainerConnectionSource source) { Assert.notNull(source, "Source must not be null"); - this.origin = source.getOrigin(); + this.source = source; + } + + protected final C getContainer() { + return this.source.getContainer(); } @Override public Origin getOrigin() { - return this.origin; + return this.source.getOrigin(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java index f83e6e523e..22d5472e8d 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java @@ -118,11 +118,7 @@ public final class ContainerConnectionSource> implements return this.origin; } - /** - * Return the {@link Container} that implements the service being connected to. - * @return the {@link Container} providing the service - */ - public C getContainer() { + C getContainer() { return this.container; } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/amqp/RabbitContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/amqp/RabbitContainerConnectionDetailsFactory.java index 7607324948..22bfc90f1d 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/amqp/RabbitContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/amqp/RabbitContainerConnectionDetailsFactory.java @@ -47,29 +47,26 @@ class RabbitContainerConnectionDetailsFactory /** * {@link RabbitConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class RabbitMqContainerConnectionDetails extends ContainerConnectionDetails + private static final class RabbitMqContainerConnectionDetails extends ContainerConnectionDetails implements RabbitConnectionDetails { - private final RabbitMQContainer container; - private RabbitMqContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.container = source.getContainer(); } @Override public String getUsername() { - return this.container.getAdminUsername(); + return getContainer().getAdminUsername(); } @Override public String getPassword() { - return this.container.getAdminPassword(); + return getContainer().getAdminPassword(); } @Override public List
getAddresses() { - URI uri = URI.create(this.container.getAmqpUrl()); + URI uri = URI.create(getContainer().getAmqpUrl()); return List.of(new Address(uri.getHost(), uri.getPort())); } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/cassandra/CassandraContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/cassandra/CassandraContainerConnectionDetailsFactory.java index 4953c1d17c..64428f13b6 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/cassandra/CassandraContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/cassandra/CassandraContainerConnectionDetailsFactory.java @@ -16,6 +16,7 @@ package org.springframework.boot.testcontainers.service.connection.cassandra; +import java.net.InetSocketAddress; import java.util.List; import org.testcontainers.containers.CassandraContainer; @@ -46,35 +47,32 @@ class CassandraContainerConnectionDetailsFactory /** * {@link CassandraConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class CassandraContainerConnectionDetails extends ContainerConnectionDetails - implements CassandraConnectionDetails { - - private final CassandraContainer container; + private static final class CassandraContainerConnectionDetails + extends ContainerConnectionDetails> implements CassandraConnectionDetails { private CassandraContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.container = source.getContainer(); } @Override public List getContactPoints() { - return List.of(new Node(this.container.getContactPoint().getHostString(), - this.container.getContactPoint().getPort())); + InetSocketAddress contactPoint = getContainer().getContactPoint(); + return List.of(new Node(contactPoint.getHostString(), contactPoint.getPort())); } @Override public String getUsername() { - return this.container.getUsername(); + return getContainer().getUsername(); } @Override public String getPassword() { - return this.container.getPassword(); + return getContainer().getPassword(); } @Override public String getLocalDatacenter() { - return this.container.getLocalDatacenter(); + return getContainer().getLocalDatacenter(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/couchbase/CouchbaseContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/couchbase/CouchbaseContainerConnectionDetailsFactory.java index e77468de32..1f69368702 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/couchbase/CouchbaseContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/couchbase/CouchbaseContainerConnectionDetailsFactory.java @@ -44,29 +44,26 @@ class CouchbaseContainerConnectionDetailsFactory /** * {@link CouchbaseConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class CouchbaseContainerConnectionDetails extends ContainerConnectionDetails - implements CouchbaseConnectionDetails { - - private final CouchbaseContainer container; + private static final class CouchbaseContainerConnectionDetails + extends ContainerConnectionDetails implements CouchbaseConnectionDetails { private CouchbaseContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.container = source.getContainer(); } @Override public String getUsername() { - return this.container.getUsername(); + return getContainer().getUsername(); } @Override public String getPassword() { - return this.container.getPassword(); + return getContainer().getPassword(); } @Override public String getConnectionString() { - return this.container.getConnectionString(); + return getContainer().getConnectionString(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactory.java index 69b1f600a9..91aec4eae4 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactory.java @@ -50,20 +50,18 @@ class ElasticsearchContainerConnectionDetailsFactory * {@link ElasticsearchConnectionDetails} backed by a * {@link ContainerConnectionSource}. */ - private static final class ElasticsearchContainerConnectionDetails extends ContainerConnectionDetails - implements ElasticsearchConnectionDetails { - - private final List nodes; + private static final class ElasticsearchContainerConnectionDetails + extends ContainerConnectionDetails implements ElasticsearchConnectionDetails { private ElasticsearchContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.nodes = List.of(new Node(source.getContainer().getHost(), - source.getContainer().getMappedPort(DEFAULT_PORT), Protocol.HTTP, null, null)); } @Override public List getNodes() { - return this.nodes; + String host = getContainer().getHost(); + Integer port = getContainer().getMappedPort(DEFAULT_PORT); + return List.of(new Node(host, port, Protocol.HTTP, null, null)); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/flyway/FlywayContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/flyway/FlywayContainerConnectionDetailsFactory.java index 5a52bfeaee..4f36c22727 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/flyway/FlywayContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/flyway/FlywayContainerConnectionDetailsFactory.java @@ -42,34 +42,31 @@ class FlywayContainerConnectionDetailsFactory /** * {@link FlywayConnectionDetails} backed by a {@link JdbcDatabaseContainer}. */ - private static final class FlywayContainerConnectionDetails extends ContainerConnectionDetails - implements FlywayConnectionDetails { - - private final JdbcDatabaseContainer container; + private static final class FlywayContainerConnectionDetails + extends ContainerConnectionDetails> implements FlywayConnectionDetails { private FlywayContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.container = source.getContainer(); } @Override public String getUsername() { - return this.container.getUsername(); + return getContainer().getUsername(); } @Override public String getPassword() { - return this.container.getPassword(); + return getContainer().getPassword(); } @Override public String getJdbcUrl() { - return this.container.getJdbcUrl(); + return getContainer().getJdbcUrl(); } @Override public String getDriverClassName() { - return this.container.getDriverClassName(); + return getContainer().getDriverClassName(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/jdbc/JdbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/jdbc/JdbcContainerConnectionDetailsFactory.java index 9112eb5f9f..d4b246dd0e 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/jdbc/JdbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/jdbc/JdbcContainerConnectionDetailsFactory.java @@ -43,34 +43,31 @@ class JdbcContainerConnectionDetailsFactory /** * {@link JdbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class JdbcContainerConnectionDetails extends ContainerConnectionDetails - implements JdbcConnectionDetails { - - private final JdbcDatabaseContainer container; + private static final class JdbcContainerConnectionDetails + extends ContainerConnectionDetails> implements JdbcConnectionDetails { private JdbcContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.container = source.getContainer(); } @Override public String getUsername() { - return this.container.getUsername(); + return getContainer().getUsername(); } @Override public String getPassword() { - return this.container.getPassword(); + return getContainer().getPassword(); } @Override public String getJdbcUrl() { - return this.container.getJdbcUrl(); + return getContainer().getJdbcUrl(); } @Override public String getDriverClassName() { - return this.container.getDriverClassName(); + return getContainer().getDriverClassName(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/kafka/KafkaContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/kafka/KafkaContainerConnectionDetailsFactory.java index abf3f6c9d8..2e20b63a32 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/kafka/KafkaContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/kafka/KafkaContainerConnectionDetailsFactory.java @@ -45,19 +45,16 @@ class KafkaContainerConnectionDetailsFactory /** * {@link KafkaConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class KafkaContainerConnectionDetails extends ContainerConnectionDetails + private static final class KafkaContainerConnectionDetails extends ContainerConnectionDetails implements KafkaConnectionDetails { - private final KafkaContainer container; - private KafkaContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.container = source.getContainer(); } @Override public List getBootstrapNodes() { - URI uri = URI.create(this.container.getBootstrapServers()); + URI uri = URI.create(getContainer().getBootstrapServers()); return List.of(new Node(uri.getHost(), uri.getPort())); } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/liquibase/LiquibaseContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/liquibase/LiquibaseContainerConnectionDetailsFactory.java index 73fb1c728a..356771aa46 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/liquibase/LiquibaseContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/liquibase/LiquibaseContainerConnectionDetailsFactory.java @@ -42,34 +42,31 @@ class LiquibaseContainerConnectionDetailsFactory /** * {@link LiquibaseConnectionDetails} backed by a {@link JdbcDatabaseContainer}. */ - private static final class LiquibaseContainerConnectionDetails extends ContainerConnectionDetails - implements LiquibaseConnectionDetails { - - private final JdbcDatabaseContainer container; + private static final class LiquibaseContainerConnectionDetails + extends ContainerConnectionDetails> implements LiquibaseConnectionDetails { private LiquibaseContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.container = source.getContainer(); } @Override public String getUsername() { - return this.container.getUsername(); + return getContainer().getUsername(); } @Override public String getPassword() { - return this.container.getPassword(); + return getContainer().getPassword(); } @Override public String getJdbcUrl() { - return this.container.getJdbcUrl(); + return getContainer().getJdbcUrl(); } @Override public String getDriverClassName() { - return this.container.getDriverClassName(); + return getContainer().getDriverClassName(); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/mongo/MongoContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/mongo/MongoContainerConnectionDetailsFactory.java index 4a7bfe1cca..2981a37095 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/mongo/MongoContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/mongo/MongoContainerConnectionDetailsFactory.java @@ -47,19 +47,16 @@ class MongoContainerConnectionDetailsFactory /** * {@link MongoConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class MongoContainerConnectionDetails extends ContainerConnectionDetails + private static final class MongoContainerConnectionDetails extends ContainerConnectionDetails implements MongoConnectionDetails { - private final ConnectionString connectionString; - private MongoContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.connectionString = new ConnectionString(source.getContainer().getReplicaSetUrl()); } @Override public ConnectionString getConnectionString() { - return this.connectionString; + return new ConnectionString(getContainer().getReplicaSetUrl()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/neo4j/Neo4jContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/neo4j/Neo4jContainerConnectionDetailsFactory.java index 7f94a74ba6..59cca33923 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/neo4j/Neo4jContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/neo4j/Neo4jContainerConnectionDetailsFactory.java @@ -51,24 +51,21 @@ class Neo4jContainerConnectionDetailsFactory /** * {@link Neo4jConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class Neo4jContainerConnectionDetails extends ContainerConnectionDetails + private static final class Neo4jContainerConnectionDetails extends ContainerConnectionDetails> implements Neo4jConnectionDetails { - private final Neo4jContainer container; - private Neo4jContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.container = source.getContainer(); } @Override public URI getUri() { - return URI.create(this.container.getBoltUrl()); + return URI.create(getContainer().getBoltUrl()); } @Override public AuthToken getAuthToken() { - String password = this.container.getAdminPassword(); + String password = getContainer().getAdminPassword(); return (password != null) ? AuthTokens.basic("neo4j", password) : AuthTokens.none(); } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MariaDbR2dbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MariaDbR2dbcContainerConnectionDetailsFactory.java index bfbcf6bea0..13f5bf71f4 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MariaDbR2dbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MariaDbR2dbcContainerConnectionDetailsFactory.java @@ -42,23 +42,22 @@ class MariaDbR2dbcContainerConnectionDetailsFactory @Override public R2dbcConnectionDetails getContainerConnectionDetails(ContainerConnectionSource> source) { - return new R2dbcDatabaseContainerConnectionDetails(source.getContainer()); + return new MariaDbR2dbcDatabaseContainerConnectionDetails(source); } /** * {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class R2dbcDatabaseContainerConnectionDetails implements R2dbcConnectionDetails { + private static final class MariaDbR2dbcDatabaseContainerConnectionDetails + extends ContainerConnectionDetails> implements R2dbcConnectionDetails { - private final MariaDBContainer container; - - private R2dbcDatabaseContainerConnectionDetails(MariaDBContainer container) { - this.container = container; + private MariaDbR2dbcDatabaseContainerConnectionDetails(ContainerConnectionSource> source) { + super(source); } @Override public ConnectionFactoryOptions getConnectionFactoryOptions() { - return MariaDBR2DBCDatabaseContainer.getOptions(this.container); + return MariaDBR2DBCDatabaseContainer.getOptions(getContainer()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MySqlR2dbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MySqlR2dbcContainerConnectionDetailsFactory.java index d6084574af..c16c44a6ea 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MySqlR2dbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/MySqlR2dbcContainerConnectionDetailsFactory.java @@ -42,23 +42,22 @@ class MySqlR2dbcContainerConnectionDetailsFactory @Override public R2dbcConnectionDetails getContainerConnectionDetails(ContainerConnectionSource> source) { - return new R2dbcDatabaseContainerConnectionDetails(source.getContainer()); + return new MySqlR2dbcDatabaseContainerConnectionDetails(source); } /** * {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class R2dbcDatabaseContainerConnectionDetails implements R2dbcConnectionDetails { + private static final class MySqlR2dbcDatabaseContainerConnectionDetails + extends ContainerConnectionDetails> implements R2dbcConnectionDetails { - private final MySQLContainer container; - - private R2dbcDatabaseContainerConnectionDetails(MySQLContainer container) { - this.container = container; + private MySqlR2dbcDatabaseContainerConnectionDetails(ContainerConnectionSource> source) { + super(source); } @Override public ConnectionFactoryOptions getConnectionFactoryOptions() { - return MySQLR2DBCDatabaseContainer.getOptions(this.container); + return MySQLR2DBCDatabaseContainer.getOptions(getContainer()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/OracleR2dbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/OracleR2dbcContainerConnectionDetailsFactory.java index 3d11143de1..4e13489ab3 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/OracleR2dbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/OracleR2dbcContainerConnectionDetailsFactory.java @@ -46,19 +46,16 @@ class OracleR2dbcContainerConnectionDetailsFactory /** * {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class R2dbcDatabaseContainerConnectionDetails extends ContainerConnectionDetails - implements R2dbcConnectionDetails { - - private final OracleContainer container; + private static final class R2dbcDatabaseContainerConnectionDetails + extends ContainerConnectionDetails implements R2dbcConnectionDetails { private R2dbcDatabaseContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.container = source.getContainer(); } @Override public ConnectionFactoryOptions getConnectionFactoryOptions() { - return OracleR2DBCDatabaseContainer.getOptions(this.container); + return OracleR2DBCDatabaseContainer.getOptions(getContainer()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/PostgresR2dbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/PostgresR2dbcContainerConnectionDetailsFactory.java index 5ce9d47e2c..6fcace7419 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/PostgresR2dbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/PostgresR2dbcContainerConnectionDetailsFactory.java @@ -43,23 +43,22 @@ class PostgresR2dbcContainerConnectionDetailsFactory @Override public R2dbcConnectionDetails getContainerConnectionDetails( ContainerConnectionSource> source) { - return new R2dbcDatabaseContainerConnectionDetails(source.getContainer()); + return new PostgresR2dbcDatabaseContainerConnectionDetails(source); } /** * {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class R2dbcDatabaseContainerConnectionDetails implements R2dbcConnectionDetails { + private static final class PostgresR2dbcDatabaseContainerConnectionDetails + extends ContainerConnectionDetails> implements R2dbcConnectionDetails { - private final PostgreSQLContainer container; - - private R2dbcDatabaseContainerConnectionDetails(PostgreSQLContainer container) { - this.container = container; + PostgresR2dbcDatabaseContainerConnectionDetails(ContainerConnectionSource> source) { + super(source); } @Override public ConnectionFactoryOptions getConnectionFactoryOptions() { - return PostgreSQLR2DBCDatabaseContainer.getOptions(this.container); + return PostgreSQLR2DBCDatabaseContainer.getOptions(getContainer()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/SqlServerR2dbcContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/SqlServerR2dbcContainerConnectionDetailsFactory.java index 44916da73e..a9b3faa5d8 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/SqlServerR2dbcContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/r2dbc/SqlServerR2dbcContainerConnectionDetailsFactory.java @@ -43,23 +43,23 @@ class SqlServerR2dbcContainerConnectionDetailsFactory @Override public R2dbcConnectionDetails getContainerConnectionDetails( ContainerConnectionSource> source) { - return new R2dbcDatabaseContainerConnectionDetails(source.getContainer()); + return new MsSqlServerR2dbcDatabaseContainerConnectionDetails(source); } /** * {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class R2dbcDatabaseContainerConnectionDetails implements R2dbcConnectionDetails { + private static final class MsSqlServerR2dbcDatabaseContainerConnectionDetails + extends ContainerConnectionDetails> implements R2dbcConnectionDetails { - private final MSSQLServerContainer container; - - private R2dbcDatabaseContainerConnectionDetails(MSSQLServerContainer container) { - this.container = container; + private MsSqlServerR2dbcDatabaseContainerConnectionDetails( + ContainerConnectionSource> source) { + super(source); } @Override public ConnectionFactoryOptions getConnectionFactoryOptions() { - return MSSQLR2DBCDatabaseContainer.getOptions(this.container); + return MSSQLR2DBCDatabaseContainer.getOptions(getContainer()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redis/RedisContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redis/RedisContainerConnectionDetailsFactory.java index 06bc429a40..2828a8c92b 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redis/RedisContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redis/RedisContainerConnectionDetailsFactory.java @@ -48,20 +48,16 @@ class RedisContainerConnectionDetailsFactory /** * {@link RedisConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class RedisContainerConnectionDetails extends ContainerConnectionDetails + private static final class RedisContainerConnectionDetails extends ContainerConnectionDetails> implements RedisConnectionDetails { - private final Standalone standalone; - private RedisContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.standalone = Standalone.of(source.getContainer().getHost(), - source.getContainer().getFirstMappedPort()); } @Override public Standalone getStandalone() { - return this.standalone; + return Standalone.of(getContainer().getHost(), getContainer().getFirstMappedPort()); } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redpanda/RedpandaContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redpanda/RedpandaContainerConnectionDetailsFactory.java index dd862197d5..82c15188cf 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redpanda/RedpandaContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/redpanda/RedpandaContainerConnectionDetailsFactory.java @@ -44,19 +44,16 @@ class RedpandaContainerConnectionDetailsFactory /** * {@link KafkaConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static final class RedpandaContainerConnectionDetails extends ContainerConnectionDetails + private static final class RedpandaContainerConnectionDetails extends ContainerConnectionDetails implements KafkaConnectionDetails { - private final RedpandaContainer container; - private RedpandaContainerConnectionDetails(ContainerConnectionSource source) { super(source); - this.container = source.getContainer(); } @Override public List getBootstrapNodes() { - URI uri = URI.create(this.container.getBootstrapServers()); + URI uri = URI.create(getContainer().getBootstrapServers()); return List.of(new Node(uri.getHost(), uri.getPort())); } diff --git a/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactoryTests.java b/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactoryTests.java index 7ea50a5582..7f3ea1fb64 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactoryTests.java +++ b/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactoryTests.java @@ -46,7 +46,7 @@ class ContainerConnectionDetailsFactoryTests { private Origin origin; - private JdbcDatabaseContainer container; + private PostgreSQLContainer container; private MergedAnnotation annotation; @@ -127,10 +127,10 @@ class ContainerConnectionDetailsFactoryTests { return new TestContainerConnectionDetails(source); } - static class TestContainerConnectionDetails extends ContainerConnectionDetails - implements JdbcConnectionDetails { + private static final class TestContainerConnectionDetails + extends ContainerConnectionDetails> implements JdbcConnectionDetails { - TestContainerConnectionDetails(ContainerConnectionSource source) { + private TestContainerConnectionDetails(ContainerConnectionSource> source) { super(source); }