diff --git a/src/main/java/com/michelin/ns4kafka/controller/quota/ResourceQuotaController.java b/src/main/java/com/michelin/ns4kafka/controller/quota/ResourceQuotaController.java index 991f3f2e..647062f5 100644 --- a/src/main/java/com/michelin/ns4kafka/controller/quota/ResourceQuotaController.java +++ b/src/main/java/com/michelin/ns4kafka/controller/quota/ResourceQuotaController.java @@ -43,9 +43,12 @@ public class ResourceQuotaController extends NamespacedResourceController { * @return A list of quotas */ @Get - public List list(String namespace) { - return List.of(resourceQuotaService.getUsedResourcesByQuotaByNamespace(getNamespace(namespace), - resourceQuotaService.findByNamespace(namespace))); + public List list(String namespace, @QueryValue(defaultValue = "*") String name) { + return resourceQuotaService.findByWildcardName(namespace, name) + .stream() + .map(resourceQuota -> resourceQuotaService.getUsedResourcesByQuotaByNamespace(getNamespace(namespace), + Optional.of(resourceQuota))) + .toList(); } /** @@ -54,8 +57,10 @@ public List list(String namespace) { * @param namespace The name * @param quota The quota name * @return A quota + * @deprecated use list(String, String name) instead. */ @Get("/{quota}") + @Deprecated(since = "1.12.0") public Optional get(String namespace, String quota) { Optional resourceQuota = resourceQuotaService.findByName(namespace, quota); if (resourceQuota.isEmpty()) { @@ -87,7 +92,7 @@ public HttpResponse apply(String namespace, @Body @Valid Resource throw new ResourceValidationException(quota, validationErrors); } - Optional resourceQuotaOptional = resourceQuotaService.findByNamespace(namespace); + Optional resourceQuotaOptional = resourceQuotaService.findForNamespace(namespace); if (resourceQuotaOptional.isPresent() && resourceQuotaOptional.get().equals(quota)) { return formatHttpResponse(quota, ApplyStatus.unchanged); } 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 eedc6756..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,7 +53,7 @@ public List findAll() { } /** - * 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/NamespaceService.java b/src/main/java/com/michelin/ns4kafka/service/NamespaceService.java index 48a3282d..009ab78c 100644 --- a/src/main/java/com/michelin/ns4kafka/service/NamespaceService.java +++ b/src/main/java/com/michelin/ns4kafka/service/NamespaceService.java @@ -185,7 +185,7 @@ public List findAllResourcesByNamespace(Namespace namespace) { .map(connectCluster -> CONNECT_CLUSTER + "/" + connectCluster.getMetadata().getName()), aclService.findAllForNamespace(namespace).stream() .map(ace -> ACCESS_CONTROL_ENTRY + "/" + ace.getMetadata().getName()), - resourceQuotaService.findByNamespace(namespace.getMetadata().getName()).stream() + resourceQuotaService.findForNamespace(namespace.getMetadata().getName()).stream() .map(resourceQuota -> RESOURCE_QUOTA + "/" + resourceQuota.getMetadata().getName()), roleBindingService.findAllForNamespace(namespace.getMetadata().getName()).stream() .map(roleBinding -> ROLE_BINDING + "/" + roleBinding.getMetadata().getName()) diff --git a/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java b/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java index 30701fbe..cb339b99 100644 --- a/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java +++ b/src/main/java/com/michelin/ns4kafka/service/ResourceQuotaService.java @@ -25,6 +25,7 @@ import com.michelin.ns4kafka.repository.ResourceQuotaRepository; import com.michelin.ns4kafka.service.executor.UserAsyncExecutor; import com.michelin.ns4kafka.util.BytesUtils; +import com.michelin.ns4kafka.util.RegexUtils; import io.micronaut.core.util.StringUtils; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -54,15 +55,30 @@ public class ResourceQuotaService { ConnectorService connectorService; /** - * Find a resource quota by namespace. + * Find a resource quota of a given namespace. * * @param namespace The namespace used to research * @return The researched resource quota */ - public Optional findByNamespace(String namespace) { + public Optional findForNamespace(String namespace) { return resourceQuotaRepository.findForNamespace(namespace); } + /** + * Find a resource quota of a given namespace, filtered by name. + * + * @param namespace The namespace + * @param name The name parameter + * @return The researched resource quota + */ + public List findByWildcardName(String namespace, String name) { + List nameFilterPatterns = RegexUtils.wildcardStringsToRegexPatterns(List.of(name)); + return findForNamespace(namespace) + .stream() + .filter(quota -> RegexUtils.filterByPattern(quota.getMetadata().getName(), nameFilterPatterns)) + .toList(); + } + /** * Find a resource quota by namespace and name. * @@ -71,7 +87,7 @@ public Optional findByNamespace(String namespace) { * @return The researched resource quota */ public Optional findByName(String namespace, String quota) { - return findByNamespace(namespace) + return findForNamespace(namespace) .stream() .filter(resourceQuota -> resourceQuota.getMetadata().getName().equals(quota)) .findFirst(); @@ -227,7 +243,7 @@ public long getCurrentCountConnectorsByNamespace(Namespace namespace) { * @return A list of errors */ public List validateTopicQuota(Namespace namespace, Optional existingTopic, Topic newTopic) { - Optional resourceQuotaOptional = findByNamespace(namespace.getMetadata().getName()); + Optional resourceQuotaOptional = findForNamespace(namespace.getMetadata().getName()); if (resourceQuotaOptional.isEmpty()) { return List.of(); } @@ -284,7 +300,7 @@ public List validateTopicQuota(Namespace namespace, Optional exis * @return A list of errors */ public List validateConnectorQuota(Namespace namespace) { - Optional resourceQuotaOptional = findByNamespace(namespace.getMetadata().getName()); + Optional resourceQuotaOptional = findForNamespace(namespace.getMetadata().getName()); if (resourceQuotaOptional.isEmpty()) { return List.of(); } @@ -312,7 +328,7 @@ public List getUsedQuotaByNamespaces(List name return namespaces .stream() .map(namespace -> getUsedResourcesByQuotaByNamespace(namespace, - findByNamespace(namespace.getMetadata().getName()))) + findForNamespace(namespace.getMetadata().getName()))) .toList(); } diff --git a/src/test/java/com/michelin/ns4kafka/controller/ResourceQuotaControllerTest.java b/src/test/java/com/michelin/ns4kafka/controller/ResourceQuotaControllerTest.java index da386d58..4944ae92 100644 --- a/src/test/java/com/michelin/ns4kafka/controller/ResourceQuotaControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controller/ResourceQuotaControllerTest.java @@ -53,7 +53,7 @@ class ResourceQuotaControllerTest { ApplicationEventPublisher applicationEventPublisher; @Test - void list() { + void shouldListQuotaWithoutNameParameter() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -61,6 +61,44 @@ void list() { .build()) .build(); + ResourceQuota quota = ResourceQuota.builder() + .metadata(Metadata.builder() + .cluster("local") + .name("test") + .build()) + .build(); + + ResourceQuotaResponse response = ResourceQuotaResponse.builder() + .spec(ResourceQuotaResponse.ResourceQuotaResponseSpec.builder() + .countTopic("0/INF") + .countPartition("0/INF") + .countConnector("0/INF") + .build()) + .build(); + + when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); + when(resourceQuotaService.findByWildcardName("test", "*")).thenReturn(List.of(quota)); + when(resourceQuotaService.getUsedResourcesByQuotaByNamespace(ns, Optional.of(quota))).thenReturn(response); + + assertEquals(List.of(response), resourceQuotaController.list("test", "*")); + } + + @Test + void shouldListQuotaWithNameParameter() { + Namespace ns = Namespace.builder() + .metadata(Metadata.builder() + .name("test") + .cluster("local") + .build()) + .build(); + + ResourceQuota quota = ResourceQuota.builder() + .metadata(Metadata.builder() + .cluster("local") + .name("quotaName") + .build()) + .build(); + ResourceQuotaResponse response = ResourceQuotaResponse.builder() .spec(ResourceQuotaResponse.ResourceQuotaResponseSpec.builder() .countTopic("0/INF") @@ -70,16 +108,17 @@ void list() { .build(); when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); - when(resourceQuotaService.findByNamespace(ns.getMetadata().getName())).thenReturn(Optional.empty()); - when(resourceQuotaService.getUsedResourcesByQuotaByNamespace(ns, Optional.empty())).thenReturn(response); + when(resourceQuotaService.findByWildcardName("test", "quotaName")).thenReturn(List.of(quota)); + when(resourceQuotaService.findByWildcardName("test", "not-found")).thenReturn(List.of()); + when(resourceQuotaService.getUsedResourcesByQuotaByNamespace(ns, Optional.of(quota))).thenReturn(response); - List actual = resourceQuotaController.list("test"); - assertEquals(1, actual.size()); - assertEquals(response, actual.get(0)); + assertEquals(List.of(response), resourceQuotaController.list("test", "quotaName")); + assertTrue(resourceQuotaController.list("test", "not-found").isEmpty()); } @Test - void getEmpty() { + @SuppressWarnings("deprecation") + void shouldGetQuotaWhenEmpty() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -94,7 +133,8 @@ void getEmpty() { } @Test - void getPresent() { + @SuppressWarnings("deprecation") + void shouldGetQuotaWhenPresent() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -128,7 +168,7 @@ void getPresent() { } @Test - void applyValidationErrors() { + void shouldApplyValidationErrors() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -157,7 +197,7 @@ void applyValidationErrors() { } @Test - void applyUnchanged() { + void shouldApplyUnchanged() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -175,7 +215,7 @@ void applyUnchanged() { when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); when(resourceQuotaService.validateNewResourceQuota(ns, resourceQuota)).thenReturn(List.of()); - when(resourceQuotaService.findByNamespace(ns.getMetadata().getName())).thenReturn(Optional.of(resourceQuota)); + when(resourceQuotaService.findForNamespace(ns.getMetadata().getName())).thenReturn(Optional.of(resourceQuota)); var response = resourceQuotaController.apply("test", resourceQuota, false); assertEquals("unchanged", response.header("X-Ns4kafka-Result")); @@ -184,7 +224,7 @@ void applyUnchanged() { } @Test - void applyDryRun() { + void shouldApplyDryRun() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -202,7 +242,7 @@ void applyDryRun() { when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); when(resourceQuotaService.validateNewResourceQuota(ns, resourceQuota)).thenReturn(List.of()); - when(resourceQuotaService.findByNamespace(ns.getMetadata().getName())).thenReturn(Optional.empty()); + when(resourceQuotaService.findForNamespace(ns.getMetadata().getName())).thenReturn(Optional.empty()); var response = resourceQuotaController.apply("test", resourceQuota, true); assertEquals("created", response.header("X-Ns4kafka-Result")); @@ -210,7 +250,7 @@ void applyDryRun() { } @Test - void applyCreated() { + void shouldApplyCreated() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -228,7 +268,7 @@ void applyCreated() { when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); when(resourceQuotaService.validateNewResourceQuota(ns, resourceQuota)).thenReturn(List.of()); - when(resourceQuotaService.findByNamespace(ns.getMetadata().getName())).thenReturn(Optional.empty()); + when(resourceQuotaService.findForNamespace(ns.getMetadata().getName())).thenReturn(Optional.empty()); when(securityService.username()).thenReturn(Optional.of("test-user")); when(securityService.hasRole(ResourceBasedSecurityRule.IS_ADMIN)).thenReturn(false); doNothing().when(applicationEventPublisher).publishEvent(any()); @@ -241,7 +281,7 @@ void applyCreated() { } @Test - void applyUpdated() { + void shouldApplyUpdated() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("test") @@ -267,7 +307,7 @@ void applyUpdated() { when(namespaceService.findByName("test")).thenReturn(Optional.of(ns)); when(resourceQuotaService.validateNewResourceQuota(ns, resourceQuota)).thenReturn(List.of()); - when(resourceQuotaService.findByNamespace(ns.getMetadata().getName())).thenReturn( + when(resourceQuotaService.findForNamespace(ns.getMetadata().getName())).thenReturn( Optional.of(resourceQuotaExisting)); when(securityService.username()).thenReturn(Optional.of("test-user")); when(securityService.hasRole(ResourceBasedSecurityRule.IS_ADMIN)).thenReturn(false); @@ -282,7 +322,7 @@ void applyUpdated() { } @Test - void deleteNotFound() { + void shouldDeleteWhenNotFound() { when(resourceQuotaService.findByName("test", "quota")).thenReturn(Optional.empty()); HttpResponse actual = resourceQuotaController.delete("test", "quota", false); assertEquals(HttpStatus.NOT_FOUND, actual.getStatus()); @@ -290,7 +330,7 @@ void deleteNotFound() { } @Test - void deleteDryRun() { + void shouldDeleteWhenDryRun() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") @@ -306,7 +346,7 @@ void deleteDryRun() { } @Test - void delete() { + void shouldDelete() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") diff --git a/src/test/java/com/michelin/ns4kafka/service/NamespaceServiceTest.java b/src/test/java/com/michelin/ns4kafka/service/NamespaceServiceTest.java index 852d7353..cce0eb96 100644 --- a/src/test/java/com/michelin/ns4kafka/service/NamespaceServiceTest.java +++ b/src/test/java/com/michelin/ns4kafka/service/NamespaceServiceTest.java @@ -539,7 +539,7 @@ void shouldListAllNamespaceResourcesWhenEmpty() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -576,7 +576,7 @@ void shouldListAllNamespaceResourcesOfTypeTopic() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -614,7 +614,7 @@ void shouldListAllNamespaceResourcesOfTypeConnect() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -652,7 +652,7 @@ void shouldListAllNamespaceResourcesOfTypeRoleBinding() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -690,7 +690,7 @@ void shouldListAllNamespaceResourcesOfTypeAccessControlEntry() { .thenReturn(List.of(ace)); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -728,7 +728,7 @@ void shouldListAllNamespaceResourcesOfTypeConnectCluster() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of(connectCluster)); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.empty()); List result = namespaceService.findAllResourcesByNamespace(ns); @@ -766,7 +766,7 @@ void shouldListAllNamespaceResourcesOfTypeQuota() { .thenReturn(List.of()); when(connectClusterService.findAllByNamespaceWithOwnerPermission(ns)) .thenReturn(List.of()); - when(resourceQuotaService.findByNamespace("namespace")) + when(resourceQuotaService.findForNamespace("namespace")) .thenReturn(Optional.of(resourceQuota)); List result = namespaceService.findAllResourcesByNamespace(ns); diff --git a/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java b/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java index a0dde36b..4bb6424c 100644 --- a/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java +++ b/src/test/java/com/michelin/ns4kafka/service/ResourceQuotaServiceTest.java @@ -46,7 +46,23 @@ class ResourceQuotaServiceTest { ConnectorService connectorService; @Test - void findByNamespace() { + void shouldFindQuota() { + ResourceQuota resourceQuota = ResourceQuota.builder() + .metadata(Metadata.builder() + .cluster("local") + .name("test") + .build()) + .spec(Map.of(COUNT_TOPICS.toString(), "1")) + .build(); + + when(resourceQuotaRepository.findForNamespace("namespace")) + .thenReturn(Optional.of(resourceQuota)); + + assertEquals(Optional.of(resourceQuota), resourceQuotaService.findForNamespace("namespace")); + } + + @Test + void shouldGetQuotasWhenEmpty() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -57,10 +73,19 @@ void findByNamespace() { .build()) .build(); + when(resourceQuotaRepository.findForNamespace("namespace")) + .thenReturn(Optional.empty()); + + assertTrue(resourceQuotaService.findForNamespace(ns.getMetadata().getName()).isEmpty()); + } + + @Test + void shouldListQuotasWithoutParameter() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") - .name("test") + .namespace("namespace") + .name("quotaName") .build()) .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); @@ -68,34 +93,54 @@ void findByNamespace() { when(resourceQuotaRepository.findForNamespace("namespace")) .thenReturn(Optional.of(resourceQuota)); - Optional resourceQuotaOptional = - resourceQuotaService.findByNamespace(ns.getMetadata().getName()); - assertTrue(resourceQuotaOptional.isPresent()); - assertEquals("test", resourceQuotaOptional.get().getMetadata().getName()); + assertEquals(List.of(resourceQuota), + resourceQuotaService.findByWildcardName("namespace", "*")); } @Test - void findByNamespaceEmpty() { - Namespace ns = Namespace.builder() + void shouldListQuotasWithNameParameter() { + ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() - .name("namespace") .cluster("local") + .namespace("namespace") + .name("quotaName") .build()) - .spec(Namespace.NamespaceSpec.builder() - .connectClusters(List.of("local-name")) + .spec(Map.of(COUNT_TOPICS.toString(), "1")) + .build(); + + when(resourceQuotaRepository.findForNamespace("namespace")) + .thenReturn(Optional.of(resourceQuota)); + + assertEquals(List.of(resourceQuota), + resourceQuotaService.findByWildcardName("namespace", "quotaName")); + assertTrue(resourceQuotaService.findByWildcardName("namespace", "not-found").isEmpty()); + } + + @Test + void shouldListQuotasWithWildcardNameParameter() { + ResourceQuota resourceQuota = ResourceQuota.builder() + .metadata(Metadata.builder() + .cluster("local") + .name("quotaName") + .namespace("namespace") .build()) + .spec(Map.of(COUNT_TOPICS.toString(), "1")) .build(); when(resourceQuotaRepository.findForNamespace("namespace")) - .thenReturn(Optional.empty()); + .thenReturn(Optional.of(resourceQuota)); - Optional resourceQuotaOptional = - resourceQuotaService.findByNamespace(ns.getMetadata().getName()); - assertTrue(resourceQuotaOptional.isEmpty()); + assertEquals(List.of(resourceQuota), + resourceQuotaService.findByWildcardName("namespace", "*")); + assertEquals(List.of(resourceQuota), + resourceQuotaService.findByWildcardName("namespace", "quota????")); + assertEquals(List.of(resourceQuota), + resourceQuotaService.findByWildcardName("namespace", "*Name")); + assertTrue(resourceQuotaService.findByWildcardName("namespace", "not-quotaName?").isEmpty()); } @Test - void findByName() { + void shouldFindByName() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -124,7 +169,7 @@ void findByName() { } @Test - void findByNameWrongName() { + void shouldFindByNameWrongName() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -152,7 +197,7 @@ void findByNameWrongName() { } @Test - void findByNameEmpty() { + void shouldFindByNameWhenEmpty() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -172,7 +217,7 @@ void findByNameEmpty() { } @Test - void create() { + void shouldCreateQuota() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") @@ -190,7 +235,7 @@ void create() { } @Test - void delete() { + void shouldDeleteQuota() { ResourceQuota resourceQuota = ResourceQuota.builder() .metadata(Metadata.builder() .cluster("local") @@ -206,7 +251,7 @@ void delete() { } @Test - void validateNewQuotaAgainstCurrentResourceSuccess() { + void shouldValidateNewQuotaAgainstCurrentResourceSuccess() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -254,7 +299,7 @@ void validateNewQuotaAgainstCurrentResourceSuccess() { } @Test - void validateNewQuotaAgainstCurrentResourceForCountTopics() { + void shouldValidateNewQuotaAgainstCurrentResourceForCountTopics() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -300,11 +345,11 @@ void validateNewQuotaAgainstCurrentResourceForCountTopics() { List validationErrors = resourceQuotaService.validateNewResourceQuota(ns, resourceQuota); assertEquals(1, validationErrors.size()); assertEquals("Invalid value \"2\" for field \"count/topics\": quota already exceeded (3/2).", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateNewQuotaAgainstCurrentResourceForCountPartitions() { + void shouldValidateNewQuotaAgainstCurrentResourceForCountPartitions() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -359,11 +404,11 @@ void validateNewQuotaAgainstCurrentResourceForCountPartitions() { List validationErrors = resourceQuotaService.validateNewResourceQuota(ns, resourceQuota); assertEquals(1, validationErrors.size()); assertEquals("Invalid value \"10\" for field \"count/partitions\": quota already exceeded (19/10).", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateNewQuotaDiskTopicsFormat() { + void shouldValidateNewQuotaDiskTopicsFormat() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -385,11 +430,11 @@ void validateNewQuotaDiskTopicsFormat() { List validationErrors = resourceQuotaService.validateNewResourceQuota(ns, resourceQuota); assertEquals(1, validationErrors.size()); assertEquals("Invalid value \"10\" for field \"disk/topics\": value must end with either B, KiB, MiB or GiB.", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateNewQuotaAgainstCurrentResourceForDiskTopics() { + void shouldValidateNewQuotaAgainstCurrentResourceForDiskTopics() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -436,11 +481,11 @@ void validateNewQuotaAgainstCurrentResourceForDiskTopics() { List validationErrors = resourceQuotaService.validateNewResourceQuota(ns, resourceQuota); assertEquals(1, validationErrors.size()); assertEquals("Invalid value \"5000B\" for field \"disk/topics\": quota already exceeded (8.79KiB/5000B).", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateNewQuotaAgainstCurrentResourceForCountConnectors() { + void shouldValidateNewQuotaAgainstCurrentResourceForCountConnectors() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -467,11 +512,11 @@ void validateNewQuotaAgainstCurrentResourceForCountConnectors() { List validationErrors = resourceQuotaService.validateNewResourceQuota(ns, resourceQuota); assertEquals(1, validationErrors.size()); assertEquals("Invalid value \"1\" for field \"count/connectors\": quota already exceeded (2/1).", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateUserQuotaFormatError() { + void shouldValidateUserQuotaFormatError() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -492,13 +537,13 @@ void validateUserQuotaFormatError() { assertEquals(2, validationErrors.size()); assertEquals("Invalid value \"producer\" for field \"user/producer_byte_rate\": value must be a number.", - validationErrors.get(0)); + validationErrors.getFirst()); assertEquals("Invalid value \"consumer\" for field \"user/consumer_byte_rate\": value must be a number.", validationErrors.get(1)); } @Test - void validateUserQuotaFormatSuccess() { + void shouldValidateUserQuotaFormatSuccess() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -520,7 +565,7 @@ void validateUserQuotaFormatSuccess() { } @Test - void getCurrentUsedResourceForCountTopicsByNamespace() { + void shouldGetCurrentUsedResourceForCountTopicsByNamespace() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -560,7 +605,7 @@ void getCurrentUsedResourceForCountTopicsByNamespace() { } @Test - void getCurrentUsedResourceForCountPartitionsByNamespace() { + void shouldGetCurrentUsedResourceForCountPartitionsByNamespace() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -609,7 +654,7 @@ void getCurrentUsedResourceForCountPartitionsByNamespace() { } @Test - void getCurrentUsedResourceForCountConnectorsByNamespace() { + void shouldGetCurrentUsedResourceForCountConnectorsByNamespace() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -630,7 +675,7 @@ void getCurrentUsedResourceForCountConnectorsByNamespace() { } @Test - void getCurrentUsedResourceForDiskTopicsByNamespace() { + void shouldGetCurrentUsedResourceForDiskTopicsByNamespace() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -681,7 +726,7 @@ void getCurrentUsedResourceForDiskTopicsByNamespace() { } @Test - void validateTopicQuota() { + void shouldValidateTopicQuota() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -757,7 +802,7 @@ void validateTopicQuota() { } @Test - void validateTopicQuotaNoQuota() { + void shouldValidateTopicQuotaNoQuota() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -786,7 +831,7 @@ void validateTopicQuotaNoQuota() { } @Test - void validateTopicQuotaExceed() { + void shouldValidateTopicQuotaExceed() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -859,7 +904,7 @@ void validateTopicQuotaExceed() { List validationErrors = resourceQuotaService.validateTopicQuota(ns, Optional.empty(), newTopic); assertEquals(3, validationErrors.size()); assertEquals("Invalid \"apply\" operation: exceeding quota for count/topics: 3/3 (used/limit).", - validationErrors.get(0)); + validationErrors.getFirst()); assertEquals("Invalid \"apply\" operation: exceeding quota for count/partitions: 19/20 (used/limit). " + "Cannot add 6.", validationErrors.get(1)); assertEquals("Invalid \"apply\" operation: exceeding quota for disk/topics: 18.555KiB/20.0KiB (used/limit). " @@ -868,7 +913,7 @@ void validateTopicQuotaExceed() { } @Test - void validateUpdateTopicQuotaExceed() { + void shouldValidateUpdateTopicQuotaExceed() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -941,11 +986,11 @@ void validateUpdateTopicQuotaExceed() { assertEquals(1, validationErrors.size()); assertEquals("Invalid \"apply\" operation: exceeding quota for disk/topics: 18.555KiB/20.0KiB (used/limit). " + "Cannot add 2.93KiB.", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void validateConnectorQuota() { + void shouldValidateConnectorQuota() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -976,7 +1021,7 @@ void validateConnectorQuota() { } @Test - void validateConnectorQuotaNoQuota() { + void shouldValidateConnectorQuotaNoQuota() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -995,7 +1040,7 @@ void validateConnectorQuotaNoQuota() { } @Test - void validateConnectorQuotaExceed() { + void shouldValidateConnectorQuotaExceed() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -1024,11 +1069,11 @@ void validateConnectorQuotaExceed() { List validationErrors = resourceQuotaService.validateConnectorQuota(ns); assertEquals(1, validationErrors.size()); assertEquals("Invalid \"apply\" operation: exceeding quota for count/connectors: 2/2 (used/limit).", - validationErrors.get(0)); + validationErrors.getFirst()); } @Test - void getUsedResourcesByQuotaByNamespace() { + void shouldGetUsedResourcesByQuotaByNamespace() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -1100,7 +1145,7 @@ void getUsedResourcesByQuotaByNamespace() { } @Test - void getCurrentResourcesQuotasByNamespaceNoQuota() { + void shouldGetCurrentResourcesQuotasByNamespaceNoQuota() { Namespace ns = Namespace.builder() .metadata(Metadata.builder() .name("namespace") @@ -1161,7 +1206,7 @@ void getCurrentResourcesQuotasByNamespaceNoQuota() { } @Test - void getUsedQuotaByNamespaces() { + void shouldGetUsedQuotaByNamespaces() { Namespace ns1 = Namespace.builder() .metadata(Metadata.builder() .name("namespace")