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
10 changes: 9 additions & 1 deletion modules/cassandra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ dependencies {
api project(":testcontainers-database-commons")
api "com.datastax.cassandra:cassandra-driver-core:3.10.0"

testImplementation 'com.datastax.oss:java-driver-core:4.17.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.assertj:assertj-core:3.27.4'
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.13.4'
testImplementation 'com.datastax.oss:java-driver-core:4.17.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.utility.DockerImageName;

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

public class CassandraContainerTest {
class CassandraContainerTest {

private static final String CASSANDRA_IMAGE = "cassandra:3.11.2";

Expand All @@ -19,7 +19,7 @@ public class CassandraContainerTest {
private static final String BASIC_QUERY = "SELECT release_version FROM system.local";

@Test
public void testSimple() {
void testSimple() {
try ( // container-definition {
CassandraContainer cassandraContainer = new CassandraContainer("cassandra:3.11.2")
// }
Expand All @@ -32,7 +32,7 @@ public void testSimple() {
}

@Test
public void testSpecificVersion() {
void testSpecificVersion() {
String cassandraVersion = "3.0.15";
try (
CassandraContainer cassandraContainer = new CassandraContainer(
Expand All @@ -47,7 +47,7 @@ public void testSpecificVersion() {
}

@Test
public void testConfigurationOverride() {
void testConfigurationOverride() {
try (
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-test-configuration-example")
Expand All @@ -61,18 +61,18 @@ public void testConfigurationOverride() {
}
}

@Test(expected = ContainerLaunchException.class)
public void testEmptyConfigurationOverride() {
@Test
void testEmptyConfigurationOverride() {
try (
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-empty-configuration")
) {
cassandraContainer.start();
assertThatThrownBy(cassandraContainer::start).isInstanceOf(ContainerLaunchException.class);
}
}

@Test
public void testInitScript() {
void testInitScript() {
try (
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withInitScript("initial.cql")
Expand All @@ -83,17 +83,17 @@ public void testInitScript() {
}

@Test
public void testNonexistentInitScript() {
void testNonexistentInitScript() {
try (
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withInitScript("unknown_script.cql")
) {
assertThat(catchThrowable(cassandraContainer::start)).isInstanceOf(ContainerLaunchException.class);
assertThatThrownBy(cassandraContainer::start).isInstanceOf(ContainerLaunchException.class);
}
}

@Test
public void testInitScriptWithRequiredAuthentication() {
void testInitScriptWithRequiredAuthentication() {
try (
// init-with-auth {
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
Expand All @@ -106,18 +106,18 @@ public void testInitScriptWithRequiredAuthentication() {
}
}

@Test(expected = ContainerLaunchException.class)
public void testInitScriptWithError() {
@Test
void testInitScriptWithError() {
try (
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withInitScript("initial-with-error.cql")
) {
cassandraContainer.start();
assertThatThrownBy(cassandraContainer::start).isInstanceOf(ContainerLaunchException.class);
}
}

@Test
public void testInitScriptWithLegacyCassandra() {
void testInitScriptWithLegacyCassandra() {
try (
CassandraContainer cassandraContainer = new CassandraContainer("cassandra:2.2.11")
.withInitScript("initial.cql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

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

@RunWith(Parameterized.class)
public class CompatibleCassandraImageTest {
class CompatibleCassandraImageTest {

@Parameterized.Parameters(name = "{0}")
public static String[] params() {
return new String[] { "cassandra:3.11.2", "cassandra:4.1.1", "cassandra:5" };
}

@Parameterized.Parameter
public String imageName;

@Test
public void testCassandraGetContactPoint() {
try (CassandraContainer cassandra = new CassandraContainer(this.imageName)) {
@ParameterizedTest
@MethodSource("params")
void testCassandraGetContactPoint(String imageName) {
try (CassandraContainer cassandra = new CassandraContainer(imageName)) {
cassandra.start();
assertCassandraFunctionality(cassandra);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.wait.CassandraQueryWaitStrategy;
import org.testcontainers.utility.DockerImageName;

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

@Slf4j
public class CassandraContainerTest {
class CassandraContainerTest {

private static final DockerImageName CASSANDRA_IMAGE = DockerImageName.parse("cassandra:3.11.2");

Expand All @@ -21,7 +22,7 @@ public class CassandraContainerTest {
private static final String BASIC_QUERY = "SELECT release_version FROM system.local";

@Test
public void testSimple() {
void testSimple() {
try (CassandraContainer<?> cassandraContainer = new CassandraContainer<>(CASSANDRA_IMAGE)) {
cassandraContainer.start();
ResultSet resultSet = performQuery(cassandraContainer, BASIC_QUERY);
Expand All @@ -31,7 +32,7 @@ public void testSimple() {
}

@Test
public void testSpecificVersion() {
void testSpecificVersion() {
String cassandraVersion = "3.0.15";
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(
Expand All @@ -46,7 +47,7 @@ public void testSpecificVersion() {
}

@Test
public void testConfigurationOverride() {
void testConfigurationOverride() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-test-configuration-example")
Expand All @@ -60,18 +61,18 @@ public void testConfigurationOverride() {
}
}

@Test(expected = ContainerLaunchException.class)
public void testEmptyConfigurationOverride() {
@Test
void testEmptyConfigurationOverride() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-empty-configuration")
) {
cassandraContainer.start();
assertThatThrownBy(cassandraContainer::start).isInstanceOf(ContainerLaunchException.class);
}
}

@Test
public void testInitScript() {
void testInitScript() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(CASSANDRA_IMAGE)
.withInitScript("initial.cql")
Expand All @@ -82,7 +83,7 @@ public void testInitScript() {
}

@Test
public void testInitScriptWithLegacyCassandra() {
void testInitScriptWithLegacyCassandra() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(
DockerImageName.parse("cassandra:2.2.11")
Expand All @@ -96,7 +97,7 @@ public void testInitScriptWithLegacyCassandra() {

@SuppressWarnings("deprecation") // Using deprecated constructor for verification of backwards compatibility
@Test
public void testCassandraQueryWaitStrategy() {
void testCassandraQueryWaitStrategy() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>()
.waitingFor(new CassandraQueryWaitStrategy())
Expand All @@ -109,7 +110,7 @@ public void testCassandraQueryWaitStrategy() {

@SuppressWarnings("deprecation") // Using deprecated constructor for verification of backwards compatibility
@Test
public void testCassandraGetCluster() {
void testCassandraGetCluster() {
try (CassandraContainer<?> cassandraContainer = new CassandraContainer<>()) {
cassandraContainer.start();
ResultSet resultSet = performQuery(cassandraContainer.getCluster(), BASIC_QUERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

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

@RunWith(Parameterized.class)
public class CompatibleCassandraImageTest {

@Parameterized.Parameters(name = "{0}")
public static String[] params() {
return new String[] { "cassandra:3.11.2", "cassandra:4.1.1" };
}

@Parameterized.Parameter
public String imageName;

@Test
public void testCassandraGetContactPoint() {
try (CassandraContainer<?> cassandra = new CassandraContainer<>(this.imageName)) {
@ParameterizedTest
@MethodSource("params")
void testCassandraGetContactPoint(String imageName) {
try (CassandraContainer<?> cassandra = new CassandraContainer<>(imageName)) {
cassandra.start();
assertCassandraFunctionality(cassandra);
}
Expand Down
Loading