KafkaTopicCreateTests.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.provectus.kafka.ui;
  2. import com.provectus.kafka.ui.model.TopicCreationDTO;
  3. import java.util.UUID;
  4. import org.junit.jupiter.api.BeforeEach;
  5. import org.junit.jupiter.api.Test;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.test.web.reactive.server.WebTestClient;
  8. public class KafkaTopicCreateTests extends AbstractIntegrationTest {
  9. @Autowired
  10. private WebTestClient webTestClient;
  11. private TopicCreationDTO topicCreation;
  12. @BeforeEach
  13. public void setUpBefore() {
  14. this.topicCreation = new TopicCreationDTO()
  15. .replicationFactor(1)
  16. .partitions(3)
  17. .name(UUID.randomUUID().toString());
  18. }
  19. @Test
  20. void shouldCreateNewTopicSuccessfully() {
  21. webTestClient.post()
  22. .uri("/api/clusters/{clusterName}/topics", LOCAL)
  23. .bodyValue(topicCreation)
  24. .exchange()
  25. .expectStatus()
  26. .isOk();
  27. }
  28. @Test
  29. void shouldReturn400IfTopicAlreadyExists() {
  30. TopicCreationDTO topicCreation = new TopicCreationDTO()
  31. .replicationFactor(1)
  32. .partitions(3)
  33. .name(UUID.randomUUID().toString());
  34. webTestClient.post()
  35. .uri("/api/clusters/{clusterName}/topics", LOCAL)
  36. .bodyValue(topicCreation)
  37. .exchange()
  38. .expectStatus()
  39. .isOk();
  40. webTestClient.post()
  41. .uri("/api/clusters/{clusterName}/topics", LOCAL)
  42. .bodyValue(topicCreation)
  43. .exchange()
  44. .expectStatus()
  45. .isBadRequest();
  46. }
  47. @Test
  48. void shouldRecreateExistingTopicSuccessfully() {
  49. TopicCreationDTO topicCreation = new TopicCreationDTO()
  50. .replicationFactor(1)
  51. .partitions(3)
  52. .name(UUID.randomUUID().toString());
  53. webTestClient.post()
  54. .uri("/api/clusters/{clusterName}/topics", LOCAL)
  55. .bodyValue(topicCreation)
  56. .exchange()
  57. .expectStatus()
  58. .isOk();
  59. webTestClient.post()
  60. .uri("/api/clusters/{clusterName}/topics/" + topicCreation.getName(), LOCAL)
  61. .exchange()
  62. .expectStatus()
  63. .isCreated()
  64. .expectBody()
  65. .jsonPath("partitionCount").isEqualTo(topicCreation.getPartitions().toString())
  66. .jsonPath("replicationFactor").isEqualTo(topicCreation.getReplicationFactor().toString())
  67. .jsonPath("name").isEqualTo(topicCreation.getName());
  68. }
  69. @Test
  70. void shouldCloneExistingTopicSuccessfully() {
  71. TopicCreationDTO topicCreation = new TopicCreationDTO()
  72. .replicationFactor(1)
  73. .partitions(3)
  74. .name(UUID.randomUUID().toString());
  75. String clonedTopicName = UUID.randomUUID().toString();
  76. webTestClient.post()
  77. .uri("/api/clusters/{clusterName}/topics", LOCAL)
  78. .bodyValue(topicCreation)
  79. .exchange()
  80. .expectStatus()
  81. .isOk();
  82. webTestClient.post()
  83. .uri("/api/clusters/{clusterName}/topics/{topicName}/clone?newTopicName=" + clonedTopicName,
  84. LOCAL, topicCreation.getName())
  85. .exchange()
  86. .expectStatus()
  87. .isCreated()
  88. .expectBody()
  89. .jsonPath("partitionCount").isEqualTo(topicCreation.getPartitions().toString())
  90. .jsonPath("replicationFactor").isEqualTo(topicCreation.getReplicationFactor().toString())
  91. .jsonPath("name").isEqualTo(clonedTopicName);
  92. }
  93. }