From 9fc6deb73fecbe19b3e273dfa50f5aabc922017a Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Tue, 12 Jun 2018 11:09:06 +0200 Subject: [PATCH 1/2] Make JdbcDatabaseContainer#getDriverClassName public --- .../org/testcontainers/containers/JdbcDatabaseContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java b/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java index 77589395c19..5cd62b68220 100644 --- a/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java +++ b/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java @@ -47,7 +47,7 @@ public JdbcDatabaseContainer(@NonNull final Future image) { /** * @return the name of the actual JDBC driver to use */ - protected abstract String getDriverClassName(); + public abstract String getDriverClassName(); /** * @return a JDBC URL that may be used to connect to the dockerized DB From 7bc0cbcec2ad3a15a04ef1bb104b94712829c508 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Tue, 12 Jun 2018 11:11:16 +0200 Subject: [PATCH 2/2] Add test to demonstrate getDriverClassName use case --- .../testcontainers/junit/SimpleMySQLTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java b/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java index d1ee8100709..572921d8a1e 100644 --- a/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java +++ b/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java @@ -110,9 +110,28 @@ public void testCommandOverride() throws SQLException { } + @Test + public void testMySQL8() throws SQLException { + assumeFalse(SystemUtils.IS_OS_WINDOWS); + MySQLContainer container = new MySQLContainer<>("mysql:8.0.11") + .withCommand("mysqld --default-authentication-plugin=mysql_native_password"); + container.start(); + + try { + ResultSet resultSet = performQuery(container, "SELECT VERSION()"); + String resultSetString = resultSet.getString(1); + + assertTrue("The database version can be set using a container rule parameter", "8.0.11".equals(resultSetString)); + } + finally { + container.stop(); + } + } + @NonNull protected ResultSet performQuery(MySQLContainer containerRule, String sql) throws SQLException { HikariConfig hikariConfig = new HikariConfig(); + hikariConfig.setDriverClassName(containerRule.getDriverClassName()); hikariConfig.setJdbcUrl(containerRule.getJdbcUrl()); hikariConfig.setUsername(containerRule.getUsername()); hikariConfig.setPassword(containerRule.getPassword());