Skip to content

Commit

Permalink
Add test getR2dbcUrl on MariaDB, MySQL, PostgreSQL, MsSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
DHKIM-0511 committed Dec 4, 2024
1 parent 1d16803 commit e61d52f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<MariaDBContainer<?>> {

@Override
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<MSSQLServerContainer<?>> {

@Override
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<MySQLContainer<?>> {

@Override
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<PostgreSQLContainer<?>> {

@Override
Expand All @@ -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();
}
}

0 comments on commit e61d52f

Please sign in to comment.