Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Richard North <rich.north@gmail.com>
Richard North <rich.north@gmail.com>
Gurpreet Sohal <gurpreet@gurpreetsohal.com>
Alex Boldt <boldtalex@gmail.com>
Robert Požarickij <robert.pozarickij@gmail.com>
Robert Požarickij <robert.pozarickij@gmail.com>
Krystian Nowak <krystian.nowak@gmail.com>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
<developer>
<id>rpozarickij</id>
<name>Robert Požarickij</name>
<email>robert.pozarickij@gmail.com&gt;</email>
<email>robert.pozarickij@gmail.com</email>
</developer>
<developer>
<id>krystiannowak</id>
<name>Krystian Nowak</name>
<email>krystian.nowak@gmail.com</email>
</developer>
</developers>

Expand Down