kafka-ui/kafka-ui-api/src/test/java/com/provectus/kafka/ui/KafkaTopicCreateTests.java
Ilya Kuramshin a8fc61dcff
Integration tests structure unified, unnecessary imports removed (#1711)
Co-authored-by: iliax <ikuramshin@provectus.com>
2022-03-09 15:47:36 +03:00

79 lines
2.4 KiB
Java

package com.provectus.kafka.ui;
import com.provectus.kafka.ui.model.TopicCreationDTO;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.reactive.server.WebTestClient;
public class KafkaTopicCreateTests extends AbstractIntegrationTest {
@Autowired
private WebTestClient webTestClient;
private TopicCreationDTO topicCreation;
@BeforeEach
public void setUpBefore() {
this.topicCreation = new TopicCreationDTO()
.replicationFactor(1)
.partitions(3)
.name(UUID.randomUUID().toString());
}
@Test
void shouldCreateNewTopicSuccessfully() {
webTestClient.post()
.uri("/api/clusters/{clusterName}/topics", LOCAL)
.bodyValue(topicCreation)
.exchange()
.expectStatus()
.isOk();
}
@Test
void shouldReturn400IfTopicAlreadyExists() {
TopicCreationDTO topicCreation = new TopicCreationDTO()
.replicationFactor(1)
.partitions(3)
.name(UUID.randomUUID().toString());
webTestClient.post()
.uri("/api/clusters/{clusterName}/topics", LOCAL)
.bodyValue(topicCreation)
.exchange()
.expectStatus()
.isOk();
webTestClient.post()
.uri("/api/clusters/{clusterName}/topics", LOCAL)
.bodyValue(topicCreation)
.exchange()
.expectStatus()
.isBadRequest();
}
@Test
void shouldRecreateExistingTopicSuccessfully() {
TopicCreationDTO topicCreation = new TopicCreationDTO()
.replicationFactor(1)
.partitions(3)
.name(UUID.randomUUID().toString());
webTestClient.post()
.uri("/api/clusters/{clusterName}/topics", LOCAL)
.bodyValue(topicCreation)
.exchange()
.expectStatus()
.isOk();
webTestClient.post()
.uri("/api/clusters/{clusterName}/topics/" + topicCreation.getName(), LOCAL)
.exchange()
.expectStatus()
.isCreated()
.expectBody()
.jsonPath("partitionCount").isEqualTo(topicCreation.getPartitions().toString())
.jsonPath("replicationFactor").isEqualTo(topicCreation.getReplicationFactor().toString())
.jsonPath("name").isEqualTo(topicCreation.getName());
}
}