Skip to content

Commit c8f91bf

Browse files
author
raju.gupta
committed
Refactor query execution to use performSelectOneQuery method for consistency
1 parent ebd0501 commit c8f91bf

File tree

17 files changed

+55
-324
lines changed

17 files changed

+55
-324
lines changed

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

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

29-
performQuery(
30-
clickhouse,
31-
"SELECT 1",
32-
resultSet -> {
33-
Assertions
34-
.assertThatNoException()
35-
.isThrownBy(() -> {
36-
int resultSetInt = resultSet.getInt(1);
37-
assertThat(resultSetInt).isEqualTo(1);
38-
});
39-
}
40-
);
29+
performSelectOneQuery(clickhouse);
4130
}
4231
}
4332

@@ -73,18 +62,7 @@ void testNewAuth() throws SQLException {
7362
try (ClickHouseContainer clickhouse = new ClickHouseContainer(ClickhouseTestImages.CLICKHOUSE_24_12_IMAGE)) {
7463
clickhouse.start();
7564

76-
performQuery(
77-
clickhouse,
78-
"SELECT 1",
79-
resultSet -> {
80-
Assertions
81-
.assertThatNoException()
82-
.isThrownBy(() -> {
83-
int resultSetInt = resultSet.getInt(1);
84-
assertThat(resultSetInt).isEqualTo(1);
85-
});
86-
}
87-
);
65+
performSelectOneQuery(clickhouse);
8866
}
8967
}
9068

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
package org.testcontainers.junit.clickhouse;
22

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.ClickhouseTestImages;
65
import org.testcontainers.containers.ClickHouseContainer;
76
import org.testcontainers.db.AbstractContainerDatabaseTest;
87

98
import java.sql.SQLException;
109

11-
import static org.assertj.core.api.Assertions.assertThat;
12-
1310
class SimpleClickhouseTest extends AbstractContainerDatabaseTest {
1411

1512
@Test
16-
public void testSimple() throws SQLException {
13+
void testSimple() throws SQLException {
1714
try (ClickHouseContainer clickhouse = new ClickHouseContainer(ClickhouseTestImages.CLICKHOUSE_IMAGE)) {
1815
clickhouse.start();
1916

20-
performQuery(
21-
clickhouse,
22-
"SELECT 1",
23-
resultSet -> {
24-
Assertions
25-
.assertThatNoException()
26-
.isThrownBy(() -> {
27-
int resultSetInt = resultSet.getInt(1);
28-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
29-
});
30-
}
31-
);
17+
performSelectOneQuery(clickhouse);
3218
}
3319
}
3420
}

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@ void testSimple() throws SQLException {
2626
// }
2727
) {
2828
cockroach.start();
29-
30-
performQuery(
31-
cockroach,
32-
"SELECT 1",
33-
resultSet -> {
34-
Assertions
35-
.assertThatNoException()
36-
.isThrownBy(() -> {
37-
int resultSetInt = resultSet.getInt(1);
38-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
39-
});
40-
}
41-
);
29+
performSelectOneQuery(cockroach);
4230
}
4331
}
4432

@@ -98,18 +86,7 @@ void testWithUsernamePasswordDatabase() throws SQLException {
9886
) {
9987
cockroach.start();
10088

101-
performQuery(
102-
cockroach,
103-
"SELECT 1",
104-
resultSet -> {
105-
Assertions
106-
.assertThatNoException()
107-
.isThrownBy(() -> {
108-
int resultSetInt = resultSet.getInt(1);
109-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
110-
});
111-
}
112-
);
89+
performSelectOneQuery(cockroach);
11390

11491
String jdbcUrl = cockroach.getJdbcUrl();
11592
assertThat(jdbcUrl).contains("/" + "test_database");

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

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

29-
performQuery(
30-
cratedb,
31-
"SELECT 1",
32-
resultSet -> {
33-
Assertions
34-
.assertThatNoException()
35-
.isThrownBy(() -> {
36-
int resultSetInt = resultSet.getInt(1);
37-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
38-
});
39-
}
40-
);
29+
performSelectOneQuery(cratedb);
4130
assertHasCorrectExposedAndLivenessCheckPorts(cratedb);
4231
}
4332
}
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package org.testcontainers.databend;
22

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.db.AbstractContainerDatabaseTest;
65

76
import java.sql.SQLException;
87

9-
import static org.assertj.core.api.Assertions.assertThat;
10-
118
class DatabendContainerTest extends AbstractContainerDatabaseTest {
129

1310
@Test
@@ -18,18 +15,7 @@ void testSimple() throws SQLException {
1815
) {
1916
databend.start();
2017

21-
performQuery(
22-
databend,
23-
"SELECT 1",
24-
resultSet -> {
25-
Assertions
26-
.assertThatNoException()
27-
.isThrownBy(() -> {
28-
int resultSetInt = resultSet.getInt(1);
29-
assertThat(resultSetInt).isEqualTo(1);
30-
});
31-
}
32-
);
18+
performSelectOneQuery(databend);
3319
}
3420
}
3521

@@ -43,18 +29,7 @@ void customCredentialsWithUrlParams() throws SQLException {
4329
) {
4430
databend.start();
4531

46-
performQuery(
47-
databend,
48-
"SELECT 1;",
49-
resultSet -> {
50-
Assertions
51-
.assertThatNoException()
52-
.isThrownBy(() -> {
53-
int resultSetInt = resultSet.getInt(1);
54-
assertThat(resultSetInt).isEqualTo(1);
55-
});
56-
}
57-
);
32+
performSelectOneQuery(databend);
5833
}
5934
}
6035
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.zaxxer.hikari.HikariConfig;
44
import com.zaxxer.hikari.HikariDataSource;
5+
import org.assertj.core.api.Assertions;
56
import org.testcontainers.containers.JdbcDatabaseContainer;
67

78
import java.sql.Connection;
@@ -31,6 +32,21 @@ protected void performQuery(
3132
}
3233
}
3334

35+
protected void performSelectOneQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
36+
performQuery(
37+
container,
38+
"SELECT 1",
39+
resultSet -> {
40+
Assertions
41+
.assertThatNoException()
42+
.isThrownBy(() -> {
43+
int resultSetInt = resultSet.getInt(1);
44+
Assertions.assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
45+
});
46+
}
47+
);
48+
}
49+
3450
protected DataSource getDataSource(final JdbcDatabaseContainer<?> container) {
3551
HikariConfig hikariConfig = new HikariConfig();
3652
hikariConfig.setJdbcUrl(container.getJdbcUrl());

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

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

32-
performQuery(
33-
mariadb,
34-
"SELECT 1",
35-
resultSet -> {
36-
Assertions
37-
.assertThatNoException()
38-
.isThrownBy(() -> {
39-
int resultSetInt = resultSet.getInt(1);
40-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
41-
});
42-
}
43-
);
32+
performSelectOneQuery(mariadb);
4433
}
4534
}
4635

@@ -164,18 +153,7 @@ void testEmptyPasswordWithRootUser() throws SQLException {
164153
try (MariaDBContainer mysql = new MariaDBContainer("mariadb:11.2.4").withUsername("root")) {
165154
mysql.start();
166155

167-
performQuery(
168-
mysql,
169-
"SELECT 1",
170-
resultSet -> {
171-
Assertions
172-
.assertThatNoException()
173-
.isThrownBy(() -> {
174-
int resultSetInt = resultSet.getInt(1);
175-
assertThat(resultSetInt).isEqualTo(1);
176-
});
177-
}
178-
);
156+
performSelectOneQuery(mysql);
179157
}
180158
}
181159

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

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

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.MSSQLServerTestImages;
65
import org.testcontainers.db.AbstractContainerDatabaseTest;
@@ -26,18 +25,9 @@ void testSimple() throws SQLException {
2625
// }
2726
) {
2827
mssqlServer.start();
29-
performQuery(
30-
mssqlServer,
31-
"SELECT 1",
32-
resultSet -> {
33-
Assertions
34-
.assertThatNoException()
35-
.isThrownBy(() -> {
36-
int resultSetInt = resultSet.getInt(1);
37-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
38-
});
39-
}
40-
);
28+
29+
performSelectOneQuery(mssqlServer);
30+
4131
assertHasCorrectExposedAndLivenessCheckPorts(mssqlServer);
4232
}
4333
}
@@ -87,18 +77,7 @@ void testSqlServerConnection() throws SQLException {
8777
) {
8878
mssqlServerContainer.start();
8979

90-
performQuery(
91-
mssqlServerContainer,
92-
mssqlServerContainer.getTestQueryString(),
93-
resultSet -> {
94-
Assertions
95-
.assertThatNoException()
96-
.isThrownBy(() -> {
97-
int resultSetInt = resultSet.getInt(1);
98-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
99-
});
100-
}
101-
);
80+
performSelectOneQuery(mssqlServerContainer);
10281
}
10382
}
10483

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

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

45-
performQuery(
46-
mysql,
47-
"SELECT 1",
48-
resultSet -> {
49-
Assertions
50-
.assertThatNoException()
51-
.isThrownBy(() -> {
52-
int resultSetInt = resultSet.getInt(1);
53-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
54-
});
55-
}
56-
);
45+
performSelectOneQuery(mysql);
46+
5747
assertHasCorrectExposedAndLivenessCheckPorts(mysql);
5848
}
5949
}
@@ -174,18 +164,7 @@ void testEmptyPasswordWithRootUser() throws SQLException {
174164
) {
175165
mysql.start();
176166

177-
performQuery(
178-
mysql,
179-
"SELECT 1",
180-
resultSet -> {
181-
Assertions
182-
.assertThatNoException()
183-
.isThrownBy(() -> {
184-
int resultSetInt = resultSet.getInt(1);
185-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
186-
});
187-
}
188-
);
167+
performSelectOneQuery(mysql);
189168
}
190169
}
191170

@@ -308,18 +287,7 @@ void testCustom() throws SQLException {
308287
) {
309288
mysql.start();
310289

311-
performQuery(
312-
mysql,
313-
"SELECT 1",
314-
resultSet -> {
315-
Assertions
316-
.assertThatNoException()
317-
.isThrownBy(() -> {
318-
int resultSetInt = resultSet.getInt(1);
319-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
320-
});
321-
}
322-
);
290+
performSelectOneQuery(mysql);
323291
}
324292
}
325293

modules/oceanbase/src/test/java/org/testcontainers/oceanbase/SimpleOceanBaseCETest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,8 @@ void testSimple() throws SQLException {
2222
) {
2323
oceanbase.start();
2424

25-
performQuery(
26-
oceanbase,
27-
"SELECT 1",
28-
resultSet -> {
29-
Assertions
30-
.assertThatNoException()
31-
.isThrownBy(() -> {
32-
int resultSetInt = resultSet.getInt(1);
33-
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
34-
});
35-
}
36-
);
25+
performSelectOneQuery(oceanbase);
26+
3727
assertHasCorrectExposedAndLivenessCheckPorts(oceanbase);
3828
}
3929
}

0 commit comments

Comments
 (0)