Skip to content

Commit 6079f9d

Browse files
author
raju.gupta
committed
Refactor query execution methods to use executeSelectOneQuery and executeQuery for consistency
1 parent 2681006 commit 6079f9d

File tree

20 files changed

+59
-97
lines changed

20 files changed

+59
-97
lines changed

modules/clickhouse/src/test/java/org/testcontainers/clickhouse/ClickHouseContainerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void testSimple() throws SQLException {
2626
) {
2727
clickhouse.start();
2828

29-
performSelectOneQuery(clickhouse);
29+
executeSelectOneQuery(clickhouse);
3030
}
3131
}
3232

@@ -42,7 +42,7 @@ void customCredentialsWithUrlParams() throws SQLException {
4242
) {
4343
clickhouse.start();
4444

45-
performQuery(
45+
executeQuery(
4646
clickhouse,
4747
"SELECT value FROM system.settings where name='max_result_rows'",
4848
resultSet -> {
@@ -62,7 +62,7 @@ void testNewAuth() throws SQLException {
6262
try (ClickHouseContainer clickhouse = new ClickHouseContainer(ClickhouseTestImages.CLICKHOUSE_24_12_IMAGE)) {
6363
clickhouse.start();
6464

65-
performSelectOneQuery(clickhouse);
65+
executeSelectOneQuery(clickhouse);
6666
}
6767
}
6868

modules/clickhouse/src/test/java/org/testcontainers/junit/clickhouse/SimpleClickhouseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void testSimple() throws SQLException {
1414
try (ClickHouseContainer clickhouse = new ClickHouseContainer(ClickhouseTestImages.CLICKHOUSE_IMAGE)) {
1515
clickhouse.start();
1616

17-
performSelectOneQuery(clickhouse);
17+
executeSelectOneQuery(clickhouse);
1818
}
1919
}
2020
}

modules/cockroachdb/src/test/java/org/testcontainers/cockroachdb/CockroachContainerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void testSimple() throws SQLException {
2525
// }
2626
) {
2727
cockroach.start();
28-
performSelectOneQuery(cockroach);
28+
executeSelectOneQuery(cockroach);
2929
}
3030
}
3131

@@ -72,7 +72,7 @@ void testWithUsernamePasswordDatabase() throws SQLException {
7272
) {
7373
cockroach.start();
7474

75-
performSelectOneQuery(cockroach);
75+
executeSelectOneQuery(cockroach);
7676

7777
String jdbcUrl = cockroach.getJdbcUrl();
7878
assertThat(jdbcUrl).contains("/" + "test_database");

modules/cratedb/src/test/java/org/testcontainers/junit/cratedb/SimpleCrateDBTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void testSimple() throws SQLException {
2626
) {
2727
cratedb.start();
2828

29-
performSelectOneQuery(cratedb);
29+
executeSelectOneQuery(cratedb);
3030
assertHasCorrectExposedAndLivenessCheckPorts(cratedb);
3131
}
3232
}
@@ -39,7 +39,7 @@ void testCommandOverride() throws SQLException {
3939
) {
4040
cratedb.start();
4141

42-
performQuery(
42+
executeQuery(
4343
cratedb,
4444
"select name from sys.cluster",
4545
resultSet -> {

modules/databend/src/test/java/org/testcontainers/databend/DatabendContainerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void testSimple() throws SQLException {
1515
) {
1616
databend.start();
1717

18-
performSelectOneQuery(databend);
18+
executeSelectOneQuery(databend);
1919
}
2020
}
2121

@@ -29,7 +29,7 @@ void customCredentialsWithUrlParams() throws SQLException {
2929
) {
3030
databend.start();
3131

32-
performSelectOneQuery(databend);
32+
executeSelectOneQuery(databend);
3333
}
3434
}
3535
}

modules/db2/src/test/java/org/testcontainers/db2/Db2ContainerTest.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.testcontainers.db2;
22

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.Db2TestImages;
65
import org.testcontainers.db.AbstractContainerDatabaseTest;
@@ -19,18 +18,8 @@ void testSimple() throws SQLException {
1918
) {
2019
db2.start();
2120

22-
performQuery(
23-
db2,
24-
"SELECT 1 FROM SYSIBM.SYSDUMMY1",
25-
resultSet -> {
26-
Assertions
27-
.assertThatNoException()
28-
.isThrownBy(() -> {
29-
int resultSetInt = resultSet.getInt(1);
30-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
31-
});
32-
}
33-
);
21+
executeSelectOneQuery(db2, "SELECT 1 FROM SYSIBM.SYSDUMMY1");
22+
3423
assertHasCorrectExposedAndLivenessCheckPorts(db2);
3524
}
3625
}
@@ -40,18 +29,8 @@ void testSimpleWithNewImage() throws SQLException {
4029
try (Db2Container db2 = new Db2Container("icr.io/db2_community/db2:11.5.8.0").acceptLicense()) {
4130
db2.start();
4231

43-
performQuery(
44-
db2,
45-
"SELECT 1 FROM SYSIBM.SYSDUMMY1",
46-
resultSet -> {
47-
Assertions
48-
.assertThatNoException()
49-
.isThrownBy(() -> {
50-
int resultSetInt = resultSet.getInt(1);
51-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
52-
});
53-
}
54-
);
32+
executeSelectOneQuery(db2, "SELECT 1 FROM SYSIBM.SYSDUMMY1");
33+
5534
assertHasCorrectExposedAndLivenessCheckPorts(db2);
5635
}
5736
}

modules/jdbc-test/src/main/java/org/testcontainers/db/AbstractContainerDatabaseTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public abstract class AbstractContainerDatabaseTest {
1717

18-
protected void performQuery(
18+
protected void executeQuery(
1919
final JdbcDatabaseContainer<?> container,
2020
final String sql,
2121
final Consumer<ResultSet> consumer
@@ -32,10 +32,15 @@ protected void performQuery(
3232
}
3333
}
3434

35-
protected void performSelectOneQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
36-
performQuery(
35+
protected void executeSelectOneQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
36+
executeSelectOneQuery(container, "SELECT 1");
37+
}
38+
39+
protected void executeSelectOneQuery(final JdbcDatabaseContainer<?> container, final String sql)
40+
throws SQLException {
41+
executeQuery(
3742
container,
38-
"SELECT 1",
43+
sql,
3944
resultSet -> {
4045
Assertions
4146
.assertThatNoException()
@@ -48,7 +53,7 @@ protected void performSelectOneQuery(final JdbcDatabaseContainer<?> container) t
4853
}
4954

5055
protected void performSelectFooBarQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
51-
performQuery(
56+
executeQuery(
5257
container,
5358
"SELECT foo FROM bar",
5459
resultSet -> {
@@ -69,7 +74,7 @@ protected void performSelectMaxConnectionsQuery(
6974
final JdbcDatabaseContainer<?> container,
7075
final String expectedMaxConnections
7176
) throws SQLException {
72-
performQuery(
77+
executeQuery(
7378
container,
7479
"SELECT current_setting('max_connections')",
7580
resultSet -> {
@@ -88,7 +93,7 @@ protected void performSelectMaxConnectionsQuery(
8893

8994
protected void performSelectVersionQuery(final JdbcDatabaseContainer<?> container, final String expectedVersion)
9095
throws SQLException {
91-
performQuery(
96+
executeQuery(
9297
container,
9398
"SELECT VERSION()",
9499
resultSet -> {

modules/mariadb/src/test/java/org/testcontainers/mariadb/MariaDBContainerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void testSimple() throws SQLException {
2929
) {
3030
mariadb.start();
3131

32-
performSelectOneQuery(mariadb);
32+
executeSelectOneQuery(mariadb);
3333
}
3434
}
3535

@@ -42,7 +42,7 @@ void testSpecificVersion() throws SQLException {
4242
) {
4343
mariadbOldVersion.start();
4444

45-
performSelectOneQuery(mariadbOldVersion);
45+
executeSelectOneQuery(mariadbOldVersion);
4646
}
4747
}
4848

@@ -69,7 +69,7 @@ void testMariaDBWithCommandOverride() throws SQLException {
6969
.withCommand("mysqld --auto_increment_increment=10")
7070
) {
7171
mariadbCustomConfig.start();
72-
performQuery(
72+
executeQuery(
7373
mariadbCustomConfig,
7474
"show variables like 'auto_increment_increment'",
7575
resultSet -> {
@@ -140,12 +140,12 @@ void testEmptyPasswordWithRootUser() throws SQLException {
140140
try (MariaDBContainer mysql = new MariaDBContainer("mariadb:11.2.4").withUsername("root")) {
141141
mysql.start();
142142

143-
performSelectOneQuery(mysql);
143+
executeSelectOneQuery(mysql);
144144
}
145145
}
146146

147147
private void assertThatCustomIniFileWasUsed(MariaDBContainer mariadb) throws SQLException {
148-
performQuery(
148+
executeQuery(
149149
mariadb,
150150
"SELECT @@GLOBAL.innodb_max_undo_log_size",
151151
resultSet -> {

modules/mssqlserver/src/test/java/org/testcontainers/mssqlserver/MSSQLServerContainerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void testSimple() throws SQLException {
2626
) {
2727
mssqlServer.start();
2828

29-
performSelectOneQuery(mssqlServer);
29+
executeSelectOneQuery(mssqlServer);
3030

3131
assertHasCorrectExposedAndLivenessCheckPorts(mssqlServer);
3232
}
@@ -77,7 +77,7 @@ void testSqlServerConnection() throws SQLException {
7777
) {
7878
mssqlServerContainer.start();
7979

80-
performSelectOneQuery(mssqlServerContainer);
80+
executeSelectOneQuery(mssqlServerContainer);
8181
}
8282
}
8383

modules/mysql/src/test/java/org/testcontainers/mysql/MySQLContainerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void testSimple() throws SQLException {
4242
) {
4343
mysql.start();
4444

45-
performSelectOneQuery(mysql);
45+
executeSelectOneQuery(mysql);
4646

4747
assertHasCorrectExposedAndLivenessCheckPorts(mysql);
4848
}
@@ -81,7 +81,7 @@ void testCommandOverride() throws SQLException {
8181
) {
8282
mysqlCustomConfig.start();
8383

84-
performQuery(
84+
executeQuery(
8585
mysqlCustomConfig,
8686
"show variables like 'auto_increment_increment'",
8787
resultSet -> {
@@ -138,7 +138,7 @@ void testEmptyPasswordWithRootUser() throws SQLException {
138138
) {
139139
mysql.start();
140140

141-
performSelectOneQuery(mysql);
141+
executeSelectOneQuery(mysql);
142142
}
143143
}
144144

@@ -261,7 +261,7 @@ void testCustom() throws SQLException {
261261
) {
262262
mysql.start();
263263

264-
performSelectOneQuery(mysql);
264+
executeSelectOneQuery(mysql);
265265
}
266266
}
267267

@@ -271,7 +271,7 @@ private void assertHasCorrectExposedAndLivenessCheckPorts(MySQLContainer mysql)
271271
}
272272

273273
private void assertThatCustomIniFileWasUsed(MySQLContainer mysql) throws SQLException {
274-
performQuery(
274+
executeQuery(
275275
mysql,
276276
"SELECT @@GLOBAL.innodb_max_undo_log_size",
277277
resultSet -> {

0 commit comments

Comments
 (0)