-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopicsCreatorTest.java
48 lines (38 loc) · 1.47 KB
/
TopicsCreatorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pl.dirtyread.sandbox.java.kafka.admins;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import static org.testcontainers.shaded.org.hamcrest.MatcherAssert.assertThat;
import static org.testcontainers.shaded.org.hamcrest.core.StringContains.containsString;
/**
* @author Dirty Read
*/
public class TopicsCreatorTest {
@Container
private static final KafkaContainer KAFKA_CONTAINER =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0"));
@Test
public void shouldGivenProperlyTopicName_whenCreateNewTopic() throws IOException, InterruptedException {
//given
String topicName = "test-topic";
System.out.println(KAFKA_CONTAINER.getExposedPorts());
TopicsCreator.addTopic(KAFKA_CONTAINER.getBootstrapServers(), topicName, 1, (short) 1);
//when
String commandToListingTopics = "/usr/bin/kafka-topics --bootstrap-server=localhost:9092 --list";
String topicList = KAFKA_CONTAINER.execInContainer("/bin/sh", "-c", commandToListingTopics).getStdout();
//then
assertThat(topicList, containsString(topicName));
}
@Before
public void up() {
KAFKA_CONTAINER.start();
}
@After
public void tearDown() {
KAFKA_CONTAINER.stop();
}
}