Add support for Bitnami container images with Docker Compose

Closes gh-35759
This commit is contained in:
Scott Frederick 2023-11-17 15:56:30 -06:00 committed by Scott Frederick
parent 533f6c3bb1
commit 09a6ae51cc
50 changed files with 993 additions and 65 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -32,10 +32,12 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
class CassandraDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<CassandraConnectionDetails> {
private static final String[] CASSANDRA_CONTAINER_NAMES = { "cassandra", "bitnami/cassandra" };
private static final int CASSANDRA_PORT = 9042;
CassandraDockerComposeConnectionDetailsFactory() {
super("cassandra");
super(CASSANDRA_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -28,7 +28,7 @@ class CassandraEnvironment {
private final String datacenter;
CassandraEnvironment(Map<String, String> env) {
this.datacenter = env.getOrDefault("CASSANDRA_DC", "datacenter1");
this.datacenter = env.getOrDefault("CASSANDRA_DC", env.getOrDefault("CASSANDRA_DATACENTER", "datacenter1"));
}
String getDatacenter() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,14 +31,17 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class ElasticsearchDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ElasticsearchConnectionDetails> {
private static final String[] ELASTICSEARCH_CONTAINER_NAMES = { "elasticsearch", "bitnami/elasticsearch" };
private static final int ELASTICSEARCH_PORT = 9200;
protected ElasticsearchDockerComposeConnectionDetailsFactory() {
super("elasticsearch");
super(ELASTICSEARCH_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbEnvironment {
@ -52,7 +53,7 @@ class MariaDbEnvironment {
Assert.state(!env.containsKey("MYSQL_RANDOM_ROOT_PASSWORD"), "MYSQL_RANDOM_ROOT_PASSWORD is not supported");
Assert.state(!env.containsKey("MARIADB_ROOT_PASSWORD_HASH"), "MARIADB_ROOT_PASSWORD_HASH is not supported");
boolean allowEmpty = env.containsKey("MARIADB_ALLOW_EMPTY_PASSWORD")
|| env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD");
|| env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD") || env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("MARIADB_PASSWORD");
password = (password != null) ? password : env.get("MYSQL_PASSWORD");
password = (password != null) ? password : env.get("MARIADB_ROOT_PASSWORD");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -29,12 +29,15 @@ import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBu
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] MARIADB_CONTAINER_NAMES = { "mariadb", "bitnami/mariadb" };
protected MariaDbJdbcDockerComposeConnectionDetailsFactory() {
super("mariadb");
super(MARIADB_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,12 +31,15 @@ import org.springframework.boot.docker.compose.service.connection.r2dbc.Connecti
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] MARIADB_CONTAINER_NAMES = { "mariadb", "bitnami/mariadb" };
MariaDbR2dbcDockerComposeConnectionDetailsFactory() {
super("mariadb", "io.r2dbc.spi.ConnectionFactoryOptions");
super(MARIADB_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -34,10 +34,12 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
*/
class MongoDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<MongoConnectionDetails> {
private static final String[] MONGODB_CONTAINER_NAMES = { "mongo", "bitnami/mongodb" };
private static final int MONGODB_PORT = 27017;
protected MongoDockerComposeConnectionDetailsFactory() {
super("mongo", "com.mongodb.ConnectionString");
super(MONGODB_CONTAINER_NAMES, "com.mongodb.ConnectionString");
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -26,6 +26,7 @@ import org.springframework.util.Assert;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MongoEnvironment {
@ -40,8 +41,8 @@ class MongoEnvironment {
"MONGO_INITDB_ROOT_USERNAME_FILE is not supported");
Assert.state(!env.containsKey("MONGO_INITDB_ROOT_PASSWORD_FILE"),
"MONGO_INITDB_ROOT_PASSWORD_FILE is not supported");
this.username = env.get("MONGO_INITDB_ROOT_USERNAME");
this.password = env.get("MONGO_INITDB_ROOT_PASSWORD");
this.username = env.getOrDefault("MONGO_INITDB_ROOT_USERNAME", env.get("MONGO_ROOT_USERNAME"));
this.password = env.getOrDefault("MONGO_INITDB_ROOT_PASSWORD", env.get("MONGO_ROOT_PASSWORD"));
this.database = env.get("MONGO_INITDB_DATABASE");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlEnvironment {
@ -44,7 +45,7 @@ class MySqlEnvironment {
private String extractPassword(Map<String, String> env) {
Assert.state(!env.containsKey("MYSQL_RANDOM_ROOT_PASSWORD"), "MYSQL_RANDOM_ROOT_PASSWORD is not supported");
boolean allowEmpty = env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD");
boolean allowEmpty = env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD") || env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("MYSQL_PASSWORD");
password = (password != null) ? password : env.get("MYSQL_ROOT_PASSWORD");
Assert.state(StringUtils.hasLength(password) || allowEmpty, "No MySQL password found");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -29,12 +29,15 @@ import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBu
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] MYSQL_CONTAINER_NAMES = { "mysql", "bitnami/mysql" };
protected MySqlJdbcDockerComposeConnectionDetailsFactory() {
super("mysql");
super(MYSQL_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,12 +31,15 @@ import org.springframework.boot.docker.compose.service.connection.r2dbc.Connecti
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] MYSQL_CONTAINER_NAMES = { "mysql", "bitnami/mysql" };
MySqlR2dbcDockerComposeConnectionDetailsFactory() {
super("mysql", "io.r2dbc.spi.ConnectionFactoryOptions");
super(MYSQL_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -30,11 +30,14 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
* for a {@code Neo4j} service.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class Neo4jDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<Neo4jConnectionDetails> {
private static final String[] NEO4J_CONTAINER_NAMES = { "neo4j", "bitnami/neo4j" };
Neo4jDockerComposeConnectionDetailsFactory() {
super("neo4j");
super(NEO4J_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -25,13 +25,18 @@ import org.neo4j.driver.AuthTokens;
* Neo4j environment details.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class Neo4jEnvironment {
private final AuthToken authToken;
Neo4jEnvironment(Map<String, String> env) {
this.authToken = parse(env.get("NEO4J_AUTH"));
AuthToken authToken = parse(env.get("NEO4J_AUTH"));
if (authToken == null && env.containsKey("NEO4J_PASSWORD")) {
authToken = parse("neo4j/" + env.get("NEO4J_PASSWORD"));
}
this.authToken = authToken;
}
private AuthToken parse(String neo4jAuth) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresEnvironment {
@ -37,14 +38,14 @@ class PostgresEnvironment {
private final String database;
PostgresEnvironment(Map<String, String> env) {
this.username = env.getOrDefault("POSTGRES_USER", "postgres");
this.username = env.getOrDefault("POSTGRES_USER", env.getOrDefault("POSTGRESQL_USER", "postgres"));
this.password = extractPassword(env);
this.database = env.getOrDefault("POSTGRES_DB", this.username);
this.database = env.getOrDefault("POSTGRES_DB", env.getOrDefault("POSTGRESQL_DB", this.username));
}
private String extractPassword(Map<String, String> env) {
String password = env.get("POSTGRES_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No POSTGRES_PASSWORD defined");
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
return password;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -29,12 +29,15 @@ import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBu
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] POSTGRES_CONTAINER_NAMES = { "postgres", "bitnami/postgresql" };
protected PostgresJdbcDockerComposeConnectionDetailsFactory() {
super("postgres");
super(POSTGRES_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,12 +31,15 @@ import org.springframework.boot.docker.compose.service.connection.r2dbc.Connecti
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] POSTGRES_CONTAINER_NAMES = { "postgres", "bitnami/postgresql" };
PostgresR2dbcDockerComposeConnectionDetailsFactory() {
super("postgres", "io.r2dbc.spi.ConnectionFactoryOptions");
super(POSTGRES_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -30,14 +30,17 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RabbitDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<RabbitConnectionDetails> {
private static final String[] RABBITMQ_CONTAINER_NAMES = { "rabbitmq", "bitnami/rabbitmq" };
private static final int RABBITMQ_PORT = 5672;
protected RabbitDockerComposeConnectionDetailsFactory() {
super("rabbitmq");
super(RABBITMQ_CONTAINER_NAMES);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -24,6 +24,7 @@ import java.util.Map;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RabbitEnvironment {
@ -32,8 +33,8 @@ class RabbitEnvironment {
private final String password;
RabbitEnvironment(Map<String, String> env) {
this.username = env.getOrDefault("RABBITMQ_DEFAULT_USER", "guest");
this.password = env.getOrDefault("RABBITMQ_DEFAULT_PASS", "guest");
this.username = env.getOrDefault("RABBITMQ_DEFAULT_USER", env.getOrDefault("RABBITMQ_USERNAME", "guest"));
this.password = env.getOrDefault("RABBITMQ_DEFAULT_PASS", env.getOrDefault("RABBITMQ_PASSWORD", "guest"));
}
String getUsername() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -28,13 +28,16 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RedisDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<RedisConnectionDetails> {
private static final String[] REDIS_CONTAINER_NAMES = { "redis", "bitnami/redis" };
private static final int REDIS_PORT = 6379;
RedisDockerComposeConnectionDetailsFactory() {
super("redis");
super(REDIS_CONTAINER_NAMES);
}
@Override

View File

@ -0,0 +1,55 @@
/*
* 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.docker.compose.service.connection.cassandra;
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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for {@link CassandraDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("cassandra-bitnami-compose.yaml", BitnamiImageNames.cassandra());
}
@Test
void runCreatesConnectionDetails() {
CassandraConnectionDetails connectionDetails = run(CassandraConnectionDetails.class);
List<Node> contactPoints = connectionDetails.getContactPoints();
assertThat(contactPoints).hasSize(1);
Node node = contactPoints.get(0);
assertThat(node.host()).isNotNull();
assertThat(node.port()).isGreaterThan(0);
assertThat(connectionDetails.getUsername()).isNull();
assertThat(connectionDetails.getPassword()).isNull();
assertThat(connectionDetails.getLocalDatacenter()).isEqualTo("testdc1");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -48,7 +48,7 @@ class CassandraDockerComposeConnectionDetailsFactoryIntegrationTests extends Abs
assertThat(node.port()).isGreaterThan(0);
assertThat(connectionDetails.getUsername()).isNull();
assertThat(connectionDetails.getPassword()).isNull();
assertThat(connectionDetails.getLocalDatacenter()).isEqualTo("dc1");
assertThat(connectionDetails.getLocalDatacenter()).isEqualTo("testdc1");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -36,10 +36,16 @@ class CassandraEnvironmentTests {
assertThat(environment.getDatacenter()).isEqualTo("datacenter1");
}
@Test
void getDatacenterWhenDcIsSet() {
CassandraEnvironment environment = new CassandraEnvironment(Map.of("CASSANDRA_DC", "testdc1"));
assertThat(environment.getDatacenter()).isEqualTo("testdc1");
}
@Test
void getDatacenterWhenDatacenterIsSet() {
CassandraEnvironment environment = new CassandraEnvironment(Map.of("CASSANDRA_DC", "dc1"));
assertThat(environment.getDatacenter()).isEqualTo("dc1");
CassandraEnvironment environment = new CassandraEnvironment(Map.of("CASSANDRA_DATACENTER", "testdc1"));
assertThat(environment.getDatacenter()).isEqualTo("testdc1");
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link ElasticsearchDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("elasticsearch-bitnami-compose.yaml", BitnamiImageNames.elasticsearch());
}
@Test
void runCreatesConnectionDetails() {
ElasticsearchConnectionDetails connectionDetails = run(ElasticsearchConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("elastic");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getPathPrefix()).isNull();
assertThat(connectionDetails.getNodes()).hasSize(1);
Node node = connectionDetails.getNodes().get(0);
assertThat(node.hostname()).isNotNull();
assertThat(node.port()).isGreaterThan(0);
assertThat(node.protocol()).isEqualTo(Protocol.HTTP);
assertThat(node.username()).isEqualTo("elastic");
assertThat(node.password()).isEqualTo("secret");
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link MariaDbJdbcDockerComposeConnectionDetailsFactory}
*
* @author Scott Frederick
*/
class MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-bitnami-compose.yaml", BitnamiImageNames.mariadb());
}
@Test
void runCreatesConnectionDetails() {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:mariadb://").endsWith("/mydatabase");
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link MariaDbR2dbcDockerComposeConnectionDetailsFactory}
*
* @author Scott Frederick
*/
class MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mariadb-bitnami-compose.yaml", BitnamiImageNames.mariadb());
}
@Test
void runCreatesConnectionDetails() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("database=mydatabase", "driver=mariadb",
"password=REDACTED", "user=myuser");
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Jinseong Hwang
* @author Scott Frederick
*/
class MariaDbEnvironmentTests {
@ -130,6 +131,13 @@ class MariaDbEnvironmentTests {
assertThat(environment.getPassword()).isEqualTo("secret");
}
@Test
void getPasswordWhenHasNoPasswordAndAllowEmptyPassword() {
MariaDbEnvironment environment = new MariaDbEnvironment(
Map.of("ALLOW_EMPTY_PASSWORD", "true", "MARIADB_DATABASE", "db"));
assertThat(environment.getPassword()).isEmpty();
}
@Test
void getPasswordWhenHasNoPasswordAndMariadbAllowEmptyPassword() {
MariaDbEnvironment environment = new MariaDbEnvironment(

View File

@ -0,0 +1,50 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link MongoDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mongo-bitnami-compose.yaml", BitnamiImageNames.mongo());
}
@Test
void runCreatesConnectionDetails() {
MongoConnectionDetails connectionDetails = run(MongoConnectionDetails.class);
ConnectionString connectionString = connectionDetails.getConnectionString();
assertThat(connectionString.getCredential().getUserName()).isEqualTo("root");
assertThat(connectionString.getCredential().getPassword()).isEqualTo("secret".toCharArray());
assertThat(connectionString.getCredential().getSource()).isEqualTo("admin");
assertThat(connectionString.getDatabase()).isEqualTo("test");
assertThat(connectionDetails.getGridFs()).isNull();
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link MySqlJdbcDockerComposeConnectionDetailsFactory}
*
* @author Scott Frederick
*/
class MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-bitnami-compose.yaml", BitnamiImageNames.mysql());
}
@Test
void runCreatesConnectionDetails() {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:mysql://").endsWith("/mydatabase");
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link MySqlR2dbcDockerComposeConnectionDetailsFactory}
*
* @author Scott Frederick
*/
class MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("mysql-bitnami-compose.yaml", BitnamiImageNames.mysql());
}
@Test
void runCreatesConnectionDetails() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("database=mydatabase", "driver=mysql",
"password=REDACTED", "user=myuser");
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Jinseong Hwang
* @author Scott Frederick
*/
class MySqlEnvironmentTests {
@ -86,6 +87,13 @@ class MySqlEnvironmentTests {
assertThat(environment.getPassword()).isEmpty();
}
@Test
void getPasswordWhenHasNoPasswordAndAllowEmptyPassword() {
MySqlEnvironment environment = new MySqlEnvironment(
Map.of("ALLOW_EMPTY_PASSWORD", "true", "MYSQL_DATABASE", "db"));
assertThat(environment.getPassword()).isEmpty();
}
@Test
void getDatabaseWhenHasMysqlDatabase() {
MySqlEnvironment environment = new MySqlEnvironment(

View File

@ -0,0 +1,51 @@
/*
* Copyright 2012-2023 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.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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
/**
* Integration tests for {@link Neo4jDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("neo4j-bitnami-compose.yaml", BitnamiImageNames.neo4j());
}
@Test
void runCreatesConnectionDetailsThatCanAccessNeo4j() {
Neo4jConnectionDetails connectionDetails = run(Neo4jConnectionDetails.class);
assertThat(connectionDetails.getAuthToken()).isEqualTo(AuthTokens.basic("neo4j", "bitnami2"));
try (Driver driver = GraphDatabase.driver(connectionDetails.getUri(), connectionDetails.getAuthToken())) {
assertThatNoException().isThrownBy(driver::verifyConnectivity);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -29,11 +29,12 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Tests for {@link Neo4jEnvironment}.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class Neo4jEnvironmentTests {
@Test
void whenNeo4jAuthIsNullThenAuthTokenIsNull() {
void whenNeo4jAuthAndPasswordAreNullThenAuthTokenIsNull() {
Neo4jEnvironment environment = new Neo4jEnvironment(Collections.emptyMap());
assertThat(environment.getAuthToken()).isNull();
}
@ -56,4 +57,10 @@ class Neo4jEnvironmentTests {
.isThrownBy(() -> new Neo4jEnvironment(Map.of("NEO4J_AUTH", "graphdb/custom-password")));
}
@Test
void whenNeo4jPasswordIsProvidedThenAuthTokenIsBasic() {
Neo4jEnvironment environment = new Neo4jEnvironment(Map.of("NEO4J_PASSWORD", "custom-password"));
assertThat(environment.getAuthToken()).isEqualTo(AuthTokens.basic("neo4j", "custom-password"));
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.docker.compose.service.connection.postgres;
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.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link PostgresJdbcDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("postgres-bitnami-compose.yaml", BitnamiImageNames.postgresql());
}
@Test
void runCreatesConnectionDetails() {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:postgresql://").endsWith("/mydatabase");
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.docker.compose.service.connection.postgres;
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.testsupport.testcontainers.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link PostgresR2dbcDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests
extends AbstractDockerComposeIntegrationTests {
PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("postgres-bitnami-compose.yaml", BitnamiImageNames.postgresql());
}
@Test
void runCreatesConnectionDetails() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("database=mydatabase", "driver=postgresql",
"password=REDACTED", "user=myuser");
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -30,13 +30,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresEnvironmentTests {
@Test
void createWhenNoPostgresPasswordThrowsException() {
assertThatIllegalStateException().isThrownBy(() -> new PostgresEnvironment(Collections.emptyMap()))
.withMessage("No POSTGRES_PASSWORD defined");
.withMessage("PostgreSQL password must be provided");
}
@Test
@ -45,6 +46,12 @@ class PostgresEnvironmentTests {
assertThat(environment.getUsername()).isEqualTo("postgres");
}
@Test
void getUsernameWhenNoPostgresqlUser() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getUsername()).isEqualTo("postgres");
}
@Test
void getUsernameWhenHasPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(
@ -52,18 +59,37 @@ class PostgresEnvironmentTests {
assertThat(environment.getUsername()).isEqualTo("me");
}
@Test
void getUsernameWhenHasPostgresqlUser() {
PostgresEnvironment environment = new PostgresEnvironment(
Map.of("POSTGRESQL_USER", "me", "POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getUsername()).isEqualTo("me");
}
@Test
void getPasswordWhenHasPostgresPassword() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));
assertThat(environment.getPassword()).isEqualTo("secret");
}
@Test
void getPasswordWhenHasPostgresqlPassword() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getPassword()).isEqualTo("secret");
}
@Test
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));
assertThat(environment.getDatabase()).isEqualTo("postgres");
}
@Test
void getDatabaseWhenNoPostgresqlDbOrPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getDatabase()).isEqualTo("postgres");
}
@Test
void getDatabaseWhenNoPostgresDbAndPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(
@ -71,6 +97,13 @@ class PostgresEnvironmentTests {
assertThat(environment.getDatabase()).isEqualTo("me");
}
@Test
void getDatabaseWhenNoPostgresqlDbAndPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(
Map.of("POSTGRESQL_USER", "me", "POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getDatabase()).isEqualTo("me");
}
@Test
void getDatabaseWhenHasPostgresDb() {
PostgresEnvironment environment = new PostgresEnvironment(
@ -78,4 +111,11 @@ class PostgresEnvironmentTests {
assertThat(environment.getDatabase()).isEqualTo("db");
}
@Test
void getDatabaseWhenHasPostgresqlDb() {
PostgresEnvironment environment = new PostgresEnvironment(
Map.of("POSTGRESQL_DB", "db", "POSTGRESQL_PASSWORD", "secret"));
assertThat(environment.getDatabase()).isEqualTo("db");
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.docker.compose.service.connection.rabbit;
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.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link RabbitDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("rabbit-bitnami-compose.yaml", BitnamiImageNames.rabbit());
}
@Test
void runCreatesConnectionDetails() {
RabbitConnectionDetails connectionDetails = run(RabbitConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getVirtualHost()).isEqualTo("/");
assertThat(connectionDetails.getAddresses()).hasSize(1);
Address address = connectionDetails.getFirstAddress();
assertThat(address.host()).isNotNull();
assertThat(address.port()).isGreaterThan(0);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RabbitEnvironmentTests {
@ -44,6 +45,12 @@ class RabbitEnvironmentTests {
assertThat(environment.getUsername()).isEqualTo("me");
}
@Test
void getUsernameWhenHasRabbitmqUsername() {
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_USERNAME", "me"));
assertThat(environment.getUsername()).isEqualTo("me");
}
@Test
void getUsernameWhenNoRabbitmqDefaultPass() {
RabbitEnvironment environment = new RabbitEnvironment(Collections.emptyMap());
@ -56,4 +63,10 @@ class RabbitEnvironmentTests {
assertThat(environment.getPassword()).isEqualTo("secret");
}
@Test
void getUsernameWhenHasRabbitmqPassword() {
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_PASSWORD", "secret"));
assertThat(environment.getPassword()).isEqualTo("secret");
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.docker.compose.service.connection.redis;
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.BitnamiImageNames;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for {@link RedisDockerComposeConnectionDetailsFactory}.
*
* @author Scott Frederick
*/
class RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("redis-bitnami-compose.yaml", BitnamiImageNames.redis());
}
@Test
void runCreatesConnectionDetails() {
RedisConnectionDetails connectionDetails = run(RedisConnectionDetails.class);
Standalone standalone = connectionDetails.getStandalone();
assertThat(connectionDetails.getUsername()).isNull();
assertThat(connectionDetails.getPassword()).isNull();
assertThat(connectionDetails.getCluster()).isNull();
assertThat(connectionDetails.getSentinel()).isNull();
assertThat(standalone).isNotNull();
assertThat(standalone.getDatabase()).isZero();
assertThat(standalone.getPort()).isGreaterThan(0);
assertThat(standalone.getHost()).isNotNull();
}
}

View File

@ -0,0 +1,8 @@
services:
cassandra:
image: '{imageName}'
ports:
- '9042'
environment:
- 'CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch'
- 'CASSANDRA_DATACENTER=testdc1'

View File

@ -9,4 +9,4 @@ services:
- 'HEAP_NEWSIZE=128M'
- 'MAX_HEAP_SIZE=1024M'
- 'CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch'
- 'CASSANDRA_DC=dc1'
- 'CASSANDRA_DC=testdc1'

View File

@ -0,0 +1,9 @@
services:
elasticsearch:
image: '{imageName}'
environment:
- 'ELASTIC_PASSWORD=secret'
- 'ES_JAVA_OPTS=-Xmx1024m'
ports:
- '9200'
- '9300'

View File

@ -0,0 +1,10 @@
services:
database:
image: '{imageName}'
ports:
- '3306'
environment:
- 'MARIADB_ROOT_PASSWORD=verysecret'
- 'MARIADB_USER=myuser'
- 'MARIADB_PASSWORD=secret'
- 'MARIADB_DATABASE=mydatabase'

View File

@ -0,0 +1,8 @@
services:
mongo:
image: '{imageName}'
ports:
- '27017'
environment:
- 'MONGO_ROOT_USERNAME=root'
- 'MONGO_ROOT_PASSWORD=secret'

View File

@ -0,0 +1,10 @@
services:
database:
image: '{imageName}'
ports:
- '3306'
environment:
- 'MYSQL_ROOT_PASSWORD=verysecret'
- 'MYSQL_USER=myuser'
- 'MYSQL_PASSWORD=secret'
- 'MYSQL_DATABASE=mydatabase'

View File

@ -0,0 +1,7 @@
services:
neo4j:
image: 'bitnami/neo4j:5.16.0'
ports:
- '7687'
environment:
- 'NEO4J_PASSWORD=bitnami2'

View File

@ -0,0 +1,9 @@
services:
database:
image: '{imageName}'
ports:
- '5432'
environment:
- 'POSTGRESQL_USER=myuser'
- 'POSTGRESQL_DB=mydatabase'
- 'POSTGRESQL_PASSWORD=secret'

View File

@ -0,0 +1,8 @@
services:
rabbitmq:
image: '{imageName}'
environment:
- 'RABBITMQ_DEFAULT_USER=myuser'
- 'RABBITMQ_DEFAULT_PASS=secret'
ports:
- '5672'

View File

@ -0,0 +1,7 @@
services:
redis:
image: '{imageName}'
ports:
- '6379'
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'

View File

@ -70,28 +70,28 @@ The following service connections are currently supported:
| Connection Details | Matched on
| `ActiveMQConnectionDetails`
| Containers named "symptoma/activemq", "apache/activemq-classic"
| Containers named "symptoma/activemq" or "apache/activemq-classic"
| `ArtemisConnectionDetails`
| Containers named "apache/activemq-artemis"
| `CassandraConnectionDetails`
| Containers named "cassandra"
| Containers named "cassandra" or "bitnami/cassandra"
| `ElasticsearchConnectionDetails`
| Containers named "elasticsearch"
| Containers named "elasticsearch" or "bitnami/elasticsearch"
| `JdbcConnectionDetails`
| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "mssql/server", "mysql", or "postgres"
| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql"
| `LdapConnectionDetails`
| Containers named "osixia/openldap"
| `MongoConnectionDetails`
| Containers named "mongo"
| Containers named "mongo" or "bitnami/mongodb"
| `Neo4jConnectionDetails`
| Containers named "neo4j"
| Containers named "neo4j" or "bitnami/neo4j"
| `OtlpMetricsConnectionDetails`
| Containers named "otel/opentelemetry-collector-contrib"
@ -103,13 +103,13 @@ The following service connections are currently supported:
| Containers named "apachepulsar/pulsar"
| `R2dbcConnectionDetails`
| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "mssql/server", "mysql", or "postgres"
| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql"
| `RabbitConnectionDetails`
| Containers named "rabbitmq"
| Containers named "rabbitmq" or "bitnami/rabbitmq"
| `RedisConnectionDetails`
| Containers named "redis"
| Containers named "redis" or "bitnami/redis"
| `ZipkinConnectionDetails`
| Containers named "openzipkin/zipkin".

View File

@ -0,0 +1,122 @@
/*
* 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.testsupport.testcontainers;
import org.testcontainers.utility.DockerImageName;
/**
* Create {@link DockerImageName} for Bitnami instances for services used in integration
* tests.
*
* @author Scott Frederick
*/
public final class BitnamiImageNames {
private static final String CASSANDRA_VERSION = "4.1.3";
private static final String ELASTICSEARCH_VERSION = "8.12.1";
private static final String MARIADB_VERSION = "11.2.3";
private static final String MONGO_VERSION = "7.0.5";
private static final String MYSQL_VERSION = "8.0.36";
private static final String NEO4J_VERSION = "5.16.0";
private static final String POSTGRESQL_VERSION = "16.2.0";
private static final String RABBIT_VERSION = "3.11.28";
private static final String REDIS_VERSION = "7.2.4";
private BitnamiImageNames() {
}
/**
* Return a {@link DockerImageName} suitable for running Cassandra.
* @return a docker image name for running cassandra
*/
public static DockerImageName cassandra() {
return DockerImageName.parse("bitnami/cassandra").withTag(CASSANDRA_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Elasticsearch 7.
* @return a docker image name for running elasticsearch
*/
public static DockerImageName elasticsearch() {
return DockerImageName.parse("bitnami/elasticsearch").withTag(ELASTICSEARCH_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running MariaDB.
* @return a docker image name for running MariaDB
*/
public static DockerImageName mariadb() {
return DockerImageName.parse("bitnami/mariadb").withTag(MARIADB_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Mongo.
* @return a docker image name for running mongo
*/
public static DockerImageName mongo() {
return DockerImageName.parse("bitnami/mongodb").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("bitnami/mysql").withTag(MYSQL_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Neo4j.
* @return a docker image name for running neo4j
*/
public static DockerImageName neo4j() {
return DockerImageName.parse("bitnami/neo4j").withTag(NEO4J_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running PostgreSQL.
* @return a docker image name for running postgresql
*/
public static DockerImageName postgresql() {
return DockerImageName.parse("bitnami/postgresql").withTag(POSTGRESQL_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running RabbitMQ.
* @return a docker image name for running RabbitMQ
*/
public static DockerImageName rabbit() {
return DockerImageName.parse("bitnami/rabbitmq").withTag(RABBIT_VERSION);
}
/**
* Return a {@link DockerImageName} suitable for running Redis.
* @return a docker image name for running redis
*/
public static DockerImageName redis() {
return DockerImageName.parse("bitnami/redis").withTag(REDIS_VERSION);
}
}