From effd294c923e102cd1d486ad4c20f1cd7f0d10ee Mon Sep 17 00:00:00 2001 From: Krystian Nowak Date: Tue, 16 Feb 2016 11:10:49 +0100 Subject: [PATCH 1/3] ContainerDatabaseDriver.connect misbehaviour fix --- .../jdbc/ContainerDatabaseDriver.java | 7 ++++ .../jdbc/ContainerDatabaseDriverTest.java | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 modules/jdbc/src/test/java/org/testcontainers/jdbc/ContainerDatabaseDriverTest.java diff --git a/modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java b/modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java index efd7b958574..9d0ce359100 100644 --- a/modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java +++ b/modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java @@ -72,6 +72,13 @@ public boolean acceptsURL(String url) throws SQLException { @Override public synchronized Connection connect(String url, final Properties info) throws SQLException { + /** + * The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. + */ + if(!acceptsURL(url)) { + return null; + } + String queryString = ""; /** * If we already have a running container for this exact connection string, we want to connect diff --git a/modules/jdbc/src/test/java/org/testcontainers/jdbc/ContainerDatabaseDriverTest.java b/modules/jdbc/src/test/java/org/testcontainers/jdbc/ContainerDatabaseDriverTest.java new file mode 100644 index 00000000000..8b11722c357 --- /dev/null +++ b/modules/jdbc/src/test/java/org/testcontainers/jdbc/ContainerDatabaseDriverTest.java @@ -0,0 +1,35 @@ +package org.testcontainers.jdbc; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class ContainerDatabaseDriverTest { + + private static final String PLAIN_POSTGRESQL_JDBC_URL = "jdbc:postgresql://localhost:5432/test"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void shouldNotTryToConnectToNonMatchingJdbcUrlDirectly() throws SQLException { + ContainerDatabaseDriver driver = new ContainerDatabaseDriver(); + Connection connection = driver.connect(PLAIN_POSTGRESQL_JDBC_URL, new Properties()); + Assert.assertNull(connection); + } + + @Test + public void shouldNotTryToConnectToNonMatchingJdbcUrlViaDriverManager() throws SQLException { + thrown.expect(SQLException.class); + thrown.expectMessage(CoreMatchers.startsWith("No suitable driver found for ")); + DriverManager.getConnection(PLAIN_POSTGRESQL_JDBC_URL); + } + +} From 4fd9503dc95b7c1d7b6d62873cb268b73196754f Mon Sep 17 00:00:00 2001 From: Krystian Nowak Date: Tue, 16 Feb 2016 20:49:26 +0100 Subject: [PATCH 2/3] krystiannowak added to POM developers list and AUTHORS file --- AUTHORS | 5 +++-- pom.xml | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0a877a777bb..2b3140224c7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,5 @@ -Richard North +Richard North Gurpreet Sohal Alex Boldt -Robert Požarickij \ No newline at end of file +Robert Požarickij +Krystian Nowak diff --git a/pom.xml b/pom.xml index 097b3df5ff8..1982e1c8a65 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0 @@ -38,7 +38,12 @@ rpozarickij Robert Požarickij - robert.pozarickij@gmail.com> + robert.pozarickij@gmail.com + + + krystiannowak + Krystian Nowak + krystian.nowak@gmail.com From 0ed06c3aa3994674f217d87cadf42a21e0052e3b Mon Sep 17 00:00:00 2001 From: Krystian Nowak Date: Wed, 17 Feb 2016 12:01:56 +0100 Subject: [PATCH 3/3] unnecessary byte order mark removed from pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1982e1c8a65..32226945b23 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0