Skip to content

Commit 7947d42

Browse files
committed
Update to org.testcontainers:jdbc
Apply deprecation of ambiguous constructors
1 parent 454df5e commit 7947d42

File tree

8 files changed

+136
-38
lines changed

8 files changed

+136
-38
lines changed

CHANGES.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
Version History
22
===============
33

4+
1.0.5
5+
-----
6+
- Updated org.testcontainers:jdbc to 1.15.1
7+
- Deprecated no-arg constructor of `FirebirdContainer` (see also <https://github.com/testcontainers/testcontainers-java/pull/2839>) \
8+
It is recommended to switch to using an explicit image name and version
9+
- Added constructor `FirebirdContainer(DockerImageName)`. \
10+
Use with `DockerImageName.parse(FirebirdContainer.IMAGE).withTag("3.0.7")` to get an explicit version.
11+
412
1.0.4
513
-----
614

715
- Update org.testcontainers:jdbc to 1.14.3
8-
- Move static config in modules to constructor (see also https://github.com/testcontainers/testcontainers-java/pull/2473)
9-
- Add ContainerState#getHost as a replacement for getContainerIpAddress (see also https://github.com/testcontainers/testcontainers-java/pull/2742)
10-
- Added additional url params in JdbcDatabaseContainer (see also https://github.com/testcontainers/testcontainers-java/issues/1802)
16+
- Move static config in modules to constructor (see also <https://github.com/testcontainers/testcontainers-java/pull/2473>)
17+
- Add `ContainerState#getHost` as a replacement for `getContainerIpAddress` (see also <https://github.com/testcontainers/testcontainers-java/pull/2742>)
18+
- Added additional url params in `JdbcDatabaseContainer` (see also <https://github.com/testcontainers/testcontainers-java/issues/1802>)
1119
- For compatibility with Jaybird 4, when legacy client auth is enabled and `authPlugins` URL param has not been explicitly added, add URL param `authPlugins` with value `Srp256,Srp,Legacy_auth`
1220
- Updated default image version to Firebird 3.0.5.
1321

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ The container defines several `withXXX` methods for configuration.
5858
Important standard options are:
5959

6060
- `withUsername(String)` - Sets the username to create (defaults to `test`); if
61-
other than `sysdba` (case insensitive), sets docker environment variable
61+
other than `sysdba` (case-insensitive), sets docker environment variable
6262
`FIREBIRD_USER`
6363
- `withPassword(String)` - Sets the password of the user (defaults to `test`);
64-
if `withUsername` is other than `sysdba` (case insensitive), sets the docker
64+
if `withUsername` is other than `sysdba` (case-insensitive), sets the docker
6565
environment variable `FIREBIRD_PASSWORD`, otherwise `ISC_PASSWORD`
6666
- `withDatabaseName(String)` - Sets the database name (defaults to `test`);
6767
sets docker environment variable `FIREBIRD_DATABASE`
@@ -78,40 +78,46 @@ this property is not explicitly set through `withUrlParam`
7878
- `withTimeZone(String)` - Sets the time zone (defaults to JVM default time
7979
zone); sets docker environment variable `TZ` to the specified value
8080
- `withSysdbaPassword(String)` - Sets the SYSDBA password, but if
81-
`withUsername(String)` is set to `sysdba` (case insensitive), this property is
81+
`withUsername(String)` is set to `sysdba` (case-insensitive), this property is
8282
ignored and the value of `withPassword` is used instead; sets docker
8383
environment variable `ISC_PASSWORD` to the specified value
8484

8585
Example of use:
8686

8787
```java
88+
import org.firebirdsql.testcontainers.FirebirdContainer;
89+
import org.testcontainers.utility.DockerImageName;
90+
8891
/**
8992
* Simple test demonstrating use of {@code @Rule}.
9093
*/
9194
public class ExampleRuleTest {
9295

93-
@Rule
94-
public final FirebirdContainer container = new FirebirdContainer()
95-
.withUsername("testuser")
96-
.withPassword("testpassword");
97-
98-
@Test
99-
public void canConnectToContainer() throws Exception {
100-
try (Connection connection = DriverManager
101-
.getConnection(container.getJdbcUrl(), container.getUsername(), container.getPassword());
102-
Statement stmt = connection.createStatement();
103-
ResultSet rs = stmt.executeQuery("select CURRENT_USER from RDB$DATABASE")) {
104-
assertTrue("has row", rs.next());
105-
assertEquals("user name", "TESTUSER", rs.getString(1));
106-
}
96+
private static final DockerImageName IMAGE =
97+
DockerImageName.parse(FirebirdContainer.IMAGE).withTag("3.0.7");
98+
99+
@Rule
100+
public final FirebirdContainer<?> container = new FirebirdContainer<?>(IMAGE)
101+
.withUsername("testuser")
102+
.withPassword("testpassword");
103+
104+
@Test
105+
public void canConnectToContainer() throws Exception {
106+
try (Connection connection = DriverManager
107+
.getConnection(container.getJdbcUrl(), container.getUsername(), container.getPassword());
108+
Statement stmt = connection.createStatement();
109+
ResultSet rs = stmt.executeQuery("select CURRENT_USER from RDB$DATABASE")) {
110+
assertTrue("has row", rs.next());
111+
assertEquals("user name", "TESTUSER", rs.getString(1));
107112
}
113+
}
108114
}
109115
```
110116

111117
### Testcontainers URL
112118

113-
The testcontainers URL defines the container and connects to it. As long as there
114-
are active connections, the container will stay up.
119+
The testcontainers URL defines the container and connects to it. As long as
120+
there are active connections, the container will stay up.
115121

116122
For Firebird the URL format is:
117123

@@ -120,7 +126,8 @@ For Firebird the URL format is:
120126

121127
Where:
122128

123-
- `<image-tag>` (_optional_) is the tag of the docker image to use
129+
- `<image-tag>` (_optional, but recommended_) is the tag of the docker image to
130+
use, otherwise the default is used (which might change between versions)
124131
- `<databasename>` (_optional_) is the name of the database (defaults to `test`)
125132
- `<property>` is a connection property (Jaybird properties **and** testcontainers properties are possible) \
126133
Of special note are the properties:

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.firebirdsql</groupId>
66
<artifactId>firebird-testcontainers-java</artifactId>
7-
<version>1.0.5-SNAPSHOT</version>
7+
<version>1.1.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>firebird-testcontainers-java</name>
@@ -37,9 +37,9 @@
3737
<maven.compiler.source>1.8</maven.compiler.source>
3838
<maven.compiler.target>1.8</maven.compiler.target>
3939

40-
<testcontainers.version>1.14.3</testcontainers.version>
40+
<testcontainers.version>1.15.1</testcontainers.version>
4141
<lombok.version>1.18.12</lombok.version>
42-
<jaybird.version>4.0.0.java8</jaybird.version>
42+
<jaybird.version>4.0.2.java8</jaybird.version>
4343
</properties>
4444

4545
<dependencies>

src/main/java/org/firebirdsql/testcontainers/FirebirdContainer.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class FirebirdContainer<SELF extends FirebirdContainer<SELF>> extends Jdb
1414
public static final String NAME = "firebird";
1515
public static final String ALTERNATE_NAME = "firebirdsql";
1616
public static final String IMAGE = "jacobalberty/firebird";
17+
static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE);
1718
public static final String DEFAULT_TAG = "3.0.5";
1819

1920
public static final Integer FIREBIRD_PORT = 3050;
@@ -29,12 +30,35 @@ public class FirebirdContainer<SELF extends FirebirdContainer<SELF>> extends Jdb
2930
private boolean enableWireCrypt;
3031
private String sysdbaPassword;
3132

33+
/**
34+
* Creates a Firebird container with the default image ({@link #IMAGE} and {@link #DEFAULT_TAG}).
35+
*
36+
* @deprecated Use explicit image using {@link #FirebirdContainer(DockerImageName)}
37+
*/
38+
@Deprecated
3239
public FirebirdContainer() {
33-
this(IMAGE + ":" + DEFAULT_TAG);
40+
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
3441
}
3542

43+
/**
44+
* Creates a Firebird container with an image name (e.g. {@code "jacobalberty/firebird:3.0.7"}.
45+
*
46+
* @param dockerImageName Image name
47+
*/
3648
public FirebirdContainer(String dockerImageName) {
49+
this(DockerImageName.parse(dockerImageName));
50+
}
51+
52+
/**
53+
* Creates a Firebird container with a parsed image name.
54+
*
55+
* @param dockerImageName Parse image name
56+
*/
57+
public FirebirdContainer(DockerImageName dockerImageName) {
3758
super(dockerImageName);
59+
60+
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
61+
3862
addExposedPort(FIREBIRD_PORT);
3963
}
4064

src/main/java/org/firebirdsql/testcontainers/FirebirdContainerProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.testcontainers.containers.JdbcDatabaseContainer;
44
import org.testcontainers.containers.JdbcDatabaseContainerProvider;
55
import org.testcontainers.jdbc.ConnectionUrl;
6+
import org.testcontainers.utility.DockerImageName;
67

78
public class FirebirdContainerProvider extends JdbcDatabaseContainerProvider {
89

@@ -21,7 +22,7 @@ public JdbcDatabaseContainer newInstance() {
2122

2223
@Override
2324
public JdbcDatabaseContainer newInstance(String tag) {
24-
return new FirebirdContainer(FirebirdContainer.IMAGE + ":" + tag);
25+
return new FirebirdContainer(DockerImageName.parse(FirebirdContainer.IMAGE).withTag(tag));
2526
}
2627

2728
@Override

src/test/java/org/firebirdsql/testcontainers/FirebirdContainerTest.java

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.sql.*;
88

99
import static org.firebirdsql.testcontainers.FirebirdContainer.FIREBIRD_PORT;
10-
import static org.firebirdsql.testcontainers.FirebirdContainer.IMAGE;
10+
import static org.firebirdsql.testcontainers.FirebirdTestImages.FIREBIRD_259_SC_IMAGE;
11+
import static org.firebirdsql.testcontainers.FirebirdTestImages.FIREBIRD_259_SS_IMAGE;
12+
import static org.firebirdsql.testcontainers.FirebirdTestImages.FIREBIRD_TEST_IMAGE;
1113
import static org.hamcrest.CoreMatchers.allOf;
1214
import static org.hamcrest.CoreMatchers.containsString;
1315
import static org.hamcrest.MatcherAssert.assertThat;
@@ -20,7 +22,22 @@ public class FirebirdContainerTest {
2022
@Test
2123
public void testWithSysdbaPassword() throws SQLException {
2224
final String sysdbaPassword = "sysdbapassword";
23-
try (FirebirdContainer<?> container = new FirebirdContainer<>().withSysdbaPassword(sysdbaPassword)) {
25+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
26+
.withSysdbaPassword(sysdbaPassword)) {
27+
container.start();
28+
29+
try (Connection connection = DriverManager.getConnection(container.getJdbcUrl(), "sysdba", sysdbaPassword)) {
30+
assertTrue("Connection is valid", connection.isValid(100));
31+
}
32+
}
33+
}
34+
35+
@SuppressWarnings("deprecation")
36+
@Test
37+
public void testImplicitImage() throws SQLException {
38+
final String sysdbaPassword = "sysdbapassword";
39+
try (FirebirdContainer<?> container = new FirebirdContainer<>()
40+
.withSysdbaPassword(sysdbaPassword)) {
2441
container.start();
2542

2643
try (Connection connection = DriverManager.getConnection(container.getJdbcUrl(), "sysdba", sysdbaPassword)) {
@@ -36,7 +53,8 @@ public void testWithSysdbaPassword() throws SQLException {
3653
public void testUserPasswordTakesPrecedenceOverWithSysdbaPassword() throws SQLException {
3754
final String userPassword = "password1";
3855
final String withSysdbaPassword = "password2";
39-
try (FirebirdContainer<?> container = new FirebirdContainer<>().withUsername("sysdba").withPassword(userPassword).withSysdbaPassword(withSysdbaPassword)) {
56+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
57+
.withUsername("sysdba").withPassword(userPassword).withSysdbaPassword(withSysdbaPassword)) {
4058
container.start();
4159

4260
try (Connection connection = DriverManager.getConnection(container.getJdbcUrl(), "sysdba", userPassword)) {
@@ -47,7 +65,8 @@ public void testUserPasswordTakesPrecedenceOverWithSysdbaPassword() throws SQLEx
4765

4866
@Test
4967
public void testWithEnableLegacyClientAuth() throws SQLException {
50-
try (FirebirdContainer<?> container = new FirebirdContainer<>().withEnableLegacyClientAuth()) {
68+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
69+
.withEnableLegacyClientAuth()) {
5170
container.start();
5271

5372
try (Connection connection = container.createConnection("");
@@ -61,7 +80,7 @@ public void testWithEnableLegacyClientAuth() throws SQLException {
6180

6281
@Test
6382
public void testWithEnableLegacyClientAuth_jdbcUrlIncludeAuthPlugins_default() {
64-
try (FirebirdContainer<?> container = new FirebirdContainer<>()
83+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
6584
.withEnableLegacyClientAuth()) {
6685
container.start();
6786

@@ -74,7 +93,7 @@ public void testWithEnableLegacyClientAuth_jdbcUrlIncludeAuthPlugins_default() {
7493

7594
@Test
7695
public void testWithEnableLegacyClientAuth_jdbcUrlIncludeAuthPlugins_explicitlySet() {
77-
try (FirebirdContainer<?> container = new FirebirdContainer<>()
96+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
7897
.withEnableLegacyClientAuth()
7998
.withUrlParam("authPlugins", "Legacy_Auth")) {
8099
container.start();
@@ -88,7 +107,7 @@ public void testWithEnableLegacyClientAuth_jdbcUrlIncludeAuthPlugins_explicitlyS
88107

89108
@Test
90109
public void testWithEnableWireCrypt() throws SQLException {
91-
try (FirebirdContainer<?> container = new FirebirdContainer<>().withEnableWireCrypt()) {
110+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE).withEnableWireCrypt()) {
92111
container.start();
93112

94113
if (FirebirdContainer.isWireEncryptionSupported()) {
@@ -111,7 +130,30 @@ public void testWithEnableWireCrypt() throws SQLException {
111130
*/
112131
@Test
113132
public void test259_scImage() throws Exception {
114-
try (FirebirdContainer<?> container = new FirebirdContainer<>(IMAGE + ":2.5.9-sc").withDatabaseName("test")) {
133+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_259_SC_IMAGE).withDatabaseName("test")) {
134+
assertEquals("Expect original database name before start",
135+
"test", container.getDatabaseName());
136+
137+
container.start();
138+
139+
assertEquals("Expect modified database name after start",
140+
"/firebird/data/test", container.getDatabaseName());
141+
142+
try (Connection connection = DriverManager
143+
.getConnection("jdbc:firebirdsql://" + container.getHost() + ":" + container.getMappedPort(FIREBIRD_PORT) + "/" + container.getDatabaseName(),
144+
container.getUsername(), container.getPassword())
145+
) {
146+
assertTrue(connection.isValid(1000));
147+
}
148+
}
149+
}
150+
151+
/**
152+
* The 2.5 images of jacobalberty/firebird handle FIREBIRD_DATABASE and need an absolute path to access the database
153+
*/
154+
@Test
155+
public void test259_ssImage() throws Exception {
156+
try (FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_259_SS_IMAGE).withDatabaseName("test")) {
115157
assertEquals("Expect original database name before start",
116158
"test", container.getDatabaseName());
117159

@@ -131,7 +173,7 @@ public void test259_scImage() throws Exception {
131173

132174
@Test
133175
public void testWithAdditionalUrlParamInJdbcUrl() {
134-
try (FirebirdContainer<?> firebird = new FirebirdContainer<>()
176+
try (FirebirdContainer<?> firebird = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
135177
.withUrlParam("charSet", "utf-8")
136178
.withUrlParam("blobBufferSize", "2048")) {
137179

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.firebirdsql.testcontainers;
2+
3+
import org.testcontainers.utility.DockerImageName;
4+
5+
public final class FirebirdTestImages {
6+
7+
public static final DockerImageName FIREBIRD_307_IMAGE = FirebirdContainer.DEFAULT_IMAGE_NAME.withTag("3.0.7");
8+
public static final DockerImageName FIREBIRD_259_SC_IMAGE = FirebirdContainer.DEFAULT_IMAGE_NAME.withTag("2.5.9-sc");
9+
public static final DockerImageName FIREBIRD_259_SS_IMAGE = FirebirdContainer.DEFAULT_IMAGE_NAME.withTag("2.5.9-ss");
10+
public static final DockerImageName FIREBIRD_TEST_IMAGE = FIREBIRD_307_IMAGE;
11+
12+
private FirebirdTestImages() {
13+
throw new AssertionError("no instances");
14+
}
15+
}

src/test/java/org/firebirdsql/testcontainers/examples/ExampleRuleTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.sql.ResultSet;
1010
import java.sql.Statement;
1111

12+
import static org.firebirdsql.testcontainers.FirebirdTestImages.FIREBIRD_TEST_IMAGE;
1213
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
1314
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
1415

@@ -18,7 +19,7 @@
1819
public class ExampleRuleTest {
1920

2021
@Rule
21-
public final FirebirdContainer<?> container = new FirebirdContainer<>()
22+
public final FirebirdContainer<?> container = new FirebirdContainer<>(FIREBIRD_TEST_IMAGE)
2223
.withUsername("testuser")
2324
.withPassword("testpassword");
2425

0 commit comments

Comments
 (0)