Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public JdbcDatabaseContainer(final DockerImageName dockerImageName) {
}

/**
* @return the name of the actual JDBC driver to use
* @return R2DBC driver name (e.g., "postgresql", "mysql", etc.)
*/
public abstract String getDriverClassName();

Expand All @@ -77,8 +77,20 @@ public JdbcDatabaseContainer(final DockerImageName dockerImageName) {
public abstract String getJdbcUrl();

/**
* @return the database name
* @return an R2DBC-compliant connection URL.
* Example: r2dbc:postgresql://user:password@localhost:5432/dbname
*/
public String getR2dbcUrl(){
String driver = getR2dbcDriverName();
String user = getUsername();
String pw = getPassword();
String host = getHost();
Integer port = getFirstMappedPort(getExposedPorts().get(0));
String db = getDatabaseName();


return String.format("r2dbc:%s://%s:%s@%s:%d/%s", driver, user, pw, host, port, db);
}
public String getDatabaseName() {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public JdbcDatabaseContainer newInstance(String tag) {
public JdbcDatabaseContainer newInstance(ConnectionUrl connectionUrl) {
return newInstanceFromConnectionUrl(connectionUrl, USER_PARAM, PASSWORD_PARAM);
}
@Override
public String getR2dbcDriverName() {
return "postgresql";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ protected ConnectionFactoryOptions getOptions(PostgreSQLContainer<?> container)
);
// }
// spotless:on

System.out.println("Generated R2DBC URL: " + container.getR2dbcUrl());
assertTrue(container.getR2dbcUrl().startsWith("r2dbc:postgresql://"));
return options;
}

Expand Down