33import com .zaxxer .hikari .HikariConfig ;
44import com .zaxxer .hikari .HikariDataSource ;
55import org .apache .commons .dbutils .QueryRunner ;
6- import org .junit .AfterClass ;
7- import org .junit .Test ;
8- import org .junit .runner . RunWith ;
9- import org .junit .runners . Parameterized ;
10- import org .junit .runners . Parameterized . Parameter ;
6+ import org .junit .jupiter . api . AfterAll ;
7+ import org .junit .jupiter . api . Test ;
8+ import org .junit .jupiter . params . ParameterizedClass ;
9+ import org .junit .jupiter . params . provider . Arguments ;
10+ import org .junit .jupiter . params . provider . MethodSource ;
1111import org .testcontainers .jdbc .ContainerDatabaseDriver ;
1212
1313import javax .sql .DataSource ;
1414import java .sql .Connection ;
1515import java .sql .SQLException ;
1616import java .util .EnumSet ;
17+ import java .util .Set ;
18+ import java .util .stream .Stream ;
1719
1820import static java .util .Arrays .asList ;
1921import static org .hamcrest .CoreMatchers .endsWith ;
2022import static org .hamcrest .MatcherAssert .assertThat ;
21- import static org .junit .Assert .assertEquals ;
22- import static org .junit .Assert .assertTrue ;
23+ import static org .junit .jupiter . api . Assertions .assertEquals ;
24+ import static org .junit .jupiter . api . Assertions .assertTrue ;
2325
24- @ RunWith (Parameterized .class )
26+ @ ParameterizedClass (name = "{index} - {0}" )
27+ @ MethodSource ("data" )
2528public class JDBCDriverTest {
2629
30+ // NOTE Class needs to be public due to sampleInitFunction referenced in test URLs
31+
2732 private enum Options {
2833 ScriptedSchema ,
2934 JDBCParams ,
3035 }
3136
32- @ Parameter
33- public String jdbcUrl ;
34- @ Parameter (1 )
35- public EnumSet <Options > options ;
36-
37- @ Parameterized .Parameters (name = "{index} - {0}" )
38- public static Iterable <Object []> data () {
39- return asList (
40- new Object [][]{
41- {"jdbc:tc:firebird://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
42- {"jdbc:tc:firebirdsql://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
43- {"jdbc:tc:firebird:latest://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
44- {"jdbc:tc:firebird:5://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
45- {"jdbc:tc:firebird:5.0.3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
46- {"jdbc:tc:firebirdsql:5.0.3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
47- {"jdbc:tc:firebird:4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
48- {"jdbc:tc:firebird:4.0.6://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
49- {"jdbc:tc:firebird:3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
50- {"jdbc:tc:firebird:3.0.13://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet .of (Options .ScriptedSchema , Options .JDBCParams )},
37+ private final String jdbcUrl ;
38+ private final Set <Options > options ;
39+
40+ JDBCDriverTest (String jdbcUrl , Set <Options > options ) {
41+ this .jdbcUrl = jdbcUrl ;
42+ this .options = options ;
43+ }
44+
45+ static Stream <Arguments > data () {
46+ return Stream .of (
47+ testCase ("jdbc:tc:firebird://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
48+ testCase ("jdbc:tc:firebirdsql://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
49+ testCase ("jdbc:tc:firebird:latest://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
50+ testCase ("jdbc:tc:firebird:5://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
51+ testCase ("jdbc:tc:firebird:5.0.3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
52+ testCase ("jdbc:tc:firebirdsql:5.0.3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
53+ testCase ("jdbc:tc:firebird:4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
54+ testCase ("jdbc:tc:firebird:4.0.6://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
55+ testCase ("jdbc:tc:firebird:3://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
56+ testCase ("jdbc:tc:firebird:3.0.13://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
5157
5258 // jacobalberty tags are mapped
53- { "jdbc:tc:firebird:v4.0.2://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet . of ( Options .ScriptedSchema , Options .JDBCParams )} ,
54- { "jdbc:tc:firebird:v3.0.10://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , EnumSet . of ( Options .ScriptedSchema , Options .JDBCParams )},
59+ testCase ( "jdbc:tc:firebird:v4.0.2://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams ),
60+ testCase ( "jdbc:tc:firebird:v3.0.10://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction" , Options .ScriptedSchema , Options .JDBCParams )
5561 // These images are problematic (they don't always seem to have their port available, or connecting doesn't work)
56- //{"jdbc:tc:firebird:2.5.9-sc://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
57- //{"jdbc:tc:firebird:2.5.9-ss://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
58- });
62+ //testCase("jdbc:tc:firebird:2.5.9-sc://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", Options.ScriptedSchema, Options.JDBCParams),
63+ //testCase("jdbc:tc:firebird:2.5.9-ss://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", Options.ScriptedSchema, Options.JDBCParams),
64+ );
65+ }
66+
67+ @ SuppressWarnings ("SameParameterValue" )
68+ private static Arguments testCase (String jdbcUrl , Options ... options ) {
69+ Set <Options > optionSet = EnumSet .noneOf (Options .class );
70+ optionSet .addAll (asList (options ));
71+ return Arguments .of (jdbcUrl , optionSet );
5972 }
6073
74+ // Must be public: referenced in test URLs
6175 @ SuppressWarnings ("unused" )
6276 public static void sampleInitFunction (Connection connection ) throws SQLException {
6377 connection .createStatement ().execute ("CREATE TABLE bar (\n " +
@@ -69,13 +83,13 @@ public static void sampleInitFunction(Connection connection) throws SQLException
6983 ");" );
7084 }
7185
72- @ AfterClass
73- public static void testCleanup () {
86+ @ AfterAll
87+ static void testCleanup () {
7488 ContainerDatabaseDriver .killContainers ();
7589 }
7690
7791 @ Test
78- public void test () throws SQLException {
92+ void test () throws SQLException {
7993 try (HikariDataSource dataSource = getDataSource (jdbcUrl , 1 )) {
8094 performSimpleTest (dataSource );
8195
@@ -93,18 +107,19 @@ private void performSimpleTest(DataSource dataSource) throws SQLException {
93107 boolean result = new QueryRunner (dataSource ).query ("SELECT 1 FROM RDB$DATABASE" , rs -> {
94108 rs .next ();
95109 int resultSetInt = rs .getInt (1 );
96- assertEquals ("A basic SELECT query succeeds" , 1 , resultSetInt );
110+ assertEquals (1 , resultSetInt , "A basic SELECT query succeeds" );
97111 return true ;
98112 });
99113
100- assertTrue ("The database returned a record as expected" , result );
114+ assertTrue (result , "The database returned a record as expected" );
101115 }
102116
103117 private void performTestForScriptedSchema (DataSource dataSource ) throws SQLException {
104118 new QueryRunner (dataSource ).query ("SELECT foo FROM bar WHERE foo LIKE '%world'" , rs -> {
105119 rs .next ();
106120 String resultSetString = rs .getString (1 );
107- assertEquals ("A basic SELECT query succeeds where the schema has been applied from a script" , "hello world" , resultSetString );
121+ assertEquals ("hello world" , resultSetString ,
122+ "A basic SELECT query succeeds where the schema has been applied from a script" );
108123 return true ;
109124 });
110125 }
@@ -117,11 +132,11 @@ private void performTestForJDBCParamUsage(DataSource dataSource) throws SQLExcep
117132 if (resultUser .endsWith ("@%" )) {
118133 resultUser = resultUser .substring (0 , resultUser .length () - 2 );
119134 }
120- assertEquals ("User from query param is created." , "SOMEUSER" , resultUser );
135+ assertEquals ("SOMEUSER" , resultUser , " User from query param is created" );
121136 return true ;
122137 });
123138
124- assertTrue ("The database returned a record as expected" , result );
139+ assertTrue (result , "The database returned a record as expected" );
125140
126141 String databaseQuery = "select rdb$get_context('SYSTEM', 'DB_NAME') from RDB$DATABASE" ;
127142
@@ -133,9 +148,10 @@ private void performTestForJDBCParamUsage(DataSource dataSource) throws SQLExcep
133148 return true ;
134149 });
135150
136- assertTrue ("The database returned a record as expected" , result );
151+ assertTrue (result , "The database returned a record as expected" );
137152 }
138153
154+ @ SuppressWarnings ("SameParameterValue" )
139155 private HikariDataSource getDataSource (String jdbcUrl , int poolSize ) {
140156 HikariConfig hikariConfig = new HikariConfig ();
141157 hikariConfig .setJdbcUrl (jdbcUrl );
0 commit comments