diff --git a/src/main/java/com/michelin/ns4kafka/repository/ResourceQuotaRepository.java b/src/main/java/com/michelin/ns4kafka/repository/ResourceQuotaRepository.java index 6ffbc155..fa6f948d 100644 --- a/src/main/java/com/michelin/ns4kafka/repository/ResourceQuotaRepository.java +++ b/src/main/java/com/michelin/ns4kafka/repository/ResourceQuotaRepository.java @@ -15,15 +15,6 @@ public interface ResourceQuotaRepository { */ List findAll(); - /** - * Get resource quota by namespace. - * - * @param namespace The namespace used to research - * @return The resource quotas associated to the namespace - */ - List findAllForNamespace(String namespace); - - /** * Get resource quota by namespace. * diff --git a/src/main/java/com/michelin/ns4kafka/repository/kafka/KafkaResourceQuotaRepository.java b/src/main/java/com/michelin/ns4kafka/repository/kafka/KafkaResourceQuotaRepository.java index 7285d77e..39c48e4b 100644 --- a/src/main/java/com/michelin/ns4kafka/repository/kafka/KafkaResourceQuotaRepository.java +++ b/src/main/java/com/michelin/ns4kafka/repository/kafka/KafkaResourceQuotaRepository.java @@ -53,21 +53,7 @@ public List findAll() { } /** - * Get resource quota by namespace. - * - * @param namespace The namespace used to research - * @return A resource quota - */ - @Override - public List findAllForNamespace(String namespace) { - return getKafkaStore().values() - .stream() - .filter(resourceQuota -> resourceQuota.getMetadata().getNamespace().equals(namespace)) - .toList(); - } - - /** - * Get resource quota by namespace. + * Get resource quota of a given namespace. * * @param namespace The namespace used to research * @return A resource quota diff --git a/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java b/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java index da577e6c..8a90094d 100644 --- a/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java +++ b/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java @@ -71,7 +71,10 @@ public Optional findForNamespace(String namespace) { * @return The researched resource quota */ public List findAllForNamespace(String namespace) { - return resourceQuotaRepository.findAllForNamespace(namespace); + return resourceQuotaRepository.findAll() + .stream() + .filter(resourceQuota -> resourceQuota.getMetadata().getNamespace().equals(namespace)) + .toList(); } /** diff --git a/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java b/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java index 90d5ad80..2e1f4b17 100644 --- a/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java +++ b/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java @@ -84,6 +84,7 @@ void shouldListQuotasWithoutParameter() { ResourceQuota resourceQuota1 = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") + .namespace("namespace") .name("quotaName") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) @@ -92,12 +93,13 @@ void shouldListQuotasWithoutParameter() { ResourceQuota resourceQuota2 = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") + .namespace("namespace") .name("quotaName2") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); - when(resourceQuotaRepository.findAllForNamespace("namespace")) + when(resourceQuotaRepository.findAll()) .thenReturn(List.of(resourceQuota1, resourceQuota2)); assertEquals(List.of(resourceQuota1, resourceQuota2), @@ -109,12 +111,13 @@ void shouldListQuotasWithNameParameter() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") + .namespace("namespace") .name("quotaName") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); - when(resourceQuotaRepository.findAllForNamespace("namespace")) + when(resourceQuotaRepository.findAll()) .thenReturn(List.of(resourceQuota)); assertEquals(List.of(resourceQuota), @@ -128,6 +131,7 @@ void shouldListQuotasWithWildcardNameParameter() { .metadata(Metadata.builder() .cluster("local") .name("quotaName1") + .namespace("namespace") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); @@ -136,6 +140,7 @@ void shouldListQuotasWithWildcardNameParameter() { .metadata(Metadata.builder() .cluster("local") .name("quotaName2") + .namespace("namespace") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); @@ -144,11 +149,12 @@ void shouldListQuotasWithWildcardNameParameter() { .metadata(Metadata.builder() .cluster("local") .name("topicQuota2") + .namespace("namespace") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); - when(resourceQuotaRepository.findAllForNamespace("namespace")) + when(resourceQuotaRepository.findAll()) .thenReturn(List.of(resourceQuota1, resourceQuota2, resourceQuota3)); assertEquals(List.of(resourceQuota1, resourceQuota2, resourceQuota3),