From 09a6ae51cc83ba9e07da4922cb5d12d080ae57fd Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Fri, 17 Nov 2023 15:56:30 -0600 Subject: [PATCH] Add support for Bitnami container images with Docker Compose Closes gh-35759 --- ...DockerComposeConnectionDetailsFactory.java | 6 +- .../cassandra/CassandraEnvironment.java | 4 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- .../mariadb/MariaDbEnvironment.java | 5 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 6 +- .../connection/mongo/MongoEnvironment.java | 7 +- .../connection/mysql/MySqlEnvironment.java | 5 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- .../connection/neo4j/Neo4jEnvironment.java | 9 +- .../postgres/PostgresEnvironment.java | 11 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- .../connection/rabbit/RabbitEnvironment.java | 7 +- ...DockerComposeConnectionDetailsFactory.java | 7 +- ...nectionDetailsFactoryIntegrationTests.java | 55 ++++++++ ...nectionDetailsFactoryIntegrationTests.java | 4 +- .../cassandra/CassandraEnvironmentTests.java | 12 +- ...nectionDetailsFactoryIntegrationTests.java | 56 ++++++++ ...nectionDetailsFactoryIntegrationTests.java | 47 +++++++ ...nectionDetailsFactoryIntegrationTests.java | 49 +++++++ .../mariadb/MariaDbEnvironmentTests.java | 10 +- ...nectionDetailsFactoryIntegrationTests.java | 50 +++++++ ...nectionDetailsFactoryIntegrationTests.java | 47 +++++++ ...nectionDetailsFactoryIntegrationTests.java | 49 +++++++ .../mysql/MySqlEnvironmentTests.java | 10 +- ...nectionDetailsFactoryIntegrationTests.java | 51 ++++++++ .../neo4j/Neo4jEnvironmentTests.java | 11 +- ...nectionDetailsFactoryIntegrationTests.java | 47 +++++++ ...nectionDetailsFactoryIntegrationTests.java | 49 +++++++ .../postgres/PostgresEnvironmentTests.java | 44 ++++++- ...nectionDetailsFactoryIntegrationTests.java | 51 ++++++++ .../rabbit/RabbitEnvironmentTests.java | 15 ++- ...nectionDetailsFactoryIntegrationTests.java | 53 ++++++++ .../cassandra/cassandra-bitnami-compose.yaml | 8 ++ .../cassandra/cassandra-compose.yaml | 2 +- .../elasticsearch-bitnami-compose.yaml | 9 ++ .../mariadb/mariadb-bitnami-compose.yaml | 10 ++ .../mongo/mongo-bitnami-compose.yaml | 8 ++ .../mysql/mysql-bitnami-compose.yaml | 10 ++ .../neo4j/neo4j-bitnami-compose.yaml | 7 + .../postgres/postgres-bitnami-compose.yaml | 9 ++ .../rabbit/rabbit-bitnami-compose.yaml | 8 ++ .../redis/redis-bitnami-compose.yaml | 7 + .../asciidoc/features/docker-compose.adoc | 18 +-- .../testcontainers/BitnamiImageNames.java | 122 ++++++++++++++++++ 50 files changed, 993 insertions(+), 65 deletions(-) create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/redis/RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/elasticsearch/elasticsearch-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mariadb/mariadb-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mongo/mongo-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mysql/mysql-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/neo4j/neo4j-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/postgres/postgres-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/rabbit/rabbit-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/redis/redis-bitnami-compose.yaml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/BitnamiImageNames.java diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactory.java index aa5d86d8b8..7065297869 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironment.java index 84ed5f9704..e49f7c40e6 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironment.java @@ -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 env) { - this.datacenter = env.getOrDefault("CASSANDRA_DC", "datacenter1"); + this.datacenter = env.getOrDefault("CASSANDRA_DC", env.getOrDefault("CASSANDRA_DATACENTER", "datacenter1")); } String getDatacenter() { diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchDockerComposeConnectionDetailsFactory.java index 1304bef2b2..e2e27630be 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironment.java index 388d77d952..7da0a5e716 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironment.java @@ -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"); diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbJdbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbJdbcDockerComposeConnectionDetailsFactory.java index f5c2e85a55..c0759a02f6 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbJdbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbJdbcDockerComposeConnectionDetailsFactory.java @@ -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 { + private static final String[] MARIADB_CONTAINER_NAMES = { "mariadb", "bitnami/mariadb" }; + protected MariaDbJdbcDockerComposeConnectionDetailsFactory() { - super("mariadb"); + super(MARIADB_CONTAINER_NAMES); } @Override diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbR2dbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbR2dbcDockerComposeConnectionDetailsFactory.java index 06b2f1a742..75f22d1567 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbR2dbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbR2dbcDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoDockerComposeConnectionDetailsFactory.java index 34e748c143..4fdba16f69 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoEnvironment.java index 9b881fdab6..7bdb2e407b 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoEnvironment.java @@ -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"); } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironment.java index ceb8afe5aa..d0c7fe4450 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironment.java @@ -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 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"); diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlJdbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlJdbcDockerComposeConnectionDetailsFactory.java index 5977911879..d2fb07bf44 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlJdbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlJdbcDockerComposeConnectionDetailsFactory.java @@ -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 { + private static final String[] MYSQL_CONTAINER_NAMES = { "mysql", "bitnami/mysql" }; + protected MySqlJdbcDockerComposeConnectionDetailsFactory() { - super("mysql"); + super(MYSQL_CONTAINER_NAMES); } @Override diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlR2dbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlR2dbcDockerComposeConnectionDetailsFactory.java index 6869007a6e..1b25705b49 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlR2dbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlR2dbcDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jDockerComposeConnectionDetailsFactory.java index 33bd622e23..5b58d6d1d0 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jDockerComposeConnectionDetailsFactory.java @@ -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 { + private static final String[] NEO4J_CONTAINER_NAMES = { "neo4j", "bitnami/neo4j" }; + Neo4jDockerComposeConnectionDetailsFactory() { - super("neo4j"); + super(NEO4J_CONTAINER_NAMES); } @Override diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironment.java index 59e5a90e92..eaad04475a 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironment.java @@ -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 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) { diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java index 435a936e51..4a63bbc0b6 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java @@ -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 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 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; } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactory.java index 2330a3dc81..3f4ad8653d 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactory.java @@ -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 { + private static final String[] POSTGRES_CONTAINER_NAMES = { "postgres", "bitnami/postgresql" }; + protected PostgresJdbcDockerComposeConnectionDetailsFactory() { - super("postgres"); + super(POSTGRES_CONTAINER_NAMES); } @Override diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactory.java index 835bd1fe63..cb1c66ded5 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitDockerComposeConnectionDetailsFactory.java index 7bc79b1d12..c4e85853dc 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironment.java index 4cc471149f..7d6beb70f2 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironment.java @@ -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 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() { diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/redis/RedisDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/redis/RedisDockerComposeConnectionDetailsFactory.java index 9503bde010..c41ba25ccb 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/redis/RedisDockerComposeConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/redis/RedisDockerComposeConnectionDetailsFactory.java @@ -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 { + 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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..28cc16ec33 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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 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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactoryIntegrationTests.java index 8df562e231..d9d79aeb47 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactoryIntegrationTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironmentTests.java index 9344df6654..f4f7bbd7ca 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/cassandra/CassandraEnvironmentTests.java @@ -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"); } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..88256b596c --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/elasticsearch/ElasticsearchBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..0032fa4498 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..2d68b18af3 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironmentTests.java index d291bfab1d..1aeb244e68 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mariadb/MariaDbEnvironmentTests.java @@ -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( diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..9c93a1ab59 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mongo/MongoBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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(); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..bea96f9a83 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..18ead62fcd --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironmentTests.java index 819d2ebd13..e01b4a8ebc 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/mysql/MySqlEnvironmentTests.java @@ -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( diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..6750c2363d --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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); + } + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironmentTests.java index 4cbb02d0b6..528682e773 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/neo4j/Neo4jEnvironmentTests.java @@ -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")); + } + } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..b057a37b20 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..2f5590f5ec --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresBitnamiR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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"); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java index 58d590de53..9058c1f11d 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java @@ -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"); + } + } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..abfb1ac59c --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironmentTests.java index fdac67e5ce..95d0733539 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironmentTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/rabbit/RabbitEnvironmentTests.java @@ -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"); + } + } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/redis/RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/redis/RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 0000000000..47feef6ded --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/redis/RedisBitnamiDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -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(); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-bitnami-compose.yaml new file mode 100644 index 0000000000..fc9c3d6d8f --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-bitnami-compose.yaml @@ -0,0 +1,8 @@ +services: + cassandra: + image: '{imageName}' + ports: + - '9042' + environment: + - 'CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch' + - 'CASSANDRA_DATACENTER=testdc1' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-compose.yaml index b8d5ffd528..946fd4fd35 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-compose.yaml +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/cassandra/cassandra-compose.yaml @@ -9,4 +9,4 @@ services: - 'HEAP_NEWSIZE=128M' - 'MAX_HEAP_SIZE=1024M' - 'CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch' - - 'CASSANDRA_DC=dc1' + - 'CASSANDRA_DC=testdc1' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/elasticsearch/elasticsearch-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/elasticsearch/elasticsearch-bitnami-compose.yaml new file mode 100644 index 0000000000..b68a393757 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/elasticsearch/elasticsearch-bitnami-compose.yaml @@ -0,0 +1,9 @@ +services: + elasticsearch: + image: '{imageName}' + environment: + - 'ELASTIC_PASSWORD=secret' + - 'ES_JAVA_OPTS=-Xmx1024m' + ports: + - '9200' + - '9300' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mariadb/mariadb-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mariadb/mariadb-bitnami-compose.yaml new file mode 100644 index 0000000000..64406055b9 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mariadb/mariadb-bitnami-compose.yaml @@ -0,0 +1,10 @@ +services: + database: + image: '{imageName}' + ports: + - '3306' + environment: + - 'MARIADB_ROOT_PASSWORD=verysecret' + - 'MARIADB_USER=myuser' + - 'MARIADB_PASSWORD=secret' + - 'MARIADB_DATABASE=mydatabase' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mongo/mongo-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mongo/mongo-bitnami-compose.yaml new file mode 100644 index 0000000000..0a09b5ced4 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mongo/mongo-bitnami-compose.yaml @@ -0,0 +1,8 @@ +services: + mongo: + image: '{imageName}' + ports: + - '27017' + environment: + - 'MONGO_ROOT_USERNAME=root' + - 'MONGO_ROOT_PASSWORD=secret' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mysql/mysql-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mysql/mysql-bitnami-compose.yaml new file mode 100644 index 0000000000..b0340ed3ed --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/mysql/mysql-bitnami-compose.yaml @@ -0,0 +1,10 @@ +services: + database: + image: '{imageName}' + ports: + - '3306' + environment: + - 'MYSQL_ROOT_PASSWORD=verysecret' + - 'MYSQL_USER=myuser' + - 'MYSQL_PASSWORD=secret' + - 'MYSQL_DATABASE=mydatabase' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/neo4j/neo4j-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/neo4j/neo4j-bitnami-compose.yaml new file mode 100644 index 0000000000..f60e53329a --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/neo4j/neo4j-bitnami-compose.yaml @@ -0,0 +1,7 @@ +services: + neo4j: + image: 'bitnami/neo4j:5.16.0' + ports: + - '7687' + environment: + - 'NEO4J_PASSWORD=bitnami2' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/postgres/postgres-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/postgres/postgres-bitnami-compose.yaml new file mode 100644 index 0000000000..cb34245ec1 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/postgres/postgres-bitnami-compose.yaml @@ -0,0 +1,9 @@ +services: + database: + image: '{imageName}' + ports: + - '5432' + environment: + - 'POSTGRESQL_USER=myuser' + - 'POSTGRESQL_DB=mydatabase' + - 'POSTGRESQL_PASSWORD=secret' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/rabbit/rabbit-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/rabbit/rabbit-bitnami-compose.yaml new file mode 100644 index 0000000000..1951fba4bb --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/rabbit/rabbit-bitnami-compose.yaml @@ -0,0 +1,8 @@ +services: + rabbitmq: + image: '{imageName}' + environment: + - 'RABBITMQ_DEFAULT_USER=myuser' + - 'RABBITMQ_DEFAULT_PASS=secret' + ports: + - '5672' diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/redis/redis-bitnami-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/redis/redis-bitnami-compose.yaml new file mode 100644 index 0000000000..c4d6aeb291 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/resources/org/springframework/boot/docker/compose/service/connection/redis/redis-bitnami-compose.yaml @@ -0,0 +1,7 @@ +services: + redis: + image: '{imageName}' + ports: + - '6379' + environment: + - 'ALLOW_EMPTY_PASSWORD=yes' diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/docker-compose.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/docker-compose.adoc index 9b6f4688d1..bb5f205819 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/docker-compose.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/docker-compose.adoc @@ -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". diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/BitnamiImageNames.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/BitnamiImageNames.java new file mode 100644 index 0000000000..c5a6700955 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/BitnamiImageNames.java @@ -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); + } + +}