@@ -38,6 +38,110 @@ testCompile "org.firebirdsql:firebird-testcontainers-java:1.0.0"
3838</dependency >
3939```
4040
41+ Usage
42+ -----
43+
44+ For extensive documentation, consult https://www.testcontainers.org/modules/databases/
45+
46+ ### JUnit rule
47+
48+ Using a JUnit ` @Rule ` or ` @ClassRule ` you can configure a container and start it
49+ per test (` @Rule ` ) or per class (` @ClassRule ` ).
50+
51+ The container defines several ` withXXX ` methods for configuration.
52+
53+ Important standard options are:
54+
55+ - ` withUsername(String) ` - Sets the username to create (defaults to ` test ` ); if
56+ other than ` sysdba ` (case insensitive), sets docker environment variable
57+ ` FIREBIRD_USER `
58+ - ` withPassword(String) ` - Sets the password of the user (defaults to ` test ` );
59+ if ` withUsername ` is other than ` sysdba ` (case insensitive), sets the docker
60+ environment variable ` FIREBIRD_PASSWORD ` , otherwise ` ISC_PASSWORD `
61+ - ` withDatabaseName(String) ` - Sets the database name (defaults to ` test ` );
62+ sets docker environment variable ` FIREBIRD_DATABASE `
63+
64+ Firebird specific options are:
65+
66+ - ` withEnableLegacyClientAuth() ` - (_ Firebird 3+_ ) Enables ` LegacyAuth ` and uses
67+ it as the default for creating users, also relaxes ` WireCrypt ` to ` Enabled ` ;
68+ sets docker environment variable ` EnableLegacyClientAuth ` to ` true `
69+ - ` withEnableWireCrypt ` - (_ Firebird 3+_ ) Relaxes ` WireCrypt ` from ` Required ` to
70+ ` Enabled ` ; sets docker environment variable ` EnableWireCrypt ` to `true
71+ - ` withTimeZone(String) ` - Sets the time zone (defaults to JVM default time
72+ zone); sets docker environment variable ` TZ ` to the specified value
73+ - ` withSysdbaPassword(String) ` - Sets the SYSDBA password, but if
74+ ` withUsername(String) ` is set to ` sysdba ` (case insensitive), this property is
75+ ignored and the value of ` withPassword ` is used instead; sets docker
76+ environment variable ` ISC_PASSWORD ` to the specified value
77+
78+ Example of use:
79+
80+ ``` java
81+ /**
82+ * Simple test demonstrating use of {@code @Rule }.
83+ */
84+ public class ExampleRuleTest {
85+
86+ @Rule
87+ public final FirebirdContainer container = new FirebirdContainer ()
88+ .withUsername(" testuser" )
89+ .withPassword(" testpassword" );
90+
91+ @Test
92+ public void canConnectToContainer () throws Exception {
93+ try (Connection connection = DriverManager
94+ .getConnection(container. getJdbcUrl(), container. getUsername(), container. getPassword());
95+ Statement stmt = connection. createStatement();
96+ ResultSet rs = stmt. executeQuery(" select CURRENT_USER from RDB$DATABASE" )) {
97+ assertTrue(" has row" , rs. next());
98+ assertEquals(" user name" , " TESTUSER" , rs. getString(1 ));
99+ }
100+ }
101+ }
102+ ```
103+
104+ ### Testcontainers URL
105+
106+ The testcontainers URL defines the container and connects to it. As long as there
107+ are active connections, the container will stay up.
108+
109+ For Firebird the URL format is:
110+
111+ - ` jdbc:tc:firebird[:<image-tag>]://hostname/<databasename>[?<property>=<value>[&<property>=<value>...]] `
112+ - ` jdbc:tc:firebirdsql[:<image-tag>]://hostname/<databasename>[?<property>=<value>[&<property>=<value>...]] `
113+
114+ Where:
115+
116+ - ` <image-tag> ` (_ optional_ ) is the tag of the docker image to use
117+ - ` <databasename> ` (_ optional_ ) is the name of the database (defaults to ` test ` )
118+ - ` <property> ` is a connection property (Jaybird properties ** and** testcontainers properties are possible) \
119+ Of special note are the properties:
120+ - ` user ` (_ optional_ ) specifies the username to create and connect (defaults to ` test ` )
121+ - ` password ` (_ optional_ ) specifies the password for the user (defaults to ` test ` )
122+ - ` <value> ` is the value of the property
123+
124+ Example of use:
125+
126+ ``` java
127+ /**
128+ * Simple test demonstrating use of url to instantiate container.
129+ */
130+ public class ExampleUrlTest {
131+
132+ @Test
133+ public void canConnectUsingUrl () throws Exception {
134+ try (Connection connection = DriverManager
135+ .getConnection(" jdbc:tc:firebird://hostname/databasename?user=someuser&password=somepwd" );
136+ Statement stmt = connection. createStatement();
137+ ResultSet rs = stmt. executeQuery(" select CURRENT_USER from RDB$DATABASE" )) {
138+ assertTrue(" has row" , rs. next());
139+ assertEquals(" user name" , " SOMEUSER" , rs. getString(1 ));
140+ }
141+ }
142+ }
143+ ```
144+
41145License
42146-------
43147
0 commit comments