diff --git a/modules/mariadb/src/test/java/org/testcontainers/containers/MariaDBR2DBCDatabaseContainerTest.java b/modules/mariadb/src/test/java/org/testcontainers/containers/MariaDBR2DBCDatabaseContainerTest.java index 0f4acd889d5..b4216dcb246 100644 --- a/modules/mariadb/src/test/java/org/testcontainers/containers/MariaDBR2DBCDatabaseContainerTest.java +++ b/modules/mariadb/src/test/java/org/testcontainers/containers/MariaDBR2DBCDatabaseContainerTest.java @@ -1,9 +1,12 @@ package org.testcontainers.containers; import io.r2dbc.spi.ConnectionFactoryOptions; +import org.junit.Test; import org.testcontainers.r2dbc.AbstractR2DBCDatabaseContainerTest; import org.testcontainers.utility.DockerImageName; +import static org.assertj.core.api.Assertions.assertThat; + public class MariaDBR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest> { @Override @@ -20,4 +23,24 @@ protected String createR2DBCUrl() { protected MariaDBContainer createContainer() { return new MariaDBContainer<>(DockerImageName.parse("mariadb:10.3.39")); } + + @Test + public void testGetR2DBCUrl(){ + //given + MariaDBContainer container = createContainer(); + container.start(); + + String expectedUrl = "r2dbc:mariadb://" + container.getHost() + ":" + + container.getMappedPort(MariaDBContainer.MARIADB_PORT) + "/" + + container.getDatabaseName() + container.constructUrlParameters("?", "&"); + + //when + String r2dbcUrl = MariaDBR2DBCDatabaseContainer.getR2dbcUrl(container); + + //then + assertThat(expectedUrl).isEqualTo(r2dbcUrl); + + //clean-up + container.stop(); + } } diff --git a/modules/mssqlserver/src/test/java/org/testcontainers/containers/MSSQLR2DBCDatabaseContainerTest.java b/modules/mssqlserver/src/test/java/org/testcontainers/containers/MSSQLR2DBCDatabaseContainerTest.java index a0d3106f9c6..1c343abcb91 100644 --- a/modules/mssqlserver/src/test/java/org/testcontainers/containers/MSSQLR2DBCDatabaseContainerTest.java +++ b/modules/mssqlserver/src/test/java/org/testcontainers/containers/MSSQLR2DBCDatabaseContainerTest.java @@ -1,9 +1,14 @@ package org.testcontainers.containers; import io.r2dbc.spi.ConnectionFactoryOptions; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; import org.testcontainers.MSSQLServerTestImages; import org.testcontainers.r2dbc.AbstractR2DBCDatabaseContainerTest; +import static org.assertj.core.api.Assertions.assertThat; + +@Slf4j public class MSSQLR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest> { @Override @@ -20,4 +25,23 @@ protected String createR2DBCUrl() { protected MSSQLServerContainer createContainer() { return new MSSQLServerContainer<>(MSSQLServerTestImages.MSSQL_SERVER_IMAGE); } + + @Test + public void testGetR2DBCUrl(){ + //given + MSSQLServerContainer container = createContainer(); + container.start(); + + String expectedUrl = "r2dbc:sqlserver://" + container.getHost() + ":" + + container.getMappedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT) + + container.constructUrlParameters(";", ";"); + + //when + String r2dbcUrl = MSSQLR2DBCDatabaseContainer.getR2dbcUrl(container); + //then + assertThat(expectedUrl).isEqualTo(r2dbcUrl); + //clean-up + container.stop(); + } } + diff --git a/modules/mysql/src/test/java/org/testcontainers/containers/MySQLR2DBCDatabaseContainerTest.java b/modules/mysql/src/test/java/org/testcontainers/containers/MySQLR2DBCDatabaseContainerTest.java index 42a852ad1f1..3ab4bdcdeef 100644 --- a/modules/mysql/src/test/java/org/testcontainers/containers/MySQLR2DBCDatabaseContainerTest.java +++ b/modules/mysql/src/test/java/org/testcontainers/containers/MySQLR2DBCDatabaseContainerTest.java @@ -1,9 +1,12 @@ package org.testcontainers.containers; import io.r2dbc.spi.ConnectionFactoryOptions; +import org.junit.Test; import org.testcontainers.MySQLTestImages; import org.testcontainers.r2dbc.AbstractR2DBCDatabaseContainerTest; +import static org.assertj.core.api.Assertions.assertThat; + public class MySQLR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest> { @Override @@ -20,4 +23,24 @@ protected String createR2DBCUrl() { protected MySQLContainer createContainer() { return new MySQLContainer<>(MySQLTestImages.MYSQL_80_IMAGE); } + + @Test + public void testGetR2DBCUrl(){ + //given + MySQLContainer container = createContainer(); + container.start(); + + String expectedUrl = "r2dbc:mysql://" + container.getHost() + ":" + + container.getMappedPort(MySQLContainer.MYSQL_PORT) + "/" + + container.getDatabaseName() + container.constructUrlParameters("?", "&"); + + //when + String r2dbcUrl = MySQLR2DBCDatabaseContainer.getR2dbcUrl(container); + + //then + assertThat(expectedUrl).isEqualTo(r2dbcUrl); + + //clean-up + container.stop(); + } } diff --git a/modules/postgresql/src/test/java/org/testcontainers/containers/PostgreSQLR2DBCDatabaseContainerTest.java b/modules/postgresql/src/test/java/org/testcontainers/containers/PostgreSQLR2DBCDatabaseContainerTest.java index fb503bfd659..1859ac06233 100644 --- a/modules/postgresql/src/test/java/org/testcontainers/containers/PostgreSQLR2DBCDatabaseContainerTest.java +++ b/modules/postgresql/src/test/java/org/testcontainers/containers/PostgreSQLR2DBCDatabaseContainerTest.java @@ -1,9 +1,12 @@ package org.testcontainers.containers; import io.r2dbc.spi.ConnectionFactoryOptions; +import org.junit.Test; import org.testcontainers.PostgreSQLTestImages; import org.testcontainers.r2dbc.AbstractR2DBCDatabaseContainerTest; +import static org.assertj.core.api.Assertions.assertThat; + public class PostgreSQLR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest> { @Override @@ -27,4 +30,27 @@ protected ConnectionFactoryOptions getOptions(PostgreSQLContainer container) protected String createR2DBCUrl() { return "r2dbc:tc:postgresql:///db?TC_IMAGE_TAG=10-alpine"; } + + @Test + public void testGetR2DBCUrl(){ + //given + PostgreSQLContainer container = createContainer(); + container.start(); + + String expectedUrl = "r2dbc:postgresql://" + container.getHost() + ":" + + container.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT) + "/" + + container.getDatabaseName() + container.constructUrlParameters("?", "&"); + + + //when + String r2dbcUrl = PostgreSQLR2DBCDatabaseContainer.getR2dbcUrl(container); + + //then +// log.info("expectedUrl: {}", expectedUrl); +// log.info("createdUrl: {}", r2dbcUrl); + assertThat(expectedUrl).isEqualTo(r2dbcUrl); + + //clean-up + container.stop(); + } }