-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c91d6aa
commit 20e4e94
Showing
7 changed files
with
170 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
kafka-ui-api/src/test/java/com/provectus/kafka/ui/cluster/service/ClusterServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.provectus.kafka.ui.cluster.service; | ||
|
||
import com.provectus.kafka.ui.cluster.mapper.ClusterMapper; | ||
import com.provectus.kafka.ui.cluster.model.ClustersStorage; | ||
import com.provectus.kafka.ui.cluster.model.InternalTopic; | ||
import com.provectus.kafka.ui.cluster.model.KafkaCluster; | ||
import com.provectus.kafka.ui.kafka.KafkaService; | ||
import com.provectus.kafka.ui.model.Topic; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mapstruct.factory.Mappers; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ClusterServiceTest { | ||
@InjectMocks | ||
private ClusterService clusterService; | ||
|
||
@Mock | ||
private ClustersStorage clustersStorage; | ||
@Spy | ||
private final ClusterMapper clusterMapper = Mappers.getMapper(ClusterMapper.class); | ||
@Mock | ||
private KafkaService kafkaService; | ||
@Mock | ||
private ConsumingService consumingService; | ||
|
||
@Test | ||
public void shouldListFirst20Topics() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.empty(), Optional.empty()); | ||
assertThat(topics.getPageCount()).isEqualTo(5); | ||
assertThat(topics.getTopics()).hasSize(20); | ||
assertThat(topics.getTopics()).map(Topic::getName).isSorted(); | ||
} | ||
|
||
@Test | ||
public void shouldCalculateCorrectPageCountForNonDivisiblePageSize() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.of(4), Optional.of(33)); | ||
assertThat(topics.getPageCount()).isEqualTo(4); | ||
assertThat(topics.getTopics()).hasSize(1) | ||
.first().extracting(Topic::getName).isEqualTo("99"); | ||
} | ||
|
||
@Test | ||
public void shouldCorrectlyHandleNonPositivePageNumberAndPageSize() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.of(0), Optional.of(-1)); | ||
assertThat(topics.getPageCount()).isEqualTo(5); | ||
assertThat(topics.getTopics()).hasSize(20); | ||
assertThat(topics.getTopics()).map(Topic::getName).isSorted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters