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
7 changes: 7 additions & 0 deletions modules/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ description = "Testcontainers :: JDBC"
dependencies {
api project(':testcontainers-database-commons')

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
compileOnly 'org.jetbrains:annotations:26.0.2'
testImplementation 'commons-dbutils:commons-dbutils:1.8.1'
testImplementation 'org.vibur:vibur-dbcp:26.0'
Expand All @@ -13,3 +16,7 @@ dependencies {
exclude(module: 'hamcrest-core')
}
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.testcontainers.containers;

import lombok.NonNull;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;

import java.sql.Connection;
Expand All @@ -10,10 +10,10 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;

public class JdbcDatabaseContainerTest {
class JdbcDatabaseContainerTest {

@Test
public void anExceptionIsThrownIfJdbcIsNotAvailable() {
void anExceptionIsThrownIfJdbcIsNotAvailable() {
JdbcDatabaseContainer<?> jdbcContainer = new JdbcDatabaseContainerStub("mysql:latest")
.withStartupTimeoutSeconds(1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,127 +1,126 @@
package org.testcontainers.jdbc;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

/**
* This Test class validates that all supported JDBC URL's can be parsed by ConnectionUrl class.
*/
@RunWith(Parameterized.class)
public class ConnectionUrlDriversTests {
class ConnectionUrlDriversTests {

@Parameter
public String jdbcUrl;

@Parameter(1)
public String databaseType;

@Parameter(2)
public Optional<String> tag;

@Parameter(3)
public String dbHostString;

@Parameter(4)
public String databaseName;

@Parameterized.Parameters(name = "{index} - {0}")
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][] {
{ "jdbc:tc:mysql:8.0.36://hostname/test", "mysql", Optional.of("8.0.36"), "hostname/test", "test" },
{ "jdbc:tc:mysql://hostname/test", "mysql", Optional.empty(), "hostname/test", "test" },
{
"jdbc:tc:postgresql:1.2.3://hostname/test",
"postgresql",
Optional.of("1.2.3"),
"hostname/test",
"test",
},
{ "jdbc:tc:postgresql://hostname/test", "postgresql", Optional.empty(), "hostname/test", "test" },
{
"jdbc:tc:sqlserver:1.2.3://localhost;instance=SQLEXPRESS:1433;databaseName=test",
"sqlserver",
Optional.of("1.2.3"),
"localhost;instance=SQLEXPRESS:1433;databaseName=test",
"test",
},
{
"jdbc:tc:sqlserver://localhost;instance=SQLEXPRESS:1433;databaseName=test",
"sqlserver",
Optional.empty(),
"localhost;instance=SQLEXPRESS:1433;databaseName=test",
"test",
},
{
"jdbc:tc:mariadb:1.2.3://localhost:3306/test",
"mariadb",
Optional.of("1.2.3"),
"localhost:3306/test",
"test",
},
{ "jdbc:tc:mariadb://localhost:3306/test", "mariadb", Optional.empty(), "localhost:3306/test", "test" },
{
"jdbc:tc:oracle:1.2.3:thin://@localhost:1521/test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521/test",
"test",
},
{
"jdbc:tc:oracle:1.2.3:thin:@localhost:1521/test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521/test",
"test",
},
{
"jdbc:tc:oracle:thin:@localhost:1521/test",
"oracle",
Optional.empty(),
"localhost:1521/test",
"test",
},
{
"jdbc:tc:oracle:1.2.3:thin:@localhost:1521:test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521:test",
"test",
},
{
"jdbc:tc:oracle:1.2.3:thin://@localhost:1521:test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521:test",
"test",
},
{
"jdbc:tc:oracle:1.2.3-anything:thin://@localhost:1521:test",
"oracle",
Optional.of("1.2.3-anything"),
"localhost:1521:test",
"test",
},
{
"jdbc:tc:oracle:thin:@localhost:1521:test",
"oracle",
Optional.empty(),
"localhost:1521:test",
"test",
},
}
public static Stream<Arguments> data() {
return Stream.of(
Arguments.arguments(
"jdbc:tc:mysql:8.0.36://hostname/test",
"mysql",
Optional.of("8.0.36"),
"hostname/test",
"test"
),
Arguments.arguments("jdbc:tc:mysql://hostname/test", "mysql", Optional.empty(), "hostname/test", "test"),
Arguments.arguments(
"jdbc:tc:postgresql:1.2.3://hostname/test",
"postgresql",
Optional.of("1.2.3"),
"hostname/test",
"test"
),
Arguments.arguments(
"jdbc:tc:postgresql://hostname/test",
"postgresql",
Optional.empty(),
"hostname/test",
"test"
),
Arguments.arguments(
"jdbc:tc:sqlserver:1.2.3://localhost;instance=SQLEXPRESS:1433;databaseName=test",
"sqlserver",
Optional.of("1.2.3"),
"localhost;instance=SQLEXPRESS:1433;databaseName=test",
"test"
),
Arguments.arguments(
"jdbc:tc:sqlserver://localhost;instance=SQLEXPRESS:1433;databaseName=test",
"sqlserver",
Optional.empty(),
"localhost;instance=SQLEXPRESS:1433;databaseName=test",
"test"
),
Arguments.arguments(
"jdbc:tc:mariadb:1.2.3://localhost:3306/test",
"mariadb",
Optional.of("1.2.3"),
"localhost:3306/test",
"test"
),
Arguments.arguments(
"jdbc:tc:mariadb://localhost:3306/test",
"mariadb",
Optional.empty(),
"localhost:3306/test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:1.2.3:thin://@localhost:1521/test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521/test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:1.2.3:thin:@localhost:1521/test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521/test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:thin:@localhost:1521/test",
"oracle",
Optional.empty(),
"localhost:1521/test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:1.2.3:thin:@localhost:1521:test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521:test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:1.2.3:thin://@localhost:1521:test",
"oracle",
Optional.of("1.2.3"),
"localhost:1521:test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:1.2.3-anything:thin://@localhost:1521:test",
"oracle",
Optional.of("1.2.3-anything"),
"localhost:1521:test",
"test"
),
Arguments.arguments(
"jdbc:tc:oracle:thin:@localhost:1521:test",
"oracle",
Optional.empty(),
"localhost:1521:test",
"test"
)
);
}

@Test
public void test() {
@ParameterizedTest(name = "{index} - {0}")
@MethodSource("data")
void test(String jdbcUrl, String databaseType, Optional<String> tag, String dbHostString, String databaseName) {
ConnectionUrl url = ConnectionUrl.newInstance(jdbcUrl);
assertThat(url.getDatabaseType()).as("Database Type is as expected").isEqualTo(databaseType);
assertThat(url.getImageTag()).as("Image tag is as expected").isEqualTo(tag);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package org.testcontainers.jdbc;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class ConnectionUrlTest {

@Rule
public ExpectedException thrown = ExpectedException.none();
class ConnectionUrlTest {

@Test
public void testConnectionUrl1() {
void testConnectionUrl1() {
String urlString = "jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

Expand All @@ -31,7 +27,7 @@ public void testConnectionUrl1() {
}

@Test
public void testConnectionUrl2() {
void testConnectionUrl2() {
String urlString = "jdbc:tc:mysql://somehostname/databasename";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

Expand All @@ -49,13 +45,13 @@ public void testConnectionUrl2() {
}

@Test
public void testEmptyQueryParameter() {
void testEmptyQueryParameter() {
ConnectionUrl url = ConnectionUrl.newInstance("jdbc:tc:mysql://somehostname/databasename?key=");
assertThat(url.getQueryParameters().get("key")).as("'key' property value").isEqualTo("");
}

@Test
public void testTmpfsOption() {
void testTmpfsOption() {
String urlString = "jdbc:tc:mysql://somehostname/databasename?TC_TMPFS=key:value,key1:value1";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

Expand All @@ -69,7 +65,7 @@ public void testTmpfsOption() {
}

@Test
public void testInitScriptPathCapture() {
void testInitScriptPathCapture() {
String urlString =
"jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_INITSCRIPT=somepath/init_mysql.sql";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);
Expand All @@ -83,13 +79,14 @@ public void testInitScriptPathCapture() {
.containsEntry("TC_INITSCRIPT", "somepath/init_mysql.sql");

//Parameter sets are unmodifiable
thrown.expect(UnsupportedOperationException.class);
url.getContainerParameters().remove("TC_INITSCRIPT");
url.getQueryParameters().remove("a");
assertThatThrownBy(() -> url.getContainerParameters().remove("TC_INITSCRIPT"))
.isInstanceOf(UnsupportedOperationException.class);
assertThatThrownBy(() -> url.getQueryParameters().remove("a"))
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
public void testInitFunctionCapture() {
void testInitFunctionCapture() {
String urlString =
"jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);
Expand All @@ -105,15 +102,15 @@ public void testInitFunctionCapture() {
}

@Test
public void testDaemonCapture() {
void testDaemonCapture() {
String urlString = "jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_DAEMON=true";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.isInDaemonMode()).as("Daemon flag is set to true.").isTrue();
}

@Test
public void testHostLessConnectionUrl() {
void testHostLessConnectionUrl() {
String urlString = "jdbc:tc:mysql:8.0.36:///databasename?a=b&c=d";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

Expand Down
Loading
Loading