Skip to content

Commit 4555238

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

File tree

9 files changed

+28
-139
lines changed

9 files changed

+28
-139
lines changed

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

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

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.CockroachDBTestImages;
65
import org.testcontainers.db.AbstractContainerDatabaseTest;
@@ -38,20 +37,7 @@ void testExplicitInitScript() throws SQLException {
3837
) { // CockroachDB is expected to be compatible with Postgres
3938
cockroach.start();
4039

41-
performQuery(
42-
cockroach,
43-
"SELECT foo FROM bar",
44-
resultSet -> {
45-
Assertions
46-
.assertThatNoException()
47-
.isThrownBy(() -> {
48-
String firstColumnValue = resultSet.getString(1);
49-
assertThat(firstColumnValue)
50-
.as("Value from init script should equal real value")
51-
.isEqualTo("hello world");
52-
});
53-
}
54-
);
40+
performSelectFooBarQuery(cockroach);
5541
}
5642
}
5743

@@ -126,20 +112,7 @@ void testInitializationScript() throws SQLException {
126112
) { // CockroachDB is expected to be compatible with Postgres
127113
cockroach.start();
128114

129-
performQuery(
130-
cockroach,
131-
"SELECT foo FROM bar",
132-
resultSet -> {
133-
Assertions
134-
.assertThatNoException()
135-
.isThrownBy(() -> {
136-
String firstColumnValue = resultSet.getString(1);
137-
assertThat(firstColumnValue)
138-
.as("Value from init script should equal real value")
139-
.isEqualTo("hello world");
140-
});
141-
}
142-
);
115+
performSelectFooBarQuery(cockroach);
143116
}
144117
}
145118
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,7 @@ void testExplicitInitScript() throws SQLException {
6262
) {
6363
cratedb.start();
6464

65-
performQuery(
66-
cratedb,
67-
"SELECT foo FROM bar",
68-
resultSet -> {
69-
Assertions
70-
.assertThatNoException()
71-
.isThrownBy(() -> {
72-
String firstColumnValue = resultSet.getString(1);
73-
assertThat(firstColumnValue)
74-
.as("Value from init script should equal real value")
75-
.isEqualTo("hello world");
76-
});
77-
}
78-
);
65+
performSelectFooBarQuery(cratedb);
7966
}
8067
}
8168

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ protected void performSelectOneQuery(final JdbcDatabaseContainer<?> container) t
4747
);
4848
}
4949

50+
protected void performSelectFooBarQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
51+
performQuery(
52+
container,
53+
"SELECT foo FROM bar",
54+
resultSet -> {
55+
Assertions
56+
.assertThatNoException()
57+
.isThrownBy(() -> {
58+
String firstColumnValue = resultSet.getString(1);
59+
Assertions
60+
.assertThat(firstColumnValue)
61+
.as("Value from init script should equal real value")
62+
.isEqualTo("hello world");
63+
});
64+
}
65+
);
66+
}
67+
5068
protected DataSource getDataSource(final JdbcDatabaseContainer<?> container) {
5169
HikariConfig hikariConfig = new HikariConfig();
5270
hikariConfig.setJdbcUrl(container.getJdbcUrl());

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,7 @@ void testExplicitInitScript() throws SQLException {
120120
) {
121121
container.start();
122122

123-
performQuery(
124-
container,
125-
"SELECT foo FROM bar",
126-
resultSet -> {
127-
Assertions
128-
.assertThatNoException()
129-
.isThrownBy(() -> {
130-
String firstColumnValue = resultSet.getString(1);
131-
assertThat(firstColumnValue)
132-
.as("Value from init script should equal real value")
133-
.isEqualTo("hello world");
134-
});
135-
}
136-
);
123+
performSelectFooBarQuery(container);
137124
}
138125
}
139126

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.testcontainers.oceanbase;
22

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

@@ -33,20 +32,7 @@ void testExplicitInitScript() throws SQLException {
3332
try (OceanBaseCEContainer oceanbase = new OceanBaseCEContainer(IMAGE).withInitScript("init.sql")) {
3433
oceanbase.start();
3534

36-
performQuery(
37-
oceanbase,
38-
"SELECT foo FROM bar",
39-
resultSet -> {
40-
Assertions
41-
.assertThatNoException()
42-
.isThrownBy(() -> {
43-
String firstColumnValue = resultSet.getString(1);
44-
assertThat(firstColumnValue)
45-
.as("Value from init script should equal real value")
46-
.isEqualTo("hello world");
47-
});
48-
}
49-
);
35+
performSelectFooBarQuery(oceanbase);
5036
}
5137
}
5238

modules/postgresql/src/test/java/org/testcontainers/containers/TimescaleDBContainerTest.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ void testSimple() throws SQLException {
1616
postgres.start();
1717

1818
performSelectOneQuery(postgres);
19-
20-
performQuery(
21-
postgres,
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-
);
3219
}
3320
}
3421

@@ -90,20 +77,7 @@ void testExplicitInitScript() throws SQLException {
9077
) {
9178
postgres.start();
9279

93-
performQuery(
94-
postgres,
95-
"SELECT foo FROM bar",
96-
resultSet -> {
97-
Assertions
98-
.assertThatNoException()
99-
.isThrownBy(() -> {
100-
String firstColumnValue = resultSet.getString(1);
101-
assertThat(firstColumnValue)
102-
.as("Value from init script should equal real value")
103-
.isEqualTo("hello world");
104-
});
105-
}
106-
);
80+
performSelectFooBarQuery(postgres);
10781
}
10882
}
10983
}

modules/postgresql/src/test/java/org/testcontainers/postgresql/PostgreSQLContainerTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,7 @@ void testExplicitInitScript() throws SQLException {
9797
) {
9898
postgres.start();
9999

100-
performQuery(
101-
postgres,
102-
"SELECT foo FROM bar",
103-
resultSet -> {
104-
Assertions
105-
.assertThatNoException()
106-
.isThrownBy(() -> {
107-
String firstColumnValue = resultSet.getString(1);
108-
assertThat(firstColumnValue)
109-
.as("Value from init script should equal real value")
110-
.isEqualTo("hello world");
111-
});
112-
}
113-
);
100+
performSelectFooBarQuery(postgres);
114101
}
115102
}
116103

modules/tidb/src/test/java/org/testcontainers/tidb/TiDBContainerTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.testcontainers.tidb;
22

3-
import org.assertj.core.api.Assertions;
43
import org.junit.jupiter.api.Test;
54
import org.testcontainers.TiDBTestImages;
65
import org.testcontainers.db.AbstractContainerDatabaseTest;
@@ -32,18 +31,7 @@ void testExplicitInitScript() throws SQLException {
3231
) { // TiDB is expected to be compatible with MySQL
3332
tidb.start();
3433

35-
performQuery(
36-
tidb,
37-
"SELECT foo FROM bar",
38-
resultSet -> {
39-
Assertions
40-
.assertThatNoException()
41-
.isThrownBy(() -> {
42-
String firstColumnValue = resultSet.getString(1);
43-
assertThat(firstColumnValue).isEqualTo("hello world");
44-
});
45-
}
46-
);
34+
performSelectFooBarQuery(tidb);
4735
}
4836
}
4937

modules/yugabytedb/src/test/java/org/testcontainers/junit/yugabytedb/YugabyteDBYSQLTest.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,8 @@ void testWithCustomRole() throws SQLException {
9595
.withUsername("yugabyte")
9696
) {
9797
ysqlContainer.start();
98-
performQuery(
99-
ysqlContainer,
100-
"SELECT 1",
101-
resultSet -> {
102-
Assertions
103-
.assertThatNoException()
104-
.isThrownBy(() -> {
105-
assertThat(resultSet.getInt(1))
106-
.as("A sample test query with a custom role succeeds")
107-
.isEqualTo(1);
108-
});
109-
}
110-
);
98+
99+
performSelectOneQuery(ysqlContainer);
111100
}
112101
}
113102

0 commit comments

Comments
 (0)