Skip to content

Commit 899a2a8

Browse files
authored
Move Kafka tests to JUnit Jupiter (#10743)
1 parent 1f8e37c commit 899a2a8

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

modules/kafka/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ description = "Testcontainers :: Kafka"
33
dependencies {
44
api project(':testcontainers')
55

6+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
7+
8+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
9+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.13.4'
610
testImplementation 'org.apache.kafka:kafka-clients:3.8.0'
711
testImplementation 'org.assertj:assertj-core:3.27.4'
812
testImplementation 'com.google.guava:guava:23.0'
913
testImplementation 'org.awaitility:awaitility:4.3.0'
1014
}
15+
16+
test {
17+
useJUnitPlatform()
18+
}

modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.apache.kafka.common.errors.SaslAuthenticationException;
1010
import org.apache.kafka.common.errors.TopicAuthorizationException;
1111
import org.awaitility.Awaitility;
12-
import org.junit.Test;
12+
import org.junit.jupiter.api.Test;
1313
import org.testcontainers.AbstractKafka;
1414
import org.testcontainers.Testcontainers;
1515
import org.testcontainers.images.builder.Transferable;
@@ -24,7 +24,7 @@
2424
import static org.assertj.core.api.Assertions.assertThat;
2525
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2626

27-
public class KafkaContainerTest extends AbstractKafka {
27+
class KafkaContainerTest extends AbstractKafka {
2828

2929
private static final DockerImageName KAFKA_TEST_IMAGE = DockerImageName.parse("confluentinc/cp-kafka:6.2.1");
3030

@@ -35,15 +35,15 @@ public class KafkaContainerTest extends AbstractKafka {
3535
);
3636

3737
@Test
38-
public void testUsage() throws Exception {
38+
void testUsage() throws Exception {
3939
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) {
4040
kafka.start();
4141
testKafkaFunctionality(kafka.getBootstrapServers());
4242
}
4343
}
4444

4545
@Test
46-
public void testUsageWithSpecificImage() throws Exception {
46+
void testUsageWithSpecificImage() throws Exception {
4747
try (
4848
// constructorWithVersion {
4949
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
@@ -59,15 +59,15 @@ public void testUsageWithSpecificImage() throws Exception {
5959
}
6060

6161
@Test
62-
public void testUsageWithVersion() throws Exception {
62+
void testUsageWithVersion() throws Exception {
6363
try (KafkaContainer kafka = new KafkaContainer("6.2.1")) {
6464
kafka.start();
6565
testKafkaFunctionality(kafka.getBootstrapServers());
6666
}
6767
}
6868

6969
@Test
70-
public void testExternalZookeeperWithExternalNetwork() throws Exception {
70+
void testExternalZookeeperWithExternalNetwork() throws Exception {
7171
try (
7272
Network network = Network.newNetwork();
7373
// withExternalZookeeper {
@@ -89,23 +89,23 @@ public void testExternalZookeeperWithExternalNetwork() throws Exception {
8989
}
9090

9191
@Test
92-
public void testConfluentPlatformVersion7() throws Exception {
92+
void testConfluentPlatformVersion7() throws Exception {
9393
try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.2.2"))) {
9494
kafka.start();
9595
testKafkaFunctionality(kafka.getBootstrapServers());
9696
}
9797
}
9898

9999
@Test
100-
public void testConfluentPlatformVersion5() throws Exception {
100+
void testConfluentPlatformVersion5() throws Exception {
101101
try (KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"))) {
102102
kafka.start();
103103
testKafkaFunctionality(kafka.getBootstrapServers());
104104
}
105105
}
106106

107107
@Test
108-
public void testWithHostExposedPort() throws Exception {
108+
void testWithHostExposedPort() throws Exception {
109109
Testcontainers.exposeHostPorts(12345);
110110
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE)) {
111111
kafka.start();
@@ -114,7 +114,7 @@ public void testWithHostExposedPort() throws Exception {
114114
}
115115

116116
@Test
117-
public void testWithHostExposedPortAndExternalNetwork() throws Exception {
117+
void testWithHostExposedPortAndExternalNetwork() throws Exception {
118118
Testcontainers.exposeHostPorts(12345);
119119
try (KafkaContainer kafka = new KafkaContainer(KAFKA_TEST_IMAGE).withNetwork(Network.newNetwork())) {
120120
kafka.start();
@@ -123,7 +123,7 @@ public void testWithHostExposedPortAndExternalNetwork() throws Exception {
123123
}
124124

125125
@Test
126-
public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
126+
void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
127127
try (
128128
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.0.1")).withKraft()
129129
) {
@@ -133,7 +133,7 @@ public void testUsageKraftBeforeConfluentPlatformVersion74() throws Exception {
133133
}
134134

135135
@Test
136-
public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
136+
void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
137137
try (
138138
// withKraftMode {
139139
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")).withKraft()
@@ -145,7 +145,7 @@ public void testUsageKraftAfterConfluentPlatformVersion74() throws Exception {
145145
}
146146

147147
@Test
148-
public void testNotSupportedKraftVersion() {
148+
void testNotSupportedKraftVersion() {
149149
try (
150150
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")).withKraft()
151151
) {} catch (IllegalArgumentException e) {
@@ -157,7 +157,7 @@ public void testNotSupportedKraftVersion() {
157157
}
158158

159159
@Test
160-
public void testKraftZookeeperMutualExclusion() {
160+
void testKraftZookeeperMutualExclusion() {
161161
try (
162162
KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withKraft().withExternalZookeeper("")
163163
) {} catch (IllegalStateException e) {
@@ -178,15 +178,15 @@ public void testKraftZookeeperMutualExclusion() {
178178
}
179179

180180
@Test
181-
public void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception {
181+
void testKraftPrecedenceOverEmbeddedZookeeper() throws Exception {
182182
try (KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE).withEmbeddedZookeeper().withKraft()) {
183183
kafka.start();
184184
testKafkaFunctionality(kafka.getBootstrapServers());
185185
}
186186
}
187187

188188
@Test
189-
public void testUsageWithListener() throws Exception {
189+
void testUsageWithListener() throws Exception {
190190
try (
191191
Network network = Network.newNetwork();
192192
KafkaContainer kafka = new KafkaContainer(KAFKA_KRAFT_TEST_IMAGE)
@@ -216,7 +216,7 @@ public void testUsageWithListener() throws Exception {
216216

217217
@SneakyThrows
218218
@Test
219-
public void shouldConfigureAuthenticationWithSaslUsingJaas() {
219+
void shouldConfigureAuthenticationWithSaslUsingJaas() {
220220
try (
221221
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
222222
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT")
@@ -234,7 +234,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() {
234234

235235
@SneakyThrows
236236
@Test
237-
public void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
237+
void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
238238
try (
239239
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.7.0")) {
240240
protected String commandKraft() {
@@ -265,7 +265,7 @@ protected String commandKraft() {
265265

266266
@SneakyThrows
267267
@Test
268-
public void enableSaslWithUnsuccessfulTopicCreation() {
268+
void enableSaslWithUnsuccessfulTopicCreation() {
269269
try (
270270
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
271271
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:SASL_PLAINTEXT")
@@ -306,7 +306,7 @@ public void enableSaslWithUnsuccessfulTopicCreation() {
306306

307307
@SneakyThrows
308308
@Test
309-
public void enableSaslAndWithAuthenticationError() {
309+
void enableSaslAndWithAuthenticationError() {
310310
String jaasConfig = getJaasConfig();
311311
try (
312312
KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))

modules/kafka/src/test/java/org/testcontainers/kafka/CompatibleApacheKafkaImageTest.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
package org.testcontainers.kafka;
22

3-
import org.junit.Test;
4-
import org.junit.runner.RunWith;
5-
import org.junit.runners.Parameterized;
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.MethodSource;
65
import org.testcontainers.AbstractKafka;
76

8-
@RunWith(Parameterized.class)
97
public class CompatibleApacheKafkaImageTest extends AbstractKafka {
108

11-
@Parameterized.Parameters(name = "{0}")
129
public static String[] params() {
1310
return new String[] { "apache/kafka:3.8.0", "apache/kafka-native:3.8.0" };
1411
}
1512

16-
@Parameterized.Parameter
17-
public String imageName;
18-
19-
@Test
20-
public void testUsage() throws Exception {
21-
try (KafkaContainer kafka = new KafkaContainer(this.imageName)) {
13+
@ParameterizedTest
14+
@MethodSource("params")
15+
public void testUsage(String imageName) throws Exception {
16+
try (KafkaContainer kafka = new KafkaContainer(imageName)) {
2217
kafka.start();
2318
testKafkaFunctionality(kafka.getBootstrapServers());
2419
}

modules/kafka/src/test/java/org/testcontainers/kafka/ConfluentKafkaContainerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.github.dockerjava.api.command.InspectContainerResponse;
44
import lombok.SneakyThrows;
5-
import org.junit.Test;
5+
import org.junit.jupiter.api.Test;
66
import org.testcontainers.AbstractKafka;
77
import org.testcontainers.KCatContainer;
88
import org.testcontainers.containers.Network;
@@ -11,10 +11,10 @@
1111

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

14-
public class ConfluentKafkaContainerTest extends AbstractKafka {
14+
class ConfluentKafkaContainerTest extends AbstractKafka {
1515

1616
@Test
17-
public void testUsage() throws Exception {
17+
void testUsage() throws Exception {
1818
try ( // constructorWithVersion {
1919
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.4.0")
2020
// }
@@ -25,7 +25,7 @@ public void testUsage() throws Exception {
2525
}
2626

2727
@Test
28-
public void testUsageWithListener() throws Exception {
28+
void testUsageWithListener() throws Exception {
2929
try (
3030
Network network = Network.newNetwork();
3131
// registerListener {
@@ -48,7 +48,7 @@ public void testUsageWithListener() throws Exception {
4848
}
4949

5050
@Test
51-
public void testUsageWithListenerFromProxy() throws Exception {
51+
void testUsageWithListenerFromProxy() throws Exception {
5252
try (
5353
Network network = Network.newNetwork();
5454
// registerListenerFromProxy {
@@ -68,7 +68,7 @@ public void testUsageWithListenerFromProxy() throws Exception {
6868

6969
@SneakyThrows
7070
@Test
71-
public void shouldConfigureAuthenticationWithSaslUsingJaas() {
71+
void shouldConfigureAuthenticationWithSaslUsingJaas() {
7272
try (
7373
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0")
7474
.withEnv(
@@ -89,7 +89,7 @@ public void shouldConfigureAuthenticationWithSaslUsingJaas() {
8989

9090
@SneakyThrows
9191
@Test
92-
public void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
92+
void shouldConfigureAuthenticationWithSaslScramUsingJaas() {
9393
try (
9494
ConfluentKafkaContainer kafka = new ConfluentKafkaContainer("confluentinc/cp-kafka:7.7.0") {
9595
@SneakyThrows

modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package org.testcontainers.kafka;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.testcontainers.AbstractKafka;
55
import org.testcontainers.KCatContainer;
66
import org.testcontainers.containers.Network;
77
import org.testcontainers.containers.SocatContainer;
88

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

11-
public class KafkaContainerTest extends AbstractKafka {
11+
class KafkaContainerTest extends AbstractKafka {
1212

1313
@Test
14-
public void testUsage() throws Exception {
14+
void testUsage() throws Exception {
1515
try ( // constructorWithVersion {
1616
KafkaContainer kafka = new KafkaContainer("apache/kafka-native:3.8.0")
1717
// }
@@ -22,7 +22,7 @@ public void testUsage() throws Exception {
2222
}
2323

2424
@Test
25-
public void testUsageWithListener() throws Exception {
25+
void testUsageWithListener() throws Exception {
2626
try (
2727
Network network = Network.newNetwork();
2828
// registerListener {
@@ -45,7 +45,7 @@ public void testUsageWithListener() throws Exception {
4545
}
4646

4747
@Test
48-
public void testUsageWithListenerFromProxy() throws Exception {
48+
void testUsageWithListenerFromProxy() throws Exception {
4949
try (
5050
Network network = Network.newNetwork();
5151
SocatContainer socat = new SocatContainer().withNetwork(network).withTarget(2000, "kafka", 19092);

0 commit comments

Comments
 (0)