From 73bebbb83384a953933815892d612d9b0eb9280d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Greffier?= Date: Sun, 8 Oct 2023 20:34:55 +0200 Subject: [PATCH] Improve tests --- .../services/executors/UserAsyncExecutor.java | 4 +-- .../executors/TopicAsyncExecutorTest.java | 31 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/michelin/ns4kafka/services/executors/UserAsyncExecutor.java b/src/main/java/com/michelin/ns4kafka/services/executors/UserAsyncExecutor.java index d2dde4f4..2b3f6296 100644 --- a/src/main/java/com/michelin/ns4kafka/services/executors/UserAsyncExecutor.java +++ b/src/main/java/com/michelin/ns4kafka/services/executors/UserAsyncExecutor.java @@ -137,7 +137,7 @@ private Map> collectNs4kafkaQuotas() { .stream() .filter(q -> q.getKey().startsWith(USER_QUOTA_PREFIX)) .forEach(q -> userQuota.put( - q.getKey().replaceAll(USER_QUOTA_PREFIX, ""), + q.getKey().replace(USER_QUOTA_PREFIX, ""), Double.parseDouble(q.getValue())))); return Map.entry(namespace.getSpec().getKafkaUser(), userQuota); @@ -165,7 +165,7 @@ static class Scram512UserSynchronizer implements AbstractUserSynchronizer { private final ScramCredentialInfo info = new ScramCredentialInfo(ScramMechanism.SCRAM_SHA_512, 4096); private final SecureRandom secureRandom = new SecureRandom(); - private Admin admin; + private final Admin admin; public Scram512UserSynchronizer(Admin admin) { this.admin = admin; diff --git a/src/test/java/com/michelin/ns4kafka/services/executors/TopicAsyncExecutorTest.java b/src/test/java/com/michelin/ns4kafka/services/executors/TopicAsyncExecutorTest.java index 2b43f9d3..0f4e1686 100644 --- a/src/test/java/com/michelin/ns4kafka/services/executors/TopicAsyncExecutorTest.java +++ b/src/test/java/com/michelin/ns4kafka/services/executors/TopicAsyncExecutorTest.java @@ -18,6 +18,7 @@ import com.michelin.ns4kafka.properties.ManagedClusterProperties; import com.michelin.ns4kafka.services.clients.schema.SchemaRegistryClient; import com.michelin.ns4kafka.services.clients.schema.entities.TagTopicInfo; +import io.micronaut.http.HttpResponse; import java.util.List; import java.util.Map; import java.util.Properties; @@ -195,7 +196,7 @@ void shouldDeleteTopicAndTags() throws ExecutionException, InterruptedException, when(managedClusterProperties.getConfig()).thenReturn(properties); when(schemaRegistryClient.deleteTag(anyString(), anyString(), anyString())) - .thenReturn(Mono.empty()) + .thenReturn(Mono.just(HttpResponse.ok())) .thenReturn(Mono.error(new Exception("error"))); Topic topic = Topic.builder() @@ -256,7 +257,33 @@ void shouldEnrichWithTagsWhenConfluentCloud() { .build()); topicAsyncExecutor.enrichWithTags(brokerTopics); - + assertEquals("typeName", brokerTopics.get(TOPIC_NAME).getSpec().getTags().get(0)); } + + @Test + void shouldEnrichWithTagsWhenConfluentCloudAndResponseIsNull() { + Properties properties = new Properties(); + properties.put(CLUSTER_ID, CLUSTER_ID_TEST); + + when(managedClusterProperties.getProvider()).thenReturn(ManagedClusterProperties.KafkaProvider.CONFLUENT_CLOUD); + when(managedClusterProperties.getName()).thenReturn(LOCAL_CLUSTER); + when(managedClusterProperties.getConfig()).thenReturn(properties); + + when(schemaRegistryClient.getTopicWithTags(LOCAL_CLUSTER, CLUSTER_ID_TEST + ":" + TOPIC_NAME)) + .thenReturn(Mono.empty()); + + Map brokerTopics = Map.of(TOPIC_NAME, + Topic.builder() + .metadata(ObjectMeta.builder() + .name(TOPIC_NAME) + .build()) + .spec(Topic.TopicSpec.builder() + .build()) + .build()); + + topicAsyncExecutor.enrichWithTags(brokerTopics); + + assertTrue(brokerTopics.get(TOPIC_NAME).getSpec().getTags().isEmpty()); + } }