From e61d52f0975b8082e43a2c3230486a3079052eeb Mon Sep 17 00:00:00 2001 From: loophyun Date: Wed, 4 Dec 2024 21:59:07 +0900 Subject: [PATCH] Add test getR2dbcUrl on MariaDB, MySQL, PostgreSQL, MsSQL --- .../MariaDBR2DBCDatabaseContainerTest.java | 26 +++++++++++++++++++ .../MSSQLR2DBCDatabaseContainerTest.java | 24 +++++++++++++++++ .../MySQLR2DBCDatabaseContainerTest.java | 26 +++++++++++++++++++ .../PostgreSQLR2DBCDatabaseContainerTest.java | 26 +++++++++++++++++++ 4 files changed, 102 insertions(+) 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..33d7b1c1c20 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,27 @@ 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..722f33d437b 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,12 @@ package org.testcontainers.containers; import io.r2dbc.spi.ConnectionFactoryOptions; +import org.junit.Test; import org.testcontainers.MSSQLServerTestImages; import org.testcontainers.r2dbc.AbstractR2DBCDatabaseContainerTest; +import static org.assertj.core.api.Assertions.assertThat; + public class MSSQLR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest> { @Override @@ -20,4 +23,25 @@ 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..3eb28541542 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,27 @@ 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..0af63a30f5d 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 + assertThat(expectedUrl).isEqualTo(r2dbcUrl); + //clean-up + container.stop(); + } }