From d3607d3350f6818604c56a76ce771b76e09aa198 Mon Sep 17 00:00:00 2001 From: thcai Date: Wed, 31 Jul 2024 14:56:28 +0200 Subject: [PATCH] rename + reuse of method for better maintenance + deprecated annotation --- .../ns4kafka/controller/SchemaController.java | 4 +++- .../ns4kafka/service/SchemaService.java | 2 +- .../controller/SchemaControllerTest.java | 6 ++++-- .../ns4kafka/service/SchemaServiceTest.java | 18 +++++++++--------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/michelin/ns4kafka/controller/SchemaController.java b/src/main/java/com/michelin/ns4kafka/controller/SchemaController.java index 5d188f30..5add5cdd 100644 --- a/src/main/java/com/michelin/ns4kafka/controller/SchemaController.java +++ b/src/main/java/com/michelin/ns4kafka/controller/SchemaController.java @@ -52,7 +52,7 @@ public class SchemaController extends NamespacedResourceController { */ @Get public Flux list(String namespace, @QueryValue(defaultValue = "*") String name) { - return schemaService.findAllForNamespace(getNamespace(namespace), name); + return schemaService.findByWildcardName(getNamespace(namespace), name); } /** @@ -61,8 +61,10 @@ public Flux list(String namespace, @QueryValue(defaultValue = "*") S * @param namespace The namespace * @param subject The subject * @return A schema + * @deprecated use list(String, String name) instead. */ @Get("/{subject}") + @Deprecated(since = "1.11.13") public Mono get(String namespace, String subject) { Namespace ns = getNamespace(namespace); diff --git a/src/main/java/com/michelin/ns4kafka/service/SchemaService.java b/src/main/java/com/michelin/ns4kafka/service/SchemaService.java index 70ac58a2..4735109d 100644 --- a/src/main/java/com/michelin/ns4kafka/service/SchemaService.java +++ b/src/main/java/com/michelin/ns4kafka/service/SchemaService.java @@ -73,7 +73,7 @@ public Flux findAllForNamespace(Namespace namespace) { * @param name The name filter * @return A list of schemas */ - public Flux findAllForNamespace(Namespace namespace, String name) { + public Flux findByWildcardName(Namespace namespace, String name) { List acls = aclService .findResourceOwnerGrantedToNamespace(namespace, AccessControlEntry.ResourceType.TOPIC); List nameFilterPatterns = RegexUtils.wildcardStringsToRegexPatterns(List.of(name)); diff --git a/src/test/java/com/michelin/ns4kafka/controller/SchemaControllerTest.java b/src/test/java/com/michelin/ns4kafka/controller/SchemaControllerTest.java index f0ebf40d..d88225a9 100644 --- a/src/test/java/com/michelin/ns4kafka/controller/SchemaControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controller/SchemaControllerTest.java @@ -250,7 +250,7 @@ void listWithoutParameter() { SchemaList schema = buildSchemaList(); when(namespaceService.findByName("myNamespace")).thenReturn(Optional.of(namespace)); - when(schemaService.findAllForNamespace(namespace, "*")).thenReturn(Flux.fromIterable(List.of(schema))); + when(schemaService.findByWildcardName(namespace, "*")).thenReturn(Flux.fromIterable(List.of(schema))); StepVerifier.create(schemaController.list("myNamespace", "*")) .consumeNextWith( @@ -264,7 +264,7 @@ void listWithNameParameter() { SchemaList schema = buildSchemaList(); when(namespaceService.findByName("myNamespace")).thenReturn(Optional.of(namespace)); - when(schemaService.findAllForNamespace(namespace, "prefix.subject-value")) + when(schemaService.findByWildcardName(namespace, "prefix.subject-value")) .thenReturn(Flux.fromIterable(List.of(schema))); StepVerifier.create(schemaController.list("myNamespace", "prefix.subject-value")) @@ -274,6 +274,7 @@ void listWithNameParameter() { } @Test + @SuppressWarnings("deprecation") void get() { Namespace namespace = buildNamespace(); Schema schema = buildSchema(); @@ -288,6 +289,7 @@ void get() { } @Test + @SuppressWarnings("deprecation") void getNamespaceNotOwnerOfSubject() { Namespace namespace = buildNamespace(); Schema schema = buildSchema(); diff --git a/src/test/java/com/michelin/ns4kafka/service/SchemaServiceTest.java b/src/test/java/com/michelin/ns4kafka/service/SchemaServiceTest.java index 21727201..b267f51b 100644 --- a/src/test/java/com/michelin/ns4kafka/service/SchemaServiceTest.java +++ b/src/test/java/com/michelin/ns4kafka/service/SchemaServiceTest.java @@ -128,12 +128,12 @@ void listSchemaWithNameParameter() { when(aclService.isAnyAclOfResource(acls, "prefix2.schema-two")).thenReturn(true); when(aclService.isAnyAclOfResource(acls, "prefix2.schema-three")).thenReturn(false); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix.schema-one")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix.schema-one")) .consumeNextWith(schema -> assertEquals("prefix.schema-one", schema.getMetadata().getName())) .verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix2.schema-three")).verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix3.schema-four")).verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix2.schema-three")).verifyComplete(); + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix3.schema-four")).verifyComplete(); + StepVerifier.create(schemaService.findByWildcardName(namespace, "")) .consumeNextWith(schema -> assertEquals("prefix.schema-one", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix2.schema-two", schema.getMetadata().getName())) .verifyComplete(); @@ -181,27 +181,27 @@ void listSchemaWithWildcardNameParameter() { Flux.fromIterable(subjectsResponse)); when(aclService.isAnyAclOfResource(eq(acls), anyString())).thenReturn(true); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix1.*")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix1.*")) .consumeNextWith(schema -> assertEquals("prefix1.schema1-value", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix1.schema1-key", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix1.schema-one", schema.getMetadata().getName())) .verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "*-value")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "*-value")) .consumeNextWith(schema -> assertEquals("prefix1.schema1-value", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix2.schema2-value", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix4.schema1-value", schema.getMetadata().getName())) .verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix?.schema1-key")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix?.schema1-key")) .consumeNextWith(schema -> assertEquals("prefix1.schema1-key", schema.getMetadata().getName())) .verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "prefix?.schema-*")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "prefix?.schema-*")) .consumeNextWith(schema -> assertEquals("prefix1.schema-one", schema.getMetadata().getName())) .verifyComplete(); - StepVerifier.create(schemaService.findAllForNamespace(namespace, "*")) + StepVerifier.create(schemaService.findByWildcardName(namespace, "*")) .consumeNextWith(schema -> assertEquals("prefix1.schema1-value", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix1.schema1-key", schema.getMetadata().getName())) .consumeNextWith(schema -> assertEquals("prefix1.schema-one", schema.getMetadata().getName()))