diff --git a/modules/kafka/build.gradle b/modules/kafka/build.gradle index ebfcca345a4..baee466d59e 100644 --- a/modules/kafka/build.gradle +++ b/modules/kafka/build.gradle @@ -3,8 +3,16 @@ description = "Testcontainers :: Kafka" dependencies { api project(':testcontainers') + testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0' + + testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.13.4' testImplementation 'org.apache.kafka:kafka-clients:3.8.0' testImplementation 'org.assertj:assertj-core:3.27.4' testImplementation 'com.google.guava:guava:23.0' testImplementation 'org.awaitility:awaitility:4.3.0' } + +test { + useJUnitPlatform() +} diff --git a/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java b/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java index 49b21108da8..e244d7a2e26 100644 --- a/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java +++ b/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java @@ -9,7 +9,7 @@ import org.apache.kafka.common.errors.SaslAuthenticationException; import org.apache.kafka.common.errors.TopicAuthorizationException; import org.awaitility.Awaitility; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.testcontainers.AbstractKafka; import org.testcontainers.Testcontainers; import org.testcontainers.images.builder.Transferable; @@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class KafkaContainerTest extends AbstractKafka { +class KafkaContainerTest extends AbstractKafka { private static final DockerImageName KAFKA_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-kafka:6.2.1"); @@ -35,7 +35,7 @@ public class KafkaContainerTest extends AbstractKafka { ); @Test - public void testUsage() throws Exception { + void testUsage() throws Exception { try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -43,7 +43,7 @@ public void testUsage() throws Exception { } @Test - public void testUsageWithSpecificImage() throws Exception { + void testUsageWithSpecificImage() throws Exception { try ( // constructorWithVersion { KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) @@ -59,7 +59,7 @@ public void testUsageWithSpecificImage() throws Exception { } @Test - public void testUsageWithVersion() throws Exception { + void testUsageWithVersion() throws Exception { try (KafkaContainer kafka = new KafkaContainer("6.2.1")) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -67,7 +67,7 @@ public void testUsageWithVersion() throws Exception { } @Test - public void testExternalZookeeperWithExternalNetwork() throws Exception { + void testExternalZookeeperWithExternalNetwork() throws Exception { try ( Network network = Network.newNetwork(); // withExternalZookeeper { @@ -89,7 +89,7 @@ public void testExternalZookeeperWithExternalNetwork() throws Exception { } @Test - public void testConfluentPlatformVersion7() throws Exception { + void testConfluentPlatformVersion7() throws Exception { try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.2.2"))) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -97,7 +97,7 @@ public void testConfluentPlatformVersion7() throws Exception { } @Test - public void testConfluentPlatformVersion5() throws Exception { + void testConfluentPlatformVersion5() throws Exception { try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"))) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -105,7 +105,7 @@ public void testConfluentPlatformVersion5() throws Exception { } @Test - public void testWithHostExposedPort() throws Exception { + void testWithHostExposedPort() throws Exception { Testcontainers.exposeHostPorts(12345); try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) { kafka.start(); @@ -114,7 +114,7 @@ public void testWithHostExposedPort() throws Exception { } @Test - public void testWithHostExposedPortAndExternalNetwork() throws Exception { + void testWithHostExposedPortAndExternalNetwork() throws Exception { Testcontainers.exposeHostPorts(12345); try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE).withNetwork(Network.newNetwork())) { kafka.start(); @@ -123,7 +123,7 @@ public void testWithHostExposedPortAndExternalNetwork() throws Exception { } @Test - public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception { + void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception { try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.0.1")).withKraft() ) { @@ -133,7 +133,7 @@ public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception { } @Test - public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception { + void testUsageKraftAfterConfluentPlatformVersion74() throws Exception { try ( // withKraftMode { KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")).withKraft() @@ -145,7 +145,7 @@ public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception { } @Test - public void testNotSupportedKraftVersion() { + void testNotSupportedKraftVersion() { try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")).withKraft() ) {} catch (IllegalArgumentException e) { @@ -157,7 +157,7 @@ public void testNotSupportedKraftVersion() { } @Test - public void testKraftZookeeperMutualExclusion() { + void testKraftZookeeperMutualExclusion() { try ( KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withKraft().withExternalZookeeper("") ) {} catch (IllegalStateException e) { @@ -178,7 +178,7 @@ public void testKraftZookeeperMutualExclusion() { } @Test - public void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception { + void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception { try (KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withEmbeddedZookeeper().withKraft()) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); @@ -186,7 +186,7 @@ public void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception { } @Test - public void testUsageWithListener() throws Exception { + void testUsageWithListener() throws Exception { try ( Network network = Network.newNetwork(); KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE) @@ -216,7 +216,7 @@ public void testUsageWithListener() throws Exception { @SneakyThrows @Test - public void shouldConfigureAuthenticationWithSaslUsingJaas() { + void shouldConfigureAuthenticationWithSaslUsingJaas() { try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) .withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT") @@ -234,7 +234,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() { @SneakyThrows @Test - public void shouldConfigureAuthenticationWithSaslScramUsingJaas() { + void shouldConfigureAuthenticationWithSaslScramUsingJaas() { try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.7.0")) { protected String commandKraft() { @@ -265,7 +265,7 @@ protected String commandKraft() { @SneakyThrows @Test - public void enableSaslWithUnsuccessfulTopicCreation() { + void enableSaslWithUnsuccessfulTopicCreation() { try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) .withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT") @@ -306,7 +306,7 @@ public void enableSaslWithUnsuccessfulTopicCreation() { @SneakyThrows @Test - public void enableSaslAndWithAuthenticationError() { + void enableSaslAndWithAuthenticationError() { String jaasConfig = getJaasConfig(); try ( KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) diff --git a/modules/kafka/src/test/java/org/testcontainers/kafka/CompatibleApacheKafkaImageTest.java b/modules/kafka/src/test/java/org/testcontainers/kafka/CompatibleApacheKafkaImageTest.java index b2bb31ae502..33916978acf 100644 --- a/modules/kafka/src/test/java/org/testcontainers/kafka/CompatibleApacheKafkaImageTest.java +++ b/modules/kafka/src/test/java/org/testcontainers/kafka/CompatibleApacheKafkaImageTest.java @@ -1,24 +1,19 @@ package org.testcontainers.kafka; -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 org.testcontainers.AbstractKafka; -@RunWith(Parameterized.class) public class CompatibleApacheKafkaImageTest extends AbstractKafka { - @Parameterized.Parameters(name = "{0}") public static String[] params() { return new String[] { "apache/kafka:3.8.0", "apache/kafka-native:3.8.0" }; } - @Parameterized.Parameter - public String imageName; - - @Test - public void testUsage() throws Exception { - try (KafkaContainer kafka = new KafkaContainer(this.imageName)) { + @ParameterizedTest + @MethodSource("params") + public void testUsage(String imageName) throws Exception { + try (KafkaContainer kafka = new KafkaContainer(imageName)) { kafka.start(); testKafkaFunctionality(kafka.getBootstrapServers()); } diff --git a/modules/kafka/src/test/java/org/testcontainers/kafka/ConfluentKafkaContainerTest.java b/modules/kafka/src/test/java/org/testcontainers/kafka/ConfluentKafkaContainerTest.java index 725dc2d2a62..1c95bf95e02 100644 --- a/modules/kafka/src/test/java/org/testcontainers/kafka/ConfluentKafkaContainerTest.java +++ b/modules/kafka/src/test/java/org/testcontainers/kafka/ConfluentKafkaContainerTest.java @@ -2,7 +2,7 @@ import com.github.dockerjava.api.command.InspectContainerResponse; import lombok.SneakyThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.testcontainers.AbstractKafka; import org.testcontainers.KCatContainer; import org.testcontainers.containers.Network; @@ -11,10 +11,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ConfluentKafkaContainerTest extends AbstractKafka { +class ConfluentKafkaContainerTest extends AbstractKafka { @Test - public void testUsage() throws Exception { + void testUsage() throws Exception { try ( // constructorWithVersion { ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.4.0") // } @@ -25,7 +25,7 @@ public void testUsage() throws Exception { } @Test - public void testUsageWithListener() throws Exception { + void testUsageWithListener() throws Exception { try ( Network network = Network.newNetwork(); // registerListener { @@ -48,7 +48,7 @@ public void testUsageWithListener() throws Exception { } @Test - public void testUsageWithListenerFromProxy() throws Exception { + void testUsageWithListenerFromProxy() throws Exception { try ( Network network = Network.newNetwork(); // registerListenerFromProxy { @@ -68,7 +68,7 @@ public void testUsageWithListenerFromProxy() throws Exception { @SneakyThrows @Test - public void shouldConfigureAuthenticationWithSaslUsingJaas() { + void shouldConfigureAuthenticationWithSaslUsingJaas() { try ( ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0") .withEnv( @@ -89,7 +89,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() { @SneakyThrows @Test - public void shouldConfigureAuthenticationWithSaslScramUsingJaas() { + void shouldConfigureAuthenticationWithSaslScramUsingJaas() { try ( ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0") { @SneakyThrows diff --git a/modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java b/modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java index e81b52574ef..34af2e1784d 100644 --- a/modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java +++ b/modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java @@ -1,6 +1,6 @@ package org.testcontainers.kafka; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.testcontainers.AbstractKafka; import org.testcontainers.KCatContainer; import org.testcontainers.containers.Network; @@ -8,10 +8,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class KafkaContainerTest extends AbstractKafka { +class KafkaContainerTest extends AbstractKafka { @Test - public void testUsage() throws Exception { + void testUsage() throws Exception { try ( // constructorWithVersion { KafkaContainer kafka = new KafkaContainer("apache/kafka-native:3.8.0") // } @@ -22,7 +22,7 @@ public void testUsage() throws Exception { } @Test - public void testUsageWithListener() throws Exception { + void testUsageWithListener() throws Exception { try ( Network network = Network.newNetwork(); // registerListener { @@ -45,7 +45,7 @@ public void testUsageWithListener() throws Exception { } @Test - public void testUsageWithListenerFromProxy() throws Exception { + void testUsageWithListenerFromProxy() throws Exception { try ( Network network = Network.newNetwork(); SocatContainer socat = new SocatContainer().withNetwork(network).withTarget(2000, "kafka", 19092);